From 3876937ae9e55f15d264772623212bb326ac3ff0 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Wed, 3 Oct 2012 00:19:28 -0400 Subject: [PATCH] Add simple config system for both #ifdef's and conditional compilation --- .gitignore | 2 ++ Makefile | 18 +++++++++++++++--- config_example | 3 +++ devices/kernel.mk | 11 ++++++++--- kernel/start_kernel.c | 23 ++++++++++++++++++++--- 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 config_example diff --git a/.gitignore b/.gitignore index a05b5bb..f60ecbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ aedrix-kernel.elf aedrix-kernel.img +config +config.h *.o *.swp *.d diff --git a/Makefile b/Makefile index a616e87..a03d3be 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,13 @@ OBJDUMP = $(TOOL_PREFIX)objdump # Define the flags we'll need for our tools INCLUDES = -I include -KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(INCLUDES) +KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 -include config.h $(INCLUDES) KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/ EXTRA_LIBS = -lgcc +# Include the config file so we don't compile/link unnecessary objects +include config + # Define KOBJS as a 'simply expanded' variable KOBJS := @@ -48,7 +51,7 @@ aedrix-kernel.img: aedrix-kernel.elf @echo 'OBJCOPY $@' $(V)$(OBJCOPY) $< -O binary $@ -%.o: %.c +%.o: %.c config.h @echo ' CC $@' $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $< @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html) @@ -57,7 +60,7 @@ aedrix-kernel.img: aedrix-kernel.elf -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \ rm -f $*.d -%.o: %.S +%.o: %.S config.h @echo ' AS $@' $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $< @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html) @@ -66,7 +69,16 @@ aedrix-kernel.img: aedrix-kernel.elf -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \ rm -f $*.d +config.h: config + @echo ' CONFIG config.h' + @cp config config.h + @sed -i '/^\w*#/d' config.h + @sed -i '/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[nN]/d' config.h + @sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[yY]/#define \1/g' config.h + clean: + @echo ' CLEAN config.h' + $(V)rm -f config.h @echo ' CLEAN *.o' $(V)rm -f $(KOBJS) @echo ' CLEAN .*.d' diff --git a/config_example b/config_example new file mode 100644 index 0000000..18cb5d3 --- /dev/null +++ b/config_example @@ -0,0 +1,3 @@ +CONFIG_RPI = y +#CONFIG_VEXPRESS_A9 = y +#CONFIG_INTEGRATOR_CP = n diff --git a/devices/kernel.mk b/devices/kernel.mk index 3aded10..beaafe2 100644 --- a/devices/kernel.mk +++ b/devices/kernel.mk @@ -3,13 +3,18 @@ SUBDIRS := include $(BASEDIR)/header.mk -OBJS_$(d) := $(d)/pl011.o \ +OBJS_$(d)_$(CONFIG_VEXPRESS_A9) := \ + $(d)/pl011.o \ + $(d)/pl111.o + +OBJS_$(d)_$(CONFIG_INTEGRATOR_CP) := \ $(d)/pl110.o \ - $(d)/pl111.o \ + +OBJS_$(d)_$(CONFIG_RPI) := \ $(d)/pi_mini_uart.o \ $(d)/bcm2835_mailbox.o \ $(d)/bcm2835_videocore.o -KOBJS += $(OBJS_$(d)) +KOBJS += $(OBJS_$(d)_y) include $(BASEDIR)/footer.mk diff --git a/kernel/start_kernel.c b/kernel/start_kernel.c index 4080c44..eab9d11 100644 --- a/kernel/start_kernel.c +++ b/kernel/start_kernel.c @@ -23,12 +23,19 @@ #include #include #include -#include - -#include #include #include +#ifdef CONFIG_VEXPRESS_A9 +#include +#include +#endif + +#ifdef CONFIG_RPI +#include +#include +#endif + struct fb myfb; void print_console_logo() { @@ -41,7 +48,12 @@ void print_console_logo() { } void video_init(void) { +#ifdef CONFIG_VEXPRESS_A9 + pl111_init(&myfb, 16); +#endif +#ifdef CONFIG_RPI bcm2835_videocore_init(&myfb, 16); +#endif } void test_mm() { @@ -124,8 +136,13 @@ int main(void) { mmu_reinit(); //initialize the serial console +#ifdef CONFIG_VEXPRESS_A9 + print_init(&pl011_putc); +#endif +#ifdef CONFIG_RPI mini_uart_init(); print_init(&mini_uart_putc); +#endif //setup memory mm_init();