Browse Source

Add simple config system for both #ifdef's and conditional compilation

master
Aaron Lindsay 8 years ago
parent
commit
3876937ae9
5 changed files with 48 additions and 9 deletions
  1. +2
    -0
      .gitignore
  2. +15
    -3
      Makefile
  3. +3
    -0
      config_example
  4. +8
    -3
      devices/kernel.mk
  5. +20
    -3
      kernel/start_kernel.c

+ 2
- 0
.gitignore View File

@ -1,5 +1,7 @@
aedrix-kernel.elf
aedrix-kernel.img
config
config.h
*.o
*.swp
*.d

+ 15
- 3
Makefile View File

@ -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'


+ 3
- 0
config_example View File

@ -0,0 +1,3 @@
CONFIG_RPI = y
#CONFIG_VEXPRESS_A9 = y
#CONFIG_INTEGRATOR_CP = n

+ 8
- 3
devices/kernel.mk View File

@ -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

+ 20
- 3
kernel/start_kernel.c View File

@ -23,12 +23,19 @@
#include <mmu.h>
#include <mm.h>
#include <print.h>
#include <devices/pi_mini_uart.h>
#include <devices/bcm2835_videocore.h>
#include <framebuffer.h>
#include <console.h>
#ifdef CONFIG_VEXPRESS_A9
#include <devices/pl011.h>
#include <devices/pl111.h>
#endif
#ifdef CONFIG_RPI
#include <devices/pi_mini_uart.h>
#include <devices/bcm2835_videocore.h>
#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();


Loading…
Cancel
Save