User:Barry Sharpe/CFBS

Detailed Objective
Weight: 1


 * Description: Candidates should be able to configure fundamental system hardware by making the correct settings in the system BIOS in x86 based hardware.


 * Key knowledge area(s):
 * Enable and disable integrated peripherals.
 * Configure systems with or without external peripherals such as keyboards.
 * Correctly set IRQ,DMA and I/O addresses for all BIOS administrated ports and settings for error handling.


 * The following is a partial list of the used files, terms and utilities:
 * /proc/ioports
 * /proc/interrupts
 * /proc/dma
 * /proc/pci

Introduction
The BIOS (Basic Input / Output System) can be thought of as a suite of small programs that operates between the operating system and the hardware on any given computer. It provides a number of services that enable the computer to boot any given operating system. The BIOS can also provide or present other services to the operating system depending on the operating system and or the type of hardware installed. It is also wise to note that a modern day computer will have multiple BIOS chips representing the various different hardware that the modern day computer has access too. This includes but is by no means a definitive list Graphic Cards, Sound Cards. Firstly lets look at the services the BIOS provides regardless of which operating system is installed that being the POST (Power On Self Test), Hardware Management, Security and Date and Time.

POST - Power On Self Test

 * The POST process involves a small diagnostic program that checks hardware for the following conditions. Is the hardware present? If so a basic test is then performed to check for faults more advanced tests can be performed but normally this feature needs to be manually enabled such as a long memory test. If the POST process errors it will always do so with audible beeps and in some cases with a visual message this is know as an "Irregular POST Condition". The number and in some cases the pattern of the beeps will aid you in diagnosing the problem however, different manufacturers have different implementations of the audible beeps so it is always wise to know who coded the BIOS for the particular hardware that you support.

Hardware Management

 * The BIOS allows you to customize certain aspects of the system, although you do not interact with the BIOS directly you in fact interact with the CMOS (Complementary Metal Oxide Semiconductor). The BIOS query's the CMOS for customized configurations as part of the POST process. The CMOS is very suitable for this as it has a very low power requirement. It is important to understand the relationship between the BIOS and the CMOS because any changes you make to your BIOS are held in CMOS which can be termed as volatile memory. Your motherboard will have a battery which powers the CMOS hence keeping any customized system configurations that you have made. Because of the technology behind the CMOS you can configure hardware on your system to behave differently or configure the hardware to respond to a different address range altogether. On older motherboards where the CMOS had limited capabilities this was done in the form of positioning jumpers or dip switches to hardware manufacturers specifications. In some cases even today you may still come across the jumper / dip switch technology most notably in SCSI ID or BIOS password resets always keep the possibility of older technology in mind.

Security

 * Computers have for a long time supported the facility to have a BIOS password set, typically this will prompt at the power up stage any given user to input a password before the BIOS would complete the boot process. Modern day computers have the facility to detect configuration changes such as memory size changes and even if the case has been removed. However, there has always been some dispute about the benefits of such a process being invoked as a "sys admin" you will need to keep in mind the administrative work load over the benefits of implementing such a system. Often the BIOS password system does not work due to the fact that information on how to get around them freely exists on the internet. Compare this with one of your users forgetting the password which will inevitably mean a visit to the computer to solve and its not hard to see why these systems are rarely invoked at the business level.

Date and Time

 * The BIOS by default will provide the system date and time upon the booting of the operating system, setting the time is a an option within the BIOS. After the operating system has gathered this information the BIOS clock and the Operating System clock become two different clocks. Further the BIOS cannot handle time zones, this is handled by the operating system. This means that the BIOS clock may differ from the operating system clock after a period of use even if it is only in milliseconds. Linux has a command called hwclock which can be used to sync the operating system clock with the BIOS. However, the important thing to remember is the two clocks, further on in the course you will start to look at ntp and how important it is to maintain a consistent "Network Time". Knowing that the BIOS and operating system maintain two clocks will aid you in setting out a solution.

