diff --git a/Makefile b/Makefile index 582c1f1..424beed 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ export MENUCONFIG_STYLE = aquatic export OSCONFIG_ASM = include/osconfig.asm # Output related BIN=os.bin +# As the first section of the OS must be RST_VECTORS, the final binary is named os_RST_VECTORS.bin +BIN_GENERATED=os_RST_VECTORS.bin BINDIR=build FULLBIN=$(BINDIR)/$(BIN) MAPFILE=os.map @@ -54,7 +56,7 @@ endef # - $2: Variable name where INCLUDES will be stored # - $3: Variable name where PRECMD will be stored # - $4: Variable name where POSTCMD will be stored -define IMPORT_subunitmk = +define IMPORT_subunitmk = SUBMKFILE = $$(wildcard */$$(MKFILE)) TMP1 := TMP2 := @@ -87,15 +89,17 @@ LINKERFILE_BUILT=$(BINDIR)/$(LINKERFILE_OBJ) all:$(KCONFIG_CONFIG) version packer precmd $(LINKERFILE_OBJ) $(OBJS) $(CC) -o$(FULLBIN) -b -m -s $(LINKERFILE_BUILT) $(BUILTOBJS) + @mv $(BINDIR)/$(BIN_GENERATED) $(FULLBIN) @echo "OS binary: $(FULLBIN)" @echo "Executing post commands..." $(POSTCMD) - # Generate a version file that will be used as a boilerplate - # when the system starts +# Generate a version file that will be used as a boilerplate when the system starts +# We add the build time to the file only if reproducible build is not enabled version: @echo Zeal 8-bit OS `git describe --tags` > version.txt - @echo Build time: `date +"%Y-%m-%d %H:%M"` >> version.txt + @[ -z "$(CONFIG_KERNEL_REPRODUCIBLE_BUILD)" ] && \ + echo Build time: `date +"%Y-%m-%d %H:%M"` >> version.txt || true packer: @echo "Building packer" @@ -105,7 +109,7 @@ precmd: @echo "Executing pre commands..." @$(PRECMD) -# Check if configuration file exists +# Check if configuration file exists $(KCONFIG_CONFIG): @test -e $@ || { echo "Configuration file $@ could not be found. Please run make menuconfig first"; exit 1; } @@ -145,10 +149,10 @@ prepare_dirs: @mkdir -p $(BINDIR) dump: - $(DISASSEMBLER) -x $(BINDIR)/os.map $(BINDIR)/$(BIN) | less + $(DISASSEMBLER) -x $(BINDIR)/$(MAPFILE) $(BINDIR)/$(BIN) | less fdump: - $(DISASSEMBLER) -x $(BINDIR)/os.map $(BINDIR)/$(BIN) > $(BINDIR)/os.dump + $(DISASSEMBLER) -x $(BINDIR)/$(MAPFILE) $(BINDIR)/$(BIN) > $(BINDIR)/os.dump clean: rm -rf $(OSCONFIG_ASM) $(BINDIR) $(KCONFIG_CONFIG) version.txt diff --git a/kernel/Kconfig b/kernel/Kconfig index 1853303..d0f3687 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -1,5 +1,13 @@ menu "Kernel configuration" - + + config KERNEL_REPRODUCIBLE_BUILD + bool "Generate a reproducible binary" + default n + help + When this option is enabled, compiling the project several times with + the same configuration will produce the exact same binary. Thus, information + like build time will be excluded from the binary. + config KERNEL_STACK_ADDR hex "Kernel Stack virtual address" default 0xFFFF @@ -7,7 +15,7 @@ menu "Kernel configuration" help After initializing the MMU, the kernel will set the Stack Pointer (SP). This value defines the top of the stack in the virtual memory. - This address must point to RAM. + This address must point to RAM. config KERNEL_COLDBOOT_HOOK bool "Hook routine at coldboot" @@ -57,7 +65,7 @@ menu "Kernel configuration" help Maximum length of a single absolute file path. Incrementing this value will make the kernel use more RAM. - + config KERNEL_INIT_EXECUTABLE string "Executable to launch on boot" default "A:/init.bin" @@ -79,5 +87,5 @@ menu "Kernel configuration" help Kernel logger, by default, prints logs without any color. However, if this option is enable, it will be able to print error messages in red, warning messages in yellow - and info messages in green. + and info messages in green. endmenu \ No newline at end of file diff --git a/target/zeal8bit/unit.mk b/target/zeal8bit/unit.mk index 08af317..1e1af5d 100644 --- a/target/zeal8bit/unit.mk +++ b/target/zeal8bit/unit.mk @@ -2,6 +2,9 @@ INCLUDES := ./ ./include SRCS := pio.asm i2c.asm keyboard.asm romdisk.asm mmu.asm interrupt_vect.asm +# Add the suffix "_romdisk" to the full binary name +FULLBIN_W_ROMDISK = $(basename $(FULLBIN))_with_romdisk.img + # If the UART is configured as the standard output, it shall be the first driver to initialize ifdef CONFIG_TARGET_STDOUT_UART SRCS := uart.asm $(SRCS) @@ -19,27 +22,27 @@ else endif endif -# Load the video driver first, in order to get an output early on - - # Command to be executed before compiling the whole OS. - # In our case, compile the programs that will be part of ROMDISK and create it. - # After creation, get its size, thanks to `stat` command, and store it in a generated header file - # named `romdisk_info_h.asm` +# Command to be executed before compiling the whole OS. +# In our case, compile the programs that will be part of ROMDISK and create it. +# After creation, get its size, thanks to `stat` command, and store it in a generated header file +# named `romdisk_info_h.asm` PRECMD := (cd $(PWD)/romdisk && make) && \ SIZE=$$(stat -c %s $(PWD)/romdisk/disk.img) && \ (echo -e "IFNDEF ROMDISK_H\nDEFINE ROMDISK_H\nDEFC ROMDISK_SIZE=$$SIZE\nENDIF" > $(PWD)/include/romdisk_info_h.asm) && \ - unset SIZE + unset SIZE - # After compiling the whole OS, we need to remove the unecessary binaries: - # In our case, it's the binary containing BSS addresses, so we only have to keep - # the one containing the actual code. The filename comes from the linker's first - # section name: RST_VECTORS - # FULLBIN defines the expected final binary path/name. - # After selecting the rigth binary, we have to truncate it to a size that will let us - # easily concatenate the ROMDISK after it. - # Of course, the final step is to concatenate the ROMDISK to the final binary after that. +# After compiling the whole OS, we need to remove the unnecessary binaries: +# In our case, it's the binary containing BSS addresses, so we only have to keep +# the one containing the actual code. The filename comes from the linker's first +# section name: RST_VECTORS +# FULLBIN defines the expected final binary path/name. +# After selecting the right binary, we have to truncate it to a size that will let us +# easily concatenate the ROMDISK after it. +# Of course, the final step is to concatenate the ROMDISK to the final binary after that. POSTCMD := @echo "RAM used by kernel: $$(du -bs $(BINDIR)/*KERNEL_BSS*.bin | cut -f1) bytes" && \ - rm $(BINDIR)/*KERNEL_BSS*.bin && mv $(BINDIR)/*RST_VECTORS*.bin $(FULLBIN) && \ - echo "OS size: $$(du -bs $(FULLBIN) | cut -f1) bytes" && \ - truncate -s $$(( $(CONFIG_ROMDISK_ADDRESS) - $(CONFIG_KERNEL_PHYS_ADDRESS) )) $(FULLBIN) && \ - cat $(PWD)/romdisk/disk.img >> $(FULLBIN) \ No newline at end of file + rm $(BINDIR)/*KERNEL_BSS*.bin && \ + echo "OS size: $$(du -bs $(FULLBIN) | cut -f1) bytes" && \ + cp $(FULLBIN) $(FULLBIN_W_ROMDISK) && \ + truncate -s $$(( $(CONFIG_ROMDISK_ADDRESS) - $(CONFIG_KERNEL_PHYS_ADDRESS) )) $(FULLBIN_W_ROMDISK) && \ + cat $(PWD)/romdisk/disk.img >> $(FULLBIN_W_ROMDISK) && \ + echo "Image size: $$(du -bs $(FULLBIN_W_ROMDISK) | cut -f1) bytes"