Skip to content

Commit

Permalink
QEMU without ISO image (#102)
Browse files Browse the repository at this point in the history
Pass the kernel image, initial RAM disk and kernel command line directly
to QEMU instead of building an ISO image.
  • Loading branch information
phaubertin authored Dec 5, 2024
1 parent 74c491f commit cc2136e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-i686.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:

- name: Install dependencies
run: sudo apt update && sudo apt-get install -y gcc-multilib grub-common nasm qemu-system-x86 xorriso
run: sudo apt update && sudo apt-get install -y gcc-multilib nasm qemu-system-x86

- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ vbox-debug:
vbox-run:
make -C $(virtualbox) run

# build the ISO file (CDROM image) needed by the QEMU
# build the dependencies for running the test application in QEMU
.PHONY: qemu
qemu:
make -C $(qemu)
Expand Down
27 changes: 4 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ be provided by the user in order to use the kernel. However, an initial
RAM disk containing a test application can be built from this
repository.

Finally, this repository makes it easy to run the kernel and test
application in QEMU. For this purpose, it builds a bootable ISO image
that contains the kernel image and the initial RAM disk.

Build Requirements
------------------

Expand All @@ -33,9 +29,6 @@ This software is known to build with GCC and clang.

You also need the Netwide Assembler (NASM).

If you wish to build the ISO image for use with QEMU, which is optional,
you need GRUB and GNU xorriso in addition to the above.

Run Time Requirements
---------------------

Expand Down Expand Up @@ -70,25 +63,13 @@ do this once, not each time you build.
./configure
```

To build the ISO image for use with QEMU, build the `qemu` target with
make:

```
make qemu
```

This builds the kernel image and the test application, and then creates
a bootable ISO image.

If you will not be using QEMU and only want to build the kernel image,
this can be done with the default make target:
To build the kernel image, use the default make target:

```
make
```

Similarly, the test application can be built separately with the
`testapp` make target:
To build the test application, use the `testapp` make target:

```
make testapp
Expand Down Expand Up @@ -126,8 +107,8 @@ make qemu-check
How to Install
--------------

If you will not be using QEMU for testing, you can copy the kernel image
to `/boot` by running the following:
If you will be testing on real hardware instead of in QEMU, you can copy the
kernel image to `/boot` by running the following:

```
sudo make install
Expand Down
111 changes: 38 additions & 73 deletions devel/qemu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,54 @@ include $(jinue_root)/header.mk
QEMU_CPU ?= core2duo
QEMU_MEM ?= 128

# GRUB location (for creation of bootable ISO for virtual machine)
#
# TODO this should probably be configurable through some sort of configure script
grub_modules = /usr/lib/grub/i386-pc
CMDLINE = \
on_panic=reboot \
serial_enable=yes \
serial_dev=/dev/ttyS0 \
DEBUG_DUMP_MEMORY_MAP=1 \
DEBUG_DUMP_SYSCALL_IMPLEMENTATION=1 \
DEBUG_DUMP_RAMDISK=1 \
DEBUG_DO_REBOOT=1 \
RUN_TEST_ACPI=1 \
RUN_TEST_IPC=1

temp_iso_fs = iso-tmp
grub_config = grub.cfg
jinue_iso = jinue.iso
grub_image_rel = boot/grub/i386-pc/jinue.img
grub_image = $(temp_iso_fs)/$(grub_image_rel)
kernel_img_copy = $(temp_iso_fs)/boot/$(notdir $(kernel_img))
initrd_copy = $(temp_iso_fs)/boot/$(notdir $(testapp_initrd))
run_log = run-jinue.log
check_script = check-log.sh

target = $(jinue_iso)
unclean_recursive = $(temp_iso_fs)
deps = $(kernel_img) $(testapp_initrd)
targets.phony = all-deps

include $(common)

.PHONY: all-deps
all-deps: $(deps)

.PHONY: run
run: $(jinue_iso)
qemu-system-i386 \
-cpu $(QEMU_CPU) \
-m $(QEMU_MEM) \
-no-reboot \
-drive format=raw,media=cdrom,file=$(jinue_iso) \
-serial stdio \
-smp 1 \
-usb \
run: $(deps)
qemu-system-i386 \
-cpu $(QEMU_CPU) \
-m $(QEMU_MEM) \
-no-reboot \
-kernel $(kernel_img) \
-initrd $(testapp_initrd) \
-append "$(CMDLINE)" \
-serial stdio \
-smp 1 \
-usb \
-vga std | tee $(run_log)

.PHONY: run-no-display
run-no-display: $(jinue_iso)
qemu-system-i386 \
-cpu $(QEMU_CPU) \
-m $(QEMU_MEM) \
-no-reboot \
-drive format=raw,media=cdrom,file=$(jinue_iso) \
-serial stdio \
-display none \
-smp 1 \
-usb \
run-no-display: $(deps)
qemu-system-i386 \
-cpu $(QEMU_CPU) \
-m $(QEMU_MEM) \
-no-reboot \
-kernel $(kernel_img) \
-initrd $(testapp_initrd) \
-append "$(CMDLINE)" \
-serial stdio \
-display none \
-smp 1 \
-usb \
-vga std | tee $(run_log)

.PHONY: check
Expand All @@ -94,44 +99,4 @@ $(kernel_img): kernel-image

$(testapp_initrd): testapp-initrd

$(temp_iso_fs): $(grub_config)
mkdir -p $(temp_iso_fs)/boot/grub/i386-pc
cp $(grub_modules)/* $(temp_iso_fs)/boot/grub/i386-pc/
cp $(grub_config) $(temp_iso_fs)/boot/grub/
touch $(temp_iso_fs)

$(kernel_img_copy): $(kernel_img) $(temp_iso_fs) kernel-image
cp $< $@

$(initrd_copy): $(testapp_initrd) $(temp_iso_fs) testapp-initrd
cp $< $@

$(grub_image): $(initrd_copy) $(kernel_img_copy)
`grub2-mkimage --version > /dev/null 2>&1 && echo grub2-mkimage || echo grub-mkimage` \
--prefix '/boot/grub' \
--output $(grub_image) \
--format i386-pc-eltorito \
--compression auto \
--config $(grub_config) \
biosdisk iso9660

$(jinue_iso): $(grub_image)
xorriso \
-as mkisofs \
-graft-points \
-b $(grub_image_rel) \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--grub2-boot-info \
--grub2-mbr \
$(grub_modules)/boot_hybrid.img \
--protective-msdos-label \
-o $(jinue_iso) \
-r $(temp_iso_fs) \
--sort-weight 0 \
/ \
--sort-weight 1 \
/boot

$(run_log): run-no-display
41 changes: 0 additions & 41 deletions devel/qemu/grub.cfg

This file was deleted.

13 changes: 4 additions & 9 deletions devel/virtualbox/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ $(testapp_initrd): testapp-initrd

$(temp_iso_fs): $(grub_config)
mkdir -p $(temp_iso_fs)/boot/grub/i386-pc
cp $(grub_modules)/* $(temp_iso_fs)/boot/grub/i386-pc/
cp $(grub_config) $(temp_iso_fs)/boot/grub/
touch $(temp_iso_fs)

Expand All @@ -88,8 +87,7 @@ $(grub_image): $(initrd_copy) $(kernel_img_copy)
--output $(grub_image) \
--format i386-pc-eltorito \
--compression auto \
--config $(grub_config) \
biosdisk iso9660
biosdisk iso9660 linux linux16

$(jinue_iso): $(grub_image)
xorriso \
Expand All @@ -100,12 +98,9 @@ $(jinue_iso): $(grub_image)
-boot-load-size 4 \
-boot-info-table \
--grub2-boot-info \
--grub2-mbr \
$(grub_modules)/boot_hybrid.img \
--grub2-mbr $(grub_modules)/boot_hybrid.img \
--protective-msdos-label \
-o $(jinue_iso) \
-r $(temp_iso_fs) \
--sort-weight 0 \
/ \
--sort-weight 1 \
/boot
--sort-weight 0 / \
--sort-weight 1 /boot

0 comments on commit cc2136e

Please sign in to comment.