Naming Convention
Firstly lets address the confusion that often comes around from disk drive terminology such as IDE/ATA (Integrated Drive Electronics / Advanced Technology Attachment) and SATA (Serial Advanced Technology Attachment) and indeed PATA (Parallel Advanced Technology Attachment) which all use the ATA (Advanced Technology Attachment) standard to communicate with the device. The first part of the acronym can be thought of simplistically as a revision. For instance IDE, Fast IDE, EIDE, etc these revisions had changes made to the physical cables or ribbons that connect the disk drives to the computer that enabled certain features. This could be to address more disk space or speed up communications with the device. SATA was like a rewrite, once SATA came into being it was decided that all historical ATA devices that predated SATA, like IDE etc be grouped under the terminology PATA.

A brief History
To get an understanding of modern hard drives it helps to have some background. The BIOS traditionally uses INT13h as an interface to the hard drive, INT13h from an historical point had certain limitations such as hard drive size limit etc. Now on the other side of the interface that being the drive which used the IDE/ATA also had restrictions. We can see these restrictions easily if we lay out a table as below. Clearly you can see that because of the limitations of INT13h and IDE/ATA (which we have highlighted) under the above scenario the largest drive your average computer could handle was 528MB, We call this specification CHS (Cylinders Heads Sectors). You may recall that to calculate the total size of a hard drive use the following formula.
 * Cylinders * Heads * Sectors * 512 = Capacity

To get around this a new specification was implemented called ECHS (Extended Cylinders Heads Sectors) some times also referred to as "Large Mode". This introduced a translation layer between the BIOS and INT13h. The translation layer then allowed a computer to handle disk drives upto 8.4GB in size we can see this with a following modification to the table above which we have set out below and highlighted the relevant row. To see how the translation works lets take a 2.5GB hard drive with the following specs Cylinders = 4960 Heads = 16 Sectors = 63. The translation program looks at the number of cylinders and makes a "Best fit" with the INT13h limitation of 1,024 cylinders. The translation program does this by division normally it divides the number of cylinders by one of the following numbers 2,4,6,8 and in some cases 16. In our case 4960 / 8 = 620 which does not break the limitation of INT13h. Now the translation program multiply's the number of heads by 8 so 16 * 8 = 128. In this way the translation program maintains the INT13h standard and provides a way in which the computer can see the whole disk. We can see this by calculating the disk space at both points previous translation and after.
 * Native 4660 * 16 * 63 * 512 = 2.5GB
 * Translation 620 * 128 * 63 * 512 = 2.5GB

The Table above needs a little more clarification you will note that the Heads for the ECHS (Translation Layer) = 128 which is incompatible with the IDE/ATA Layer which specifies a limit of 16. We get away with this because the translation layer is only concerned with INT13h and not in any way related to the IDE/ATA layer. The next table will show how this model really looks Needless to say Hard Drives got a lot bigger than 8.4GB, so some other way was need the cylinders, heads and sectors was no longer a viable option. This is covered in the next section where we bring you right up to date.

LBA
LBA (Logical Block Addressing) is the most common scheme in use today to get past the 528MB limit imposed on an IDE/ATA disk drive. With LBA each block has a unique identification number thats starts at 0 and then 1,2,3,4,5... In order for this mechanism to work it must be supported by the BIOS, the operating sytem and the IDE drive. The common misconception with LBA is that it is the LBA itself that gets around the 528MB limit when in fact LBA uses translation. When you enable LBA mode in a BIOS you are in effect enabling translation. The translation can be the same as ECHS as discussed above or another algorithm can be used by a 3rd party. It is way beyond this course to look at these algorithms. But the point of 3rd party algorithms should be made. More and more with modern operating systems the BIOS is taking a back seat when "Talking" to the drive, modern operating systems now perform this function with there own interpretation of the ATA specification preferring to bypass the BIOS altogether.

IRQ
There are 16 IRQ's (Interupt ReQuest) channels on x86 architecture, of those only a few are freely available. The table below lists the IRQ's that cannot be used in red and the IRQ's that could be reassigned providing certain hardware does not exist in your system in orange, and those that you are free to assign as you please in green.

