https://www.coreboot.org/api.php?action=feedcontributions&user=Rob&feedformat=atomcoreboot - User contributions [en]2024-03-28T12:44:59ZUser contributionsMediaWiki 1.40.0https://www.coreboot.org/index.php?title=QEMU_Build_Tutorial&diff=3968QEMU Build Tutorial2007-03-09T03:16:56Z<p>Rob: </p>
<hr />
<div>=== Introduction ===<br />
<br />
If you don't have a mainboard supported by LinuxBIOS don't worry: [http://qemu.org/ QEMU] can help you to emulate one.<br />
<br />
This nice tutorial was written by [mailto:acassis@gmail.com Alan Carvalho de Assis], with additions by [mailto:eswierk@arastra.com Ed Swierk] (but please use the [[Mailinglist|LinuxBIOS mailing list]] rather than emailing the authors directly).<br />
<br />
While there are many ways to use LinuxBIOS to load and run a Linux kernel, this tutorial covers two of the most common:<br />
<br />
* LinuxBIOS with [[FILO]] as payload, using FILO to load a Linux kernel (and optional initramfs) from a hard disk image. This approach involves a bit more mechanism (it relies on FILO's built-in disk and filesystem drivers) but it produces a tiny LinuxBIOS image.<br />
* LinuxBIOS with a Linux kernel (and optional initramfs) as payload. This cuts FILO out of the picture, but the main challenge with is approach is squeezing the resulting LinuxBIOS image into QEMU's BIOS ROM area (currently 2 MB, but easy to extend by patching QEMU).<br />
<br />
=== Requirements === <br />
<br />
You need the following software packages:<br />
<br />
* [[Download_LinuxBIOS|LinuxBIOSv2]] r2405 or greater<br />
* [http://qemu.org/ Qemu] 0.9.0 or greater<br />
* [[FILO]] 0.4.2 or greater (if using FILO)<br />
* [ftp://ftp.lnxi.com/pub/mkelfImage mkelfImage] 2.7 or greater (if not using FILO)<br />
<br />
plus a Linux kernel and root filesystem and a working development environment (make, gcc, etc.). gcc 4.0.x and 4.1.x are known to work for all packages except QEMU, which requires gcc 3.x.<br />
<br />
=== Building or finding a Linux kernel ===<br />
<br />
If you are using FILO, you can simply grab a Linux kernel and initramfs from your favorite distribution.<br />
<br />
Otherwise, you will probably need to build a kernel and initramfs from scratch, ensuring that the final LinuxBIOS image does not exceed QEMU's BIOS size limit. Building the kernel and initramfs is beyond the scope of this tutorial; how you configure them depends on your application.<br />
<br />
If you plan to use kexec to chain-boot another Linux kernel, tools from these projects can help automate the process of generating a kernel and initramfs:<br />
* [http://kboot.sourceforge.net/ kboot]<br />
* [http://wiki.laptop.org/go/Building_LinuxBIOS OLPC buildrom]<br />
<br />
=== Building a FILO payload ===<br />
<br />
If you plan to build your Linux kernel and root filesystem directly into LinuxBIOS, you can skip this section.<br />
<br />
Download FILO (I used filo-0.4.2.tar.bz2), decompress it, and cd to the created directory.<br />
<br />
First invocation of make creates the default Config file.<br />
$ make<br />
<br />
Edit this file as you like. The default configuration worked for me. <br />
$ vi Config <br />
<br />
Run make again to create filo.elf, the ELF FILO image. <br />
$ make <br />
<br />
You will use this file (filo.elf) as the LinuxBIOS payload later on.<br />
<br />
=== Building a Linux kernel payload ===<br />
<br />
If you are using FILO, skip this section.<br />
<br />
Download mkelfImage (I used mkelfImage-2.7.tar.gz), decompress it, and cd to the created directory.<br />
<br />
Configure and build the mkelfImage binary.<br />
$ ./configure && make<br />
<br />
Now use mkelfImage to convert your Linux kernel image (vmlinuz) and initramfs (initrd) into a usable LinuxBIOS payload (linux.elf):<br />
$ mkelfImage --append="console=ttyS0" --initrd=initrd vmlinuz linux.elf<br />
<br />
=== Building LinuxBIOS ===<br />
<br />
Download the LinuxBIOS source code (I used LinuxBIOSv2-2405) and extract it. <br />
<br />
Change to directory targets/emulation/qemu-i386 and modify Config.lb:<br />
* change payload to point to your payload (filo.elf or linux.elf)<br />
* if you are using a Linux payload, increase the value of option ROM_SIZE to 2048*1024 (2 MB)<br />
<br />
Return to targets directory and execute: <br />
$ ./buildtarget emulation/qemu-i386 <br />
<br />
Go to targets/emulation/qemu-i386/qemu-i386 and execute: <br />
$ make <br />
<br />
This creates the LinuxBIOS image (qemu-bios.rom). Copy and rename this file to bios.bin in your home directory.<br />
<br />
=== Building Qemu ===<br />
<br />
If you plan to run Qemu version 0.9.0, you will have to build QEMU from source after applying a couple of patches. (Later versions of QEMU might incorporate these patches, allowing you to run them unmodified; hopefully someone will be kind enough to update this tutorial if this happens.)<br />
<br />
Download the QEMU source code (I used qemu-0.9.0.tar.gz) and extract it.<br />
<br />
Download these two patches and save them to the QEMU source directory:<br />
* [http://xenon.stanford.edu/~eswierk/misc/qemu-linuxbios/qemu-isa-bios-ram.patch qemu-isa-bios-ram.patch]<br />
* [http://xenon.stanford.edu/~eswierk/misc/qemu-linuxbios/qemu-piix-ram-size.patch qemu-piix-ram-size.patch]<br />
<br />
Enter the QEMU source directory and apply the patches:<br />
$ patch -p1 < qemu-isa-bios-ram.patch<br />
$ patch -p1 < qemu-piix-ram-size.patch<br />
<br />
Configure and make QEMU (use the --cc option if your default gcc is newer than version 3.4):<br />
$ ./configure --cc=gcc34 --target-list=i386-softmmu && make<br />
<br />
The QEMU binary is stored in the i386-softmmu directory.<br />
<br />
=== Creating a hard disk image ===<br />
<br />
If you are using FILO, you must create a hard disk image containing the Linux kernel and optional initramfs that FILO loads.<br />
<br />
Whether or not you use FILO, you may also wish to populate the disk image with the root filesystem of whatever Linux distribution you want to run.<br />
<br />
Create an empty disk image:<br />
$ qemu-img create -f raw disk.img 200M<br />
<br />
Format it:<br />
$ mkfs.ext2 -F disk.img <br />
<br />
The remaining steps must be performed as root. Create a temporary mountpoint and mount the image:<br />
# mkdir /mnt/rootfs<br />
# mount -o loop disk.img /mnt/rootfs<br />
<br />
Create a boot directory and copy your Linux kernel (vmlinuz) and initramfs (initrd) to it:<br />
# mkdir /mnt/rootfs/boot<br />
# cp vmlinuz /mnt/rootfs/boot/vmlinuz<br />
# cp initrd /mnt/rootfs/boot/initrd<br />
<br />
At this point, you can also copy a complete root filesystem to the disk image. <br />
# cp -R /* /mnt/rootfs <br />
<br />
Alternatively, with Debian you can use the debootstrap command to create a basic root filesystem:<br />
# debootstrap --arch i386 sarge /mnt/rootfs http://ftp.debian.org/debian/ <br />
<br />
If you are using a debootstrap filesystem, open the file /mnt/rootfs/etc/inittab and change runlevel to level 1:<br />
id:1:initdefault: <br />
<br />
cd out of /mnt/rootfs and umount it:<br />
# umount /mnt/rootfs<br />
<br />
Exit from the root account:<br />
# exit<br />
<br />
=== Starting LinuxBIOS in QEMU ===<br />
<br />
Execute QEMU using the following parameters:<br />
$ qemu -L ~ -hda disk.img -nographic<br />
<br />
The -L option tells QEMU to look for bios.bin in your $HOME directory. The -nographic option suppresses the graphical VGA display and connects the virtual machine's serial port to your console.<br />
<br />
You should now see all sorts of interesting LinuxBIOS messages, followed by Linux kernel boot messages or a FILO prompt.<br />
<br />
If you are using FILO, enter at the boot: prompt:<br />
boot: hda:/boot/vmlinuz root=/dev/hda initrd=/boot/initrd console=ttyS0<br />
<br />
Example:<br />
<br />
[[Image:Screenshot linuxbios boots qemu.png]]<br />
[[Category:Testing]]</div>Robhttps://www.coreboot.org/index.php?title=QEMU_Build_Tutorial&diff=3967QEMU Build Tutorial2007-03-09T03:16:51Z<p>Rob: </p>
<hr />
<div>=== Introduction ===<br />
<br />
If you don't have a mainboard supported by LinuxBIOS don't worry: [http://qemu.org/ QEMU] can help you to emulate one.<br />
<br />
This nice tutorial was written by [mailto:acassis@gmail.com Alan Carvalho de Assis], with additions by [mailto:eswierk@arastra.com Ed Swierk] (but please use the [[Mailinglist|LinuxBIOS mailing list]] rather than emailing the authors directly).<br />
<br />
While there are many ways to use LinuxBIOS to load and run a Linux kernel, this tutorial covers two of the most common:<br />
<br />
* LinuxBIOS with [[FILO]] as payload, using FILO to load a Linux kernel (and optional initramfs) from a hard disk image. This approach involves a bit more mechanism (it relies on FILO's built-in disk and filesystem drivers) but it produces a tiny LinuxBIOS image.<br />
* LinuxBIOS with a Linux kernel (and optional initramfs) as payload. This cuts FILO out of the picture, but the main challenge with is approach is squeezing the resulting LinuxBIOS image into QEMU's BIOS ROM area (currently 2 MB, but easy to extend by patching QEMU).<br />
<br />
=== Requirements === <br />
<br />
You need the following software packages:<br />
<br />
* [[Download_LinuxBIOS|LinuxBIOSv2]] r2405 or greater<br />
* [http://qemu.org/ Qemu] 0.9.0 or greater<br />
* [[FILO]] 0.4.2 or greater (if using FILO)<br />
* [ftp://ftp.lnxi.com/pub/mkelfImage mkelfImage] 2.7 or greater (if not using FILO)<br />
<br />
plus a Linux kernel and root filesystem and a working development environment (make, gcc, etc.). gcc 4.0.x and 4.1.x are known to work for all packages except QEMU, which requires gcc 3.x.<br />
<br />
=== Building or finding a Linux kernel ===<br />
<br />
If you are using FILO, you can simply grab a Linux kernel and initramfs from your favorite distribution.<br />
<br />
Otherwise, you will probably need to build a kernel and initramfs from scratch, ensuring that the final LinuxBIOS image does not exceed QEMU's BIOS size limit. Building the kernel and initramfs is beyond the scope of this tutorial; how you configure them depends on your application.<br />
<br />
If you plan to use kexec to chain-boot another Linux kernel, tools from these projects can help automate the process of generating a kernel and initramfs:<br />
* [http://kboot.sourceforge.net/ kboot]<br />
* [http://wiki.laptop.org/go/Building_LinuxBIOS OLPC buildrom]<br />
<br />
=== Building a FILO payload ===<br />
<br />
If you plan to build your Linux kernel and root filesystem directly into LinuxBIOS, you can skip this section.<br />
<br />
Download FILO (I used filo-0.4.2.tar.bz2), decompress it, and cd to the created directory.<br />
<br />
First invocation of make creates the default Config file.<br />
$ make<br />
<br />
Edit this file as you like. The default configuration worked for me. <br />
$ vi Config <br />
<br />
Run make again to create filo.elf, the ELF FILO image. <br />
$ make <br />
<br />
You will use this file (filo.elf) as the LinuxBIOS payload later on.<br />
<br />
=== Building a Linux kernel payload ===<br />
<br />
If you are using FILO, skip this section.<br />
<br />
Download mkelfImage (I used mkelfImage-2.7.tar.gz), decompress it, and cd to the created directory.<br />
<br />
Configure and build the mkelfImage binary.<br />
$ ./configure && make<br />
<br />
Now use mkelfImage to convert your Linux kernel image (vmlinuz) and initramfs (initrd) into a usable LinuxBIOS payload (linux.elf):<br />
$ mkelfImage --append="console=ttyS0" --initrd=initrd vmlinuz linux.elf<br />
<br />
=== Building LinuxBIOS ===<br />
<br />
Download the LinuxBIOS source code (I used LinuxBIOSv2-2405) and extract it. <br />
<br />
Change to directory targets/emulation/qemu-i386 and modify Config.lb:<br />
* change payload to point to your payload (filo.elf or linux.elf)<br />
* if you are using a Linux payload, increase the value of option ROM_SIZE to 2048*1024 (2 MB)<br />
<br />
Return to targets directory and execute: <br />
$ ./buildtarget emulation/qemu-i386 <br />
<br />
Go to targets/emulation/qemu-i386/qemu-i386 and execute: <br />
$ make <br />
<br />
This creates the LinuxBIOS image (qemu-bios.rom). Copy and rename this file to bios.bin in your home directory.<br />
<br />
=== Building Qemu ===<br />
<br />
If you plan to run Qemu version 0.9.0, you will have to build QEMU from source after applying a couple of patches. (Later versions of QEMU might incorporate these patches, allowing you to run them unmodified; hopefully someone will be kind enough to update this tutorial if this happens.)<br />
<br />
Download the QEMU source code (I used qemu-0.9.0.tar.gz) and extract it.<br />
<br />
Download these two patches and save them to the QEMU source directory:<br />
* [http://xenon.stanford.edu/~eswierk/misc/qemu-linuxbios/qemu-isa-bios-ram.patch qemu-isa-bios-ram.patch]<br />
* [http://xenon.stanford.edu/~eswierk/misc/qemu-linuxbios/qemu-piix-ram-size.patch qemu-piix-ram-size.patch]<br />
<br />
Enter the QEMU source directory and apply the patches:<br />
$ patch -p1 < qemu-isa-bios-ram.patch<br />
$ patch -p1 < qemu-piix-ram-size.patch<br />
<br />
Configure and make QEMU (use the --cc option if your default gcc is newer than version 3.4):<br />
$ ./configure --cc=gcc34 --target-list=i386-softmmu && make<br />
<br />
The QEMU binary is stored in the i386-softmmu directory.<br />
<br />
=== Creating a hard disk image ===<br />
<br />
If you are using FILO, you must create a hard disk image containing the Linux kernel and optional initramfs that FILO loads.<br />
<br />
Whether or not you use FILO, you may also wish to populate the disk image with the root filesystem of whatever Linux distribution you want to run.<br />
<br />
Create an empty disk image:<br />
$ qemu-img create -f raw disk.img 200M<br />
<br />
Format it:<br />
$ mkfs.ext2 -F disk.img <br />
<br />
The remaining steps must be performed as root. Create a temporary mountpoint and mount the image:<br />
# mkdir /mnt/rootfs<br />
# mount -o loop disk.img /mnt/rootfs<br />
<br />
Create a boot directory and copy your Linux kernel (vmlinuz) and initramfs (initrd) to it:<br />
# mkdir /mnt/rootfs/boot<br />
# cp vmlinuz /mnt/rootfs/boot/vmlinuz<br />
# cp initrd /mnt/rootfs/boot/initrd<br />
<br />
At this point, you can also copy a complete root filesystem to the disk image. <br />
# cp -R /* /mnt/rootfs <br />
<br />
Alternatively, with Debian you can use the debootstrap command to create a basic root filesystem:<br />
# debootstrap --arch i386 sarge /mnt/rootfs http://ftp.debian.org/debian/ <br />
<br />
If you are using a debootstrap filesystem, open the file /mnt/rootfs/etc/inittab and change runlevel to level 1:<br />
id:1:initdefault: <br />
<br />
cd out of /mnt/rootfs and umount it:<br />
# umount /mnt/rootfs<br />
<br />
Exit from the root account:<br />
# exit<br />
<br />
=== Starting LinuxBIOS in QEMU ===<br />
<br />
Execute QEMU using the following parameters:<br />
$ qemu -L ~ -hda disk.img -nographic<br />
<br />
The -L option tells QEMU to look for bios.bin in your $HOME directory. The -nographic option suppresses the graphical VGA display and connects the virtual machine's serial port to your console.<br />
<br />
You should now see all sorts of interesting LinuxBIOS messages, followed by Linux kernel boot messages or a FILO prompt.<br />
<br />
If you are using FILO, enter at the boot: prompt:<br />
boot: hda:/boot/vmlinuz root=/dev/hda initrd=/boot/initrd console=ttyS0<br />
<br />
Example:<br />
<br />
[[Image:Screenshot linuxbios boots qemu.png]]<br />
[[Category:Testing]</div>Robhttps://www.coreboot.org/index.php?title=QEMU&diff=3966QEMU2007-03-09T03:16:20Z<p>Rob: </p>
<hr />
<div>You can easily try out LinuxBIOS using [http://qemu.org/ QEMU], without having to actually flash the BIOS chip on your real hardware.<br />
<br />
== Tutorials ==<br />
<br />
* [[QEMU Build Tutorial]] &mdash; Starting a Debian GNU/Linux system via LinuxBIOS + a Linux kernel, or via LinuxBIOS + [[FILO]].<br />
<br />
== Ready-made QEMU images ==<br />
<br />
We'll soon provide various downloadable QEMU images you can use to try out LinuxBIOS.<br />
<br />
TODO.<br />
[[Category: Testing]]</div>Robhttps://www.coreboot.org/index.php?title=Talk:QEMU&diff=3902Talk:QEMU2007-03-05T22:28:03Z<p>Rob: </p>
<hr />
<div>I'd be interested in building some images for QEMU. I have done this already with OS images, but not sure how to target QEMU for linuxbios images. What 'chipset' does QEMU use? Is there a generic virtual flash device? --[[User:Rob|Rob]] 23:25, 5 March 2007 (CET)<br />
:Ignore that, found the answer.</div>Robhttps://www.coreboot.org/index.php?title=Talk:QEMU&diff=3901Talk:QEMU2007-03-05T22:25:15Z<p>Rob: question about qemu linuxbios</p>
<hr />
<div>I'd be interested in building some images for QEMU. I have done this already with OS images, but not sure how to target QEMU for linuxbios images. What 'chipset' does QEMU use? Is there a generic virtual flash device? --[[User:Rob|Rob]] 23:25, 5 March 2007 (CET)</div>Robhttps://www.coreboot.org/index.php?title=User:Rob&diff=3900User:Rob2007-03-05T22:22:27Z<p>Rob: small bio</p>
<hr />
<div>I am interested in embedded systems based on linux and free software. BIOS is an important part of the overall ''applicance'' in an embedded device. I would like to create a media device based on my design ideas. <br />
<br />
==Links==<br />
*[http://organicdesign.co.nz/User:Rob My user page on organicdesign]<br />
*[http://organicdesign.co.nz/wiki/index.php?title=Special:Contributions&target=Rob My recent contributions]<br />
*[http://organicdesign.co.nz/Peerix Operating system ideas]</div>Rob