Showing posts with label SeaBIOS. Show all posts
Showing posts with label SeaBIOS. Show all posts

Monday, October 14, 2013

SeaBIOS - Interface_init

Sunday, October 13, 2013

SeaBIOS - Source Code Study (2)

QEMU_PREINIT(void)



  • qemu_detect(void)

dopost()


In this function, besides the qemu_preinit(). It will be responsible to allocate memory, init serial port, make BIOS writable, and start the main function in qemu: maininit()

maininit(): most important entrypoint for SeaBIOS


Sunday, October 6, 2013

BIOS Boot Specification


Term

  • IPL Device: Initial Program Load Device, basically, this is floppy drive or hard drive
  • BAID: BIOS Aware IPL Device, which can boot OS but requires BIOS to support it. For example: CD-ROM
  • BCV: Boot Connection Vector, which is a pointer to code inside the option ROM that perform device initialization, detect if a peripheral is attached, and hook INT 13h. 
  • BEV: Bootstrap Entry Vector is a pointer that points to code inside an option ROM which load OS. BEV resides in PnP option ROM Expansion Header.

Overview

  • BIOS creates and maintains a list of all IPL devices found in the system and stores this list in NV memory. 
  • Support devices boot order.
  • Defines the BCV priority. 
  • BIOS will try each devices to boot OS. If none succeeds, wait for a key stroke then invoke INT 19 again.

IPL Devices

  • Includes hard drives, CD-ROM devices ,etc,. 
  • Falls into three categories: BAID, Legacy (dead) and PnP (plug and play).
  • BIOS defines INT 18 as recover vector for failed boot attempt.
  • IPL tables includes: identification information, pointers to description strings, and pointers to handler.
  • Product Name String in PnP Expansion Header is very meaningful to indicate manufacturer information. Only first 32 Bytes are used.
  • Each BAID will have an entry in the IPL Table. INT 19h handler will read this table and boot OS from BAID. BAID doesn't have option ROM.
  • IPL Table and BCV Table Entry Data Structure

  • All IPL devices with option ROMs must contain a valid option ROM header which resides between C0000h and EFFFFh and begin with 55AAh. The address of PnP Expansion Header is within option ROM header at offset (C0000h-EFFFFh)  + 1Ah. PnP Expansion Header contains pointers to code in device's option ROM (BCV or BEV). 

  • BEV: is booted by the BIOS making a far call directly
  • BCV: typically SCSI controller is not directly bootable. Rather, it merely adds drives to the system by hooking into the BIOS's INT 13h services and appending drive numbers to existing drives.
  • Identifying IPL Devices:
            BAIDs are automatically identified by BIOS
            PnP Card is defined by having PnP Expansion Header in option ROM. BEV device will be included in the IPL Priority. BCV device will be called.
            PCI devices with option ROM behave like IPL devices.

IPL Priority


  • An IPL Priority ordinal value is the index of a BAID or BEV device entry in the IPL table.
  • When INT 19h handler gains control, the first IPL device in IPL priority is used to boot.
  • BIOS only recognize a change in the number of BEV devices rather than the type of BEV devices. 
  • For example, when you change your network card,  in IPL priority the ordinal value is not changed, but the entry of IPL table is changed.

BCV Priority



  • The first type of entry in the BCV Table is BIOS's own INT 13h services for ATA drives. 
  • PnP Cards with BCV are the second type of entry in BCV Table.
   

SeaBIOS - Source Code Study (1)


SeaBIOS handle fw_cfg


entry_elf -> handle_post() -> dopost() -> maininit() -> interface_init() -> qemu_cfg_init()

ENTRY(entry_elf)

SeaBIOS serial port configuration


Serial Port Information is listed as follows:














  • debug_serial_preinit()
  • DebugOutputPort = 0x402

Make BIOS Writable


BDF Architecture is blow:
bus << 16 | device << 11 | function << 8 | offset
But in SeaBIOS:
bus << 8 | dev << 3 | fn
Because when out 0xcf8 port, bdf will be << 8
  • foreachbdf(BDF, BUS)
    • pci_bus_devfn_to_bdf(bus, devfn)
    • pci_next(int bdf, int bus)
    • pci_config_readb(u16, bdf, u32 addr)

Saturday, October 5, 2013

SeaBIOS - MakeFile


  • Object
  • SRCBOTH is basics source file object. However, there are two objects based on SRCBOTH: SRC16 and SRC32FLAT. The other object is SRC32SEG.
  • Flag
  • Note: cc-option function. Basic Flag Parameter is COMMONCFLAGS. According to different Objects, there are other flags: CFLAGS32FLAT, CFLAGSSEG, CFLAGS32SEG, CFLAGS16INC, CFLAGS16  Note: If you place "@" before a makefile command, this command will not be displayed in the screen.
  • Target
  • Final target: target-y
  • Rules
  • Note: $< is the set of files in the right part, $> is the file in the left part
    • bios.bin
    • rom.o (required by bios.bin)
    • rom16.o (required by rom.o)
    • rom32seg.o (required by rom.o)
    • Note:
    • rom.o requires rom16.strip.o, rom32seg.strip.o and code32flat.o rather than rom16.o and rom32seg.o. Check the following, I can find rom16.strip.o and rom32seg.strip.o generated by rom16.o and rom32seg.o. In addition,ccode16.o, code32seg.o are used to generate rom16.o and rom32seg.o. ccode32flat.o is used to generate code32flat.o
    • ccode16.o (required by rom16.o)
    • code32seg.o (required by rom32seg.o)
    • ccode32flat.o (required by code32flat.o)
    • romlayout.o (required by rom16.o)

Tuesday, October 1, 2013

SeaBIOS - Basic

Background

  • BIOS will enumerate all PCI devices in POST stage.
  • The details about POST stage can be found here

Compile

  • SeaBIOS is Kconfig style, so run make menuconfig
  • Choose the options you want in the pop-up menu
  • A new file ".config" will be generated after you exit the menu.
  • Finally, Just make
To learn how to launch your first BIOS, please follow this

Q&A

  1. How QEMU communicate with SeaBIOS?
  2. A: fw_cfg:
    • Emulated IO ports 0x510 (address) and 0x511 (data)
    • Used to communicate various tables to the qemu BIOS (e820 map,ACPI tables, etc)
    • Also provides support for exporting writable tables to the BIOS.
  3. Where is option ROM?
  4. A: /usr/share/qemu/