In essence IRQ's are used to halt the computer from processing any further information and immediately service the request from the interrupt. That being the device that is assigned to the interrupt. The table above explains what the IRQ architecture looked like under PIC (Programmable Interrupt Controller), however it does hide the the issue of priorities. The priorities of the IRQ structure can be seen like this -0-1-2-8-9-10-11-12-13-14-15-3-4-5-6-7. The reason 8-15 have a higher priority is that they hook into IRQ 2, in fact IRQ 2 can be said to be IRQ 9. What we have looked at here is somewhat historical under the above scenario adding new hardware quickly became an art and a pain! However, the advent of PCI and USB enabled a greater range of addresses and also the ability to just plug things in and go.

DMA
DMA (Direct Memory Access) is a feature of the modern computer to enable devices to bypass the CPU when needing to write or read information to or from another device, the purpose of this is to take the load off the CPU and utilize the DMA controller and RAM to move blocks of data from one address to another. Although the CPU is never completely eliminated in a DMA transfer, its role is purely to initiate the process rather than manage it.

I/O
I/O (Input / Output) refers to all devices both external and internal within a modern computer system. Some devices can perform both input and output functions, an example of this is a Network Card, obviously keyboards, mouse etc are examples of input devices and monitor, printers are examples of output devices. I know entry level stuff but bare with me the theory is nearly over.

Putting it altogether
When you turn the PC on, BIOS instructions are loaded into RAM from a permanently available ROM chip on the motherboard. These instructions, after performing a POST, may further inform the processor where the operating system is located and how to load it into RAM. In order to allow operating systems and applications to run on a PC, the BIOS provides a standard layer of services that the operating system can use to "talk" to the hardware. In turn, the operating system provides standard services to applications to perform their functions. It is important to understand that not all operating systems use all BIOS services, some use their own instructions to access the hardware. The direct method of accessing the hardware may improve performance.

The BIOS utilizes a number of technologies to perform the above services many of which we have addressed above. However, as with all things in the computer industry technology is moving forward fast. The BIOS performs a crucial role within the system new technology added to the motherboard will normally require BIOS co-operation so that The OS can utilize the new technology. By now you should have a good understanding of the BIOS and the role it performs the also you should begin to understand the BIOS and Hardware relationship in the next section we look at Linux and how it interacts with the BIOS / Hardware hopefully giving you a more complete picture from a "sys admin" view point of these relationships.

