对于一种新东西的学习,如果有看得到、摸得着的演示,比单纯看理论知道更容易理解。在未对coreboot进行代码级别分析之前,用一个实例来看看coreboot到底长什么样子。
本文讲述如何在linux环境中编译coreboot,并使用qemu模拟器来启动。
一、下载
coreboot的发布版本下载地址为:https://www.coreboot.org/releases/,最新版本为2016年1月份发布的4.3。
coreboot的主分支仓库地址为:https://github.com/coreboot/coreboot,有超过100多人开发维护,一直在更新。
笔者研究使用的coreboot仓库地址为:https://github.com/latelee/coreboot。
二、编译
本文所用的系统为ubuntu 14.04,32位桌面版本。1、基本环境
安装必须的开发工具、库:
$ sudo apt-get install m4 bison flex
进入coreboot源码目录,安装iasl(注:笔者使用apt-get方式安装无法正常编译):
$ make iasl
2、配置
对coreboot进行配置,输入:
$ make menuconfig
注意:
1、在“通用设置”(General setup),要选择“Allow building with any toolchain”,否则要make crossgcc来新建一个交叉编译器。如下:
General setup --->
[*] Allow building with any toolchain
2、主板使用模拟器,选择x86。
Mainboard --->
Mainboard vendor (Emulation) --->
Mainboard model (QEMU x86 i440fx/piix4 (aka qemu -M pc)) --->
ROM chip size (8192 KB (8 MB)) ---> (flash大小)
3、Payload选择,可以选择配置不同类型的payload
( ) An ELF executable payload
( ) FILO
( ) GRUB2
( ) SeaBIOS
( ) U-Boot (Experimental)
( ) A Linux payload
( ) Tiano Core
选择SeaBIOS:
Payload --->
Add a payload (SeaBIOS) --->
SeaBIOS version (1.9.0) --->
另外还可以选择U-Boot:
Payload --->
Add a payload (U-Boot (Experimental)) --->
U-Boot version (v2016.1) --->
其它默认即可。
3、编译
直接使用make进行编译。
$ make
注意:
3rdparty目录文件为第三方git仓库管理,如果使用coreboot的git仓库版本,则会在编译过程自动clone里面的仓库((如vboot和arm-trusted-firmware)再进行编译。但发布版本中已经包含了第三方库(如vboot和arm-trusted-firmware)的源码。
另外,在编译过程中会下载用户选择的payload,然后一起编译,这是在Makefile.inc中控制的。
最终生成烧写文件coreboot.rom,位于build目录。
三、qemu环境
安装qemu模拟器(qemu-system-x86为只针对x86平台的工具):
$ sudo apt-get install qemu-system-x86
注意,qemu还有其它平台的,可以根据需要选择。具体如下:
* qemu-system-arm
* qemu-system-mips
* qemu-system-misc
* qemu-system-ppc
* qemu-system-sparc
* qemu-system-x86
四、启动qemu
由于本文只关注coreboot,无须用其启动操作系统。启动命令如下:
$ qemu-system-i386 -nographic -bios coreboot/build/coreboot.rom
如果使用操作系统,则要用-hda指定磁盘文件。ubuntu下制定小型根文件系统十分简单,请参阅本站文章。示例命令如下:
qemu-system-i386 -nographic -bios coreboot/build/coreboot.rom -hda rootfs/disk.img
coreboot的默认payload为seabios,它可以启动安装好grub的linux系统。
五、启动信息
POST: 0x05 QEMU debugcon not found [port 0x402] coreboot-248fb13 Mon Feb 15 12:38:01 UTC 2016 romstage starting... CBMEM: IMD: root @ 07fff000 254 entries. IMD: root @ 07ffec00 62 entries. CBFS @ 100 size 7fff00 CBFS: 'Master Header Locator' located CBFS at [100:800000) CBFS: Locating 'fallback/ramstage' CBFS: Found @ offset 35c0 size a018 QEMU debugcon not found [port 0x402] coreboot-248fb13 Mon Feb 15 12:38:01 UTC 2016 ramstage starting... POST: 0x39 Moving GDT to 07ffe8a0...ok POST: 0x80 POST: 0x70 POST: 0x71 POST: 0x72 Enumerating buses... Show all devs... Before device enumeration. Root Device: enabled 1 CPU_CLUSTER: 0: enabled 1 IMD SMALL 1. 07ffe000 00001000 CONSOLE 2. 07fde000 00020000 IRQ TABLE 3. 07fdd000 00001000 ACPI 4. 07fb9000 00024000 SMBIOS 5. 07fb8000 00000800 COREBOOT 6. 07fb0000 00008000 IMD small region: IMD ROOT 0. 07ffec00 00000400 CAR GLOBALS 1. 07ffeac0 00000140 ROMSTAGE 2. 07ffeaa0 00000004 GDT 3. 07ffe8a0 00000200 POST: 0x7a CBFS @ 100 size 7fff00 CBFS: 'Master Header Locator' located CBFS at [100:800000) CBFS: Locating 'fallback/payload' CBFS: Found @ offset d640 size ec9b Jumping to boot code at 000ff06e(07fb0000) POST: 0xf8 CPU0: stack: 00117000 - 00118000, lowest used address 00117bbc, stack used: 1092 bytes entry = 0x000ff06e lb_start = 0x00100000 lb_size = 0x000203a8 buffer = 0x07f6f000 SeaBIOS (version 1.9.1-20160218_213012-localhost) BUILD: gcc: (Ubuntu 4.8.2-19ubuntu1) 4.8.2 binutils: (GNU Binutils for Ubuntu) 2.24 SeaBIOS (version 1.9.1-20160218_213012-localhost) BUILD: gcc: (Ubuntu 4.8.2-19ubuntu1) 4.8.2 binutils: (GNU Binutils for Ubuntu) 2.24 Found coreboot cbmem console @ 7fde000 Found mainboard Emulation QEMU x86 i440fx/piix4 Relocating init from 0x000e4820 to 0x07f64850 (size 46880) Found CBFS header at 0xff800138 multiboot: eax=0, ebx=0 Found 6 PCI devices (max PCI bus is 00) Copying SMBIOS entry point from 0x07fb8000 to 0x000f7180 Copying ACPI RSDP from 0x07fb9000 to 0x000f7160 Copying PIR from 0x07fdd000 to 0x000f70e0 Using pmtimer, ioport 0xe408 Scan for VGA option rom Running option rom at c000:0003 Turning on vga text mode console SeaBIOS (version 1.9.1-20160218_213012-localhost) All threads complete. Found 1 lpt ports Found 1 serial ports ATA controller 1 at 1f0/3f4/0 (irq 14 dev 9) ATA controller 2 at 170/374/0 (irq 15 dev 9) PS2 keyboard initialized DVD/CD [ata1-0: QEMU DVD-ROM ATAPI-4 DVD/CD] Searching bootorder for: /pci@i0cf8/*@1,1/drive@1/disk@0 All threads complete. Scan for option roms Running option rom at c900:0003 pmm call arg1=1 pmm call arg1=0 pmm call arg1=1 pmm call arg1=0 Searching bootorder for: /pci@i0cf8/*@3 Press ESC for boot menu.
下面是使用U-Boot作为payload的信息:
entry = 0x01110015 lb_start = 0x00100000 lb_size = 0x00021070 buffer = 0x07f6c000 [LL DEBUG]: jmp_payload() coreboot end============================== Coreboot mission complete,PAYLOAD coming up...... U-Boot 2016.01 (Mar 06 2016 - 09:53:38 +0800) CPU: x86, vendor Intel, device 663h DRAM: 127.6 MiB Using default environment Video: No video mode configured in coreboot! Model: QEMU x86 (I440FX) Net: No ethernet found. IDE: Bus 0: OK Bus 1: OK Device 0: not available Device 1: not available Device 2: Model: QEMU Firm: 2.0. Ser#: QEMU DVD-ROM Type: Removable CD ROM Capacity: not available Device 3: not available => => version U-Boot 2016.01 (Mar 09 2016 - 09:53:38 +0800) gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 GNU ld (GNU Binutils for Ubuntu) 2.24 coreboot-4.3-367-gd161e1e-dirty (Thu Mar 3 14:09:29 UTC 2016)
李迟 2016.3.11 周五 夜