Skip to content

Commit

Permalink
Support for Multiple User Configs (#38)
Browse files Browse the repository at this point in the history
build: add support for multiple configuration

* Added user-defined config files
* Added default `os.conf` for hardware
* Added default `emulator.conf` for emulator
* Added `ZOS_CONFIG` env var support to override the default `os.conf` when calling `make`
* Updated CI to reference `emulator.conf`
* Move defaults configs into `configs/*.default`
* `make menuconfig` will now copy over the default `os.conf` for backwards compatibility and user-defined defaults

Co-authored-by: Zeal 8-bit <zeal8bit@gmail.com>
  • Loading branch information
zoul0813 and Zeal8bit authored Oct 13, 2024
1 parent 4bfcaac commit 01bfd25
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 22 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/build_zeal8bitos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ jobs:
- name: Build Zeal 8-bit OS (zeal8bit target)
shell: bash
run: |
make alldefconfig
echo 'CONFIG_ENABLE_EMULATION_HOSTFS=y' >> os.conf
make asmconf
z88dk-z80asm
make
make config=configs/zealemu.default
mv build/os_with_romdisk.img build/$(git describe --tags).img
- name: Update index.json
Expand Down
46 changes: 29 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ ifndef PYTHON_BIN
endif
export PATH := $(realpath packer)/:$(PATH)
# Kconfig related
export KCONFIG_CONFIG = os.conf
export KCONFIG_CONFIG = configs/zeal8bit.default
ifneq ("$(wildcard os.conf)", "")
export KCONFIG_CONFIG = os.conf
endif
ifdef config
export KCONFIG_CONFIG = $(config)
else
ifdef ZOS_CONFIG
export KCONFIG_CONFIG = $(ZOS_CONFIG)
endif
endif

export MENUCONFIG_STYLE = aquatic
export OSCONFIG_ASM = include/osconfig.asm
export ZOS_PATH := $(PWD)
Expand Down Expand Up @@ -88,7 +99,7 @@ endef
# If the target is not defined, no os.conf file was created.
# In that case, do not try to evaluate the build depenendies.
ifdef CONFIG_TARGET
$(eval $(call IMPORT_subunitmk,ASMSRCS,INCLUDEDIRS,PRECMD,POSTCMD))
$(eval $(call IMPORT_subunitmk,ASMSRCS,INCLUDEDIRS,PRECMD,POSTCMD))
endif

# Generate the .o files out of the .c files
Expand All @@ -103,19 +114,22 @@ LINKERFILE_BUILT=$(BINDIR)/$(LINKERFILE_OBJ)

.PHONY: check menuconfig $(SUBDIRS) version packer asmconf

all:$(KCONFIG_CONFIG) version packer precmd $(LINKERFILE_OBJ) $(OBJS)
all:$(KCONFIG_CONFIG) asmconf version packer precmd $(LINKERFILE_OBJ) $(OBJS)
$(CC) $(ASMFLAGS) -o$(FULLBIN) -b -m -s $(LINKERFILE_BUILT) $(BUILTOBJS)
@mv $(BINDIR)/$(BIN_GENERATED) $(FULLBIN)
@echo "OS binary: $(FULLBIN)"
@echo "Executing post commands..."
@echo "Config: $(KCONFIG_CONFIG)"
@echo "Kernel Physical Address: $(CONFIG_KERNEL_PHYS_ADDRESS)"
@echo "Host FS: $(CONFIG_ENABLE_EMULATION_HOSTFS)"
@echo "OS binary: $(FULLBIN)"
$(POSTCMD)

# 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
@[ -z "$(CONFIG_KERNEL_REPRODUCIBLE_BUILD)" ] && \
echo Build time: `date +"%Y-%m-%d %H:%M"` >> version.txt || true
echo Build time: `date +"%Y-%m-%d %H:%M"` >> version.txt || true

packer:
@echo "Building packer"
Expand Down Expand Up @@ -147,28 +161,26 @@ check:
# DEFM "test", 0
# ENDM
define CONVERT_config_asm =
echo -e "IFNDEF OSCONFIG_H\nDEFINE OSCONFIG_H\n" > $2 && \
cat $1 | \
grep "^CONFIG_" | \
sed 's/=y/=1/g' | sed 's/=n/=0/g' | \
sed 's/\(.*\)=\(".*"\)/MACRO \1\n DEFM \2\nENDM/g' | \
sed 's/^CONFIG/DEFC CONFIG/g' >> $2 && \
echo -e "\nENDIF" >> $2
echo -e "IFNDEF OSCONFIG_H\nDEFINE OSCONFIG_H\n" > $2 && \
cat $1 | \
grep "^CONFIG_" | \
sed 's/=y/=1/g' | sed 's/=n/=0/g' | \
sed 's/\(.*\)=\(".*"\)/MACRO \1\n DEFM \2\nENDM/g' | \
sed 's/^CONFIG/DEFC CONFIG/g' >> $2 && \
echo -e "\nENDIF" >> $2
endef

asmconf: $(KCONFIG_CONFIG)
@echo "Converting $(KCONFIG_CONFIG) to $(OSCONFIG_ASM) ..."
@$(call CONVERT_config_asm,$(KCONFIG_CONFIG), $(OSCONFIG_ASM))

menuconfig:
@test -e os.conf || cp $(KCONFIG_CONFIG) os.conf
$(eval export KCONFIG_CONFIG = os.conf)
$(MENUCONFIG)
@echo "Converting $(KCONFIG_CONFIG) to $(OSCONFIG_ASM) ..."
@$(call CONVERT_config_asm,$(KCONFIG_CONFIG), $(OSCONFIG_ASM))

alldefconfig:
$(ALLDEFCONFIG)
@echo "Converting $(KCONFIG_CONFIG) to $(OSCONFIG_ASM) ..."
@$(call CONVERT_config_asm,$(KCONFIG_CONFIG), $(OSCONFIG_ASM))

prepare_dirs:
@mkdir -p $(BINDIR)
Expand All @@ -180,4 +192,4 @@ fdump:
$(DISASSEMBLER) -o 0x0000 -x $(BINDIR)/$(MAPFILE) $(BINDIR)/$(BIN) > $(BINDIR)/os.dump

clean:
rm -rf $(OSCONFIG_ASM) $(BINDIR) $(KCONFIG_CONFIG) version.txt
rm -rf $(OSCONFIG_ASM) $(BINDIR) version.txt
52 changes: 52 additions & 0 deletions configs/zeal8bit.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CONFIG_CPU_FREQ=10000000
CONFIG_TARGET="zeal8bit"
CONFIG_TARGET_ZEAL_8_BIT=y
# CONFIG_TARGET_TRS_80 is not set
# CONFIG_TARGET_AGON_LIGHT is not set

#
# Zeal 8-bit Computer configuration
#
CONFIG_TARGET_NUMBER=1
CONFIG_TARGET_HAS_MMU=y
CONFIG_TARGET_HAS_DRIVERS_HOOK=y
CONFIG_KERNEL_RAM_PHYS_ADDRESS=0x88000
CONFIG_ROMDISK_ADDRESS=0x8000
CONFIG_KERNEL_PHYS_ADDRESS=0x4000
CONFIG_KERNEL_TARGET_HAS_MMU=y
CONFIG_TARGET_ENABLE_COMPACTFLASH=y

#
# CompactFlash driver configuration
#
CONFIG_TARGET_COMPACTFLASH_ADDRESS=0x70
CONFIG_TARGET_COMPACTFLASH_TIMEOUT=30
# end of CompactFlash driver configuration

# CONFIG_ENABLE_EMULATION_HOSTFS is not set
CONFIG_TARGET_ENABLE_VIDEO=y
CONFIG_TARGET_STDOUT_VIDEO=y
# CONFIG_TARGET_STDOUT_UART is not set
CONFIG_TARGET_KEYBOARD_QWERTY=y
# CONFIG_TARGET_KEYBOARD_DVORAK is not set
# end of Zeal 8-bit Computer configuration

#
# Kernel configuration
#
# CONFIG_KERNEL_REPRODUCIBLE_BUILD is not set
CONFIG_KERNEL_STACK_ADDR=0xFFFF
CONFIG_KERNEL_RAM_START=0xC000
# CONFIG_KERNEL_COLDBOOT_HOOK is not set
# CONFIG_KERNEL_EXIT_HOOK is not set
CONFIG_KERNEL_DRIVERS_HOOK=y
CONFIG_KERNEL_MAX_NESTED_PROGRAMS=3
CONFIG_KERNEL_MAX_LOADED_DRIVERS=16
CONFIG_KERNEL_MAX_OPENED_DEVICES=16
CONFIG_KERNEL_MAX_OPENED_FILES=16
CONFIG_KERNEL_PATH_MAX=128
CONFIG_KERNEL_INIT_EXECUTABLE="A:/init.bin"
CONFIG_KERNEL_INIT_EXECUTABLE_ADDR=0x4000
CONFIG_KERNEL_LOG_BOOT_MOUNTED_DISKS=y
CONFIG_KERNEL_ENABLE_ZEALFS_SUPPORT=y
# end of Kernel configuration
52 changes: 52 additions & 0 deletions configs/zealemu.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CONFIG_CPU_FREQ=10000000
CONFIG_TARGET="zeal8bit"
CONFIG_TARGET_ZEAL_8_BIT=y
# CONFIG_TARGET_TRS_80 is not set
# CONFIG_TARGET_AGON_LIGHT is not set

#
# Zeal 8-bit Computer configuration
#
CONFIG_TARGET_NUMBER=1
CONFIG_TARGET_HAS_MMU=y
CONFIG_TARGET_HAS_DRIVERS_HOOK=y
CONFIG_KERNEL_RAM_PHYS_ADDRESS=0x88000
CONFIG_ROMDISK_ADDRESS=0x8000
CONFIG_KERNEL_PHYS_ADDRESS=0x0000
CONFIG_KERNEL_TARGET_HAS_MMU=y
CONFIG_TARGET_ENABLE_COMPACTFLASH=y

#
# CompactFlash driver configuration
#
CONFIG_TARGET_COMPACTFLASH_ADDRESS=0x70
CONFIG_TARGET_COMPACTFLASH_TIMEOUT=30
# end of CompactFlash driver configuration

CONFIG_ENABLE_EMULATION_HOSTFS=y
CONFIG_TARGET_ENABLE_VIDEO=y
CONFIG_TARGET_STDOUT_VIDEO=y
# CONFIG_TARGET_STDOUT_UART is not set
CONFIG_TARGET_KEYBOARD_QWERTY=y
# CONFIG_TARGET_KEYBOARD_DVORAK is not set
# end of Zeal 8-bit Computer configuration

#
# Kernel configuration
#
# CONFIG_KERNEL_REPRODUCIBLE_BUILD is not set
CONFIG_KERNEL_STACK_ADDR=0xFFFF
CONFIG_KERNEL_RAM_START=0xC000
# CONFIG_KERNEL_COLDBOOT_HOOK is not set
# CONFIG_KERNEL_EXIT_HOOK is not set
CONFIG_KERNEL_DRIVERS_HOOK=y
CONFIG_KERNEL_MAX_NESTED_PROGRAMS=3
CONFIG_KERNEL_MAX_LOADED_DRIVERS=16
CONFIG_KERNEL_MAX_OPENED_DEVICES=16
CONFIG_KERNEL_MAX_OPENED_FILES=16
CONFIG_KERNEL_PATH_MAX=128
CONFIG_KERNEL_INIT_EXECUTABLE="A:/init.bin"
CONFIG_KERNEL_INIT_EXECUTABLE_ADDR=0x4000
CONFIG_KERNEL_LOG_BOOT_MOUNTED_DISKS=y
CONFIG_KERNEL_ENABLE_ZEALFS_SUPPORT=y
# end of Kernel configuration

0 comments on commit 01bfd25

Please sign in to comment.