Introduction
From this point on it becomes necessary, to have access to a Linux PC. although some theory is involved we shall more and more be interacting with Linux. I advise that you attempt the commands as you come across them testing your understanding as you go. Do be careful with some of the commands as an incorrect switch or in some cases running a command from the wrong directory (One famous example is rm -R * from / as root is not healthy). So if you are new to Linux be careful don't misuse the root account only use it when you have too. I personally advise a separate Linux installation for the course that contains no personal data etc. '''Understand that No author / contributor to this book is in any way responsible for any loss of data or damage to any hardware, however it is caused. Mistakes in typing can happen and this is an open book for anyone to edit regardless of their knowledge.'''

/proc
/proc is a pseudo-filesystem which is used as an interface to kernel data structures. Most of it is read-only, but some files allow kernel variables to be changed particularly in /proc/sys. if you were to list the file system in /proc you would see something like this. user@host:~$ cd /proc user@host:/proc$ ls 1    4190  5071  5462  5859  6          dma          pagetypeinfo 128  4312  5103  5478  5867  6024       driver       partitions 1475 44    5162  5547  5868  6553       execdomains  sched_debug 1481 45    5164  5563  5871  6583       fb           scsi 1508 4589  5205  5574  5879  6593       filesystems  self 1524 4590  5224  5579  5880  6685       fs           slabinfo 1526 4594  5227  5655  5884  6694       interrupts   stat 165  4595  5289  5660  5890  6714       iomem        swaps 166  4597  5302  5661  5892  6716       ioports      sys 1784 4765  5315  5695  5901  6717       irq          sysrq-trigger 1786 4805  5318  5697  5902  6735       kallsyms     sysvipc 1787 4878  5328  5698  5903  7          kcore        timer_list 2    4932  5336  5816  5905  acpi       key-users    timer_stats 207  4934  5356  5820  5912  asound     kmsg         tty 2272 4956  5362  5821  5915  buddyinfo  loadavg      uptime 2273 4972  5363  5829  5918  bus        locks        version 2515 4986  5370  5832  5925  cgroups    meminfo      version_signature 2718 4999  5373  5842  5938  cmdline    misc         vmcore 3    5     5378  5851  5941  cpuinfo    modules      vmnet 3181 5021  5416  5854  5970  crypto     mounts       vmstat 4    5042  5419  5856  5973  devices    mtrr         zoneinfo 41   5043  5423  5858  5982  diskstats  net

If you are new to Linux i have provided a history in the above of the commands i typed the first command being cd /proc (Change directory to /proc followed on the next line with ls (list the contents of /proc) i will do this for the first few lessons of the course with new commands only. Once we get past the GNU & UNIX commands section this will stop. The first thing that you will notice is the numbered directories these represent processes running on your system. Each numbered directory, has a common subset of directories that provide information about that process. The number representing the directory is consistent with the process number if you were to use the ps command, we cover processes in a later section. The directories and files we are interested in are the following: /proc/acpi /proc/bus/pci* Note on some distributions maybe /proc/pci /proc/cpuinfo /proc/devices /proc/dma /proc/interrupts /proc/iomem /proc/ioports /proc/irq /proc/meminfo

/proc/acpi
The /proc/acpi (Advanced Configuration and Power Interface) directory holds information about power features the motherboard has. Previous to ACPI was a system know as APM, Advanced Power Management, The main difference between the two is the role played by the BIOS. Under the APM model the BIOS controlled the way the power management features were used. Under ACPI the OS controls how the power managemnt features are used. The BIOS informs the OS what features are available and provides the nessasary registers for the OS to talk to the hardware. If you were to cd into the acpi directory you will note the following file

Getting hard drive Information
In order to get disk information, use hdparm. More information is available at the hdparm man page

hdparm [options] [devices] Common options: -g: Get the disk geometry. -C: Display the power mode of the hard drive. active/idle: Normal operation, Standby: Low power  mode, or sleeping: Lowest power mode. -v: Display all  settings,  except  -i (same as -acdgkmnru for IDE, -gr for SCSI or -adgr for XT). This is also the default behaviour when no flags are specified.

Examples:

hdparm -g /dev/hda /dev/hda: geometry    = 3648/255/63, sectors = 58605120, start = 0

hdparm -C /dev/hda /dev/hda: drive state is: active/idle

Getting kernel information
/proc is a pseudo-filesystem which is used as an interface to kernel data structures. Most of it is read-only, but some files allow kernel variables to be changed.

Examples of available directories are: [Number]: Process information running on the system. cmdline: The complete command line, cwd: The working directory, ...

/proc/uptime Since when the system is up and running. /proc/sys/kernel Kernel information. /proc/sys/net Network information. /proc/partitions Hard drive partitions information. /proc/scsi SCSI information. /proc/mount Mounted file system information. /proc/devices List the loaded drivers. /proc/bus Bus information. /proc/version Linux version.

And more...

Exercises

 * 1) What is the RAM size of your system?
 * 2) Which devices are sharing an interrupt line?
 * 3) Use the lspci utility with the right option to draw the PCI architecture of your system.
 * 4) * How many PCI buses and bridges are there?
 * 5) * Are there any PCI/ISA bridges?
 * 6) What is the lspci option to list all the Intel PCI devices?
 * 7) What is the command to set your IDE hard drive to read-only mode?
 * 8) What is the command to turn on/off the hard drive disk cache?
 * 9) What does the setpci utility do?
 * 10) What is the command to write a word in register N of a PCI device?