diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml new file mode 100644 index 0000000..5016564 --- /dev/null +++ b/.github/workflows/ccpp.yml @@ -0,0 +1,16 @@ +name: bios-build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: make + run: make + - name: Upload bios.bin + uses: actions/upload-artifact@v1 + with: + name: bios.bin + path: build/bios.bin diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..188c59c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build +*.o +*.d +*.bin +*.elf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2b6eebb --- /dev/null +++ b/Makefile @@ -0,0 +1,80 @@ +CC ?= $(CROSS)gcc +AS ?= $(CROSS)gcc +OBJCOPY ?= $(CROSS)objcopy +O ?= build + +all: $O/bios.bin +ROMSIZE = 65536 + +$O: ; mkdir -p $@ + +CFLAGS = \ + -W \ + -Wall \ + -m32 \ + -march=i386 \ + -mregparm=3 \ + -fno-stack-protector \ + -fno-delete-null-pointer-checks \ + -ffreestanding \ + -mstringop-strategy=rep_byte \ + -minline-all-stringops \ + -fno-pic \ + -Iinclude \ + -MT $@ \ + -MMD -MP \ + -MF $O/$*.d \ + +ASFLAGS = $(CFLAGS) + +LDFLAGS = \ + -nostdlib \ + -m32 \ + -Wl,--build-id=none \ + -Wl,-Tflat.lds \ + +OBJS = \ + code16.o \ + code32seg.o \ + cstart.o \ + entry.o \ + fw_cfg.o \ + hwsetup.o \ + linuxboot.o \ + main.o \ + malloc.o \ + mptable.o \ + pci.o \ + printf.o \ + string.o \ + smbios.o \ + tables.o \ + +$O/bios.elf: $(addprefix $O/,$(OBJS)) + $(CC) $(LDFLAGS) -o $@ $^ + +$O/%.bin: $O/%.elf + $(OBJCOPY) \ + -O binary \ + -j .text \ + -j .rodata \ + -j .data \ + -j .bss \ + -j .init \ + $< \ + "$@.tmp" + @if [ `stat -c '%s' "$@.tmp"` != $(ROMSIZE) ]; then \ + echo >&2 '$@ != $(ROMSIZE) bytes!' ; \ + exit 1 ; \ + fi + mv "$@.tmp" "$@" + +$O/%.o: %.c | $O + $(CC) $(CFLAGS) -c -o $@ $< +$O/%.o: %.S | $O + $(CC) $(ASFLAGS) -c -o $@ $< + +clean: + $(RM) $O/*.o $O/bios.bin $O/bios.bin.elf $O/*.d + +-include $O/*.d diff --git a/README b/README.md similarity index 83% rename from README rename to README.md index c913357..88e340b 100644 --- a/README +++ b/README.md @@ -1,3 +1,5 @@ +[![Build status](../../workflows/bios-build/badge.svg)](../../actions?query=workflow%3Abios-build) + A simple x86 firmware that can boot Linux. Most of QEMU's startup time is spent: @@ -5,6 +7,7 @@ Most of QEMU's startup time is spent: * in the dynamic linker. This can be reduced by 150 ms simply by compiling a stripped down QEMU: +``` ./configure --disable-libssh2 --disable-tcmalloc --disable-glusterfs \ --disable-seccomp --disable-{bzip2,snappy,lzo} --disable-usb-redir \ --disable-libusb --disable-smartcard-nss --disable-libnfs \ @@ -14,13 +17,14 @@ Most of QEMU's startup time is spent: --disable-fdt --disable-curl --disable-curses --disable-sdl \ --disable-gtk --disable-tpm --disable-vte --disable-vnc \ --disable-xen --disable-opengl --target-list=x86_64-softmmu +``` * in the BIOS. qboot saves another 150 ms. -* until QEMU 2.7+, in fw_cfg. qboot uses the DMA interface which is pretty +* until QEMU 2.7+, in `fw_cfg`. qboot uses the DMA interface which is pretty much instantaneous. -Compile qboot +Compile `qboot` ============= Clone the source: @@ -30,9 +34,9 @@ Clone the source: Compile the qboot firmware (you may need to install the relevant build time dependancies): - $ meson build && ninja -C build + $ make -The result will be a 64K file named bios.bin under the build/ directory. +The result will be a 64K file named `build/bios.bin`. Usage ===== diff --git a/meson.build b/meson.build deleted file mode 100644 index ce291a3..0000000 --- a/meson.build +++ /dev/null @@ -1,52 +0,0 @@ -project('qboot', 'c') - -cc = meson.get_compiler('c') -objcopy = find_program('objcopy') - -c_args = [ - '-m32', - '-march=i386', - '-mregparm=3', - '-fno-stack-protector', - '-fno-delete-null-pointer-checks', - '-ffreestanding', - '-mstringop-strategy=rep_byte', - '-minline-all-stringops', - '-fno-pic', -] - -link_args = ['-nostdlib', '-m32'] -link_args += cc.get_supported_link_arguments('-Wl,--build-id=none') -link_args += '-Wl,-T' + meson.current_source_dir() / 'flat.lds' - -elf = executable( - 'bios.bin.elf', - files( - 'code16.c', - 'code32seg.c', - 'cstart.S', - 'entry.S', - 'fw_cfg.c', - 'hwsetup.c', - 'linuxboot.c', - 'main.c', - 'malloc.c', - 'mptable.c', - 'pci.c', - 'printf.c', - 'string.c', - 'smbios.c', - 'tables.c', - ), - c_args: c_args, - include_directories: include_directories('include'), - link_args: link_args, -) - -bin = custom_target( - 'bios.bin', - output: 'bios.bin', - input: elf, - command: [objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@'], - build_by_default: true, -)