Browse Source

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

Aaron Lindsay 7 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

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

+ 15 - 3
Makefile

@@ -18,10 +18,13 @@ OBJDUMP = $(TOOL_PREFIX)objdump
18 18
 
19 19
 # Define the flags we'll need for our tools
20 20
 INCLUDES = -I include
21
-KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(INCLUDES)
21
+KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 -include config.h $(INCLUDES)
22 22
 KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/
23 23
 EXTRA_LIBS = -lgcc
24 24
 
25
+# Include the config file so we don't compile/link unnecessary objects
26
+include config
27
+
25 28
 # Define KOBJS as a 'simply expanded' variable
26 29
 KOBJS :=
27 30
 
@@ -48,7 +51,7 @@ aedrix-kernel.img: aedrix-kernel.elf
48 51
 	@echo 'OBJCOPY   $@'
49 52
 	$(V)$(OBJCOPY) $< -O binary $@
50 53
 
51
-%.o: %.c
54
+%.o: %.c config.h
52 55
 	@echo '     CC   $@'
53 56
 	$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
54 57
 	@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@@ -57,7 +60,7 @@ aedrix-kernel.img: aedrix-kernel.elf
57 60
 		-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
58 61
 		rm -f $*.d
59 62
 
60
-%.o: %.S
63
+%.o: %.S config.h
61 64
 	@echo '     AS   $@'
62 65
 	$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
63 66
 	@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@@ -66,7 +69,16 @@ aedrix-kernel.img: aedrix-kernel.elf
66 69
 		-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
67 70
 		rm -f $*.d
68 71
 
72
+config.h: config
73
+	@echo ' CONFIG   config.h'
74
+	@cp config config.h
75
+	@sed -i '/^\w*#/d' config.h
76
+	@sed -i '/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[nN]/d' config.h
77
+	@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[yY]/#define \1/g' config.h
78
+
69 79
 clean:
80
+	@echo '  CLEAN   config.h'
81
+	$(V)rm -f config.h
70 82
 	@echo '  CLEAN   *.o'
71 83
 	$(V)rm -f $(KOBJS)
72 84
 	@echo '  CLEAN   .*.d'

+ 3 - 0
config_example

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

+ 8 - 3
devices/kernel.mk

@@ -3,13 +3,18 @@ SUBDIRS :=
3 3
 
4 4
 include $(BASEDIR)/header.mk
5 5
 
6
-OBJS_$(d) := $(d)/pl011.o \
6
+OBJS_$(d)_$(CONFIG_VEXPRESS_A9) := \
7
+	$(d)/pl011.o \
8
+	$(d)/pl111.o
9
+
10
+OBJS_$(d)_$(CONFIG_INTEGRATOR_CP) := \
7 11
 	$(d)/pl110.o \
8
-	$(d)/pl111.o \
12
+
13
+OBJS_$(d)_$(CONFIG_RPI) := \
9 14
 	$(d)/pi_mini_uart.o \
10 15
 	$(d)/bcm2835_mailbox.o \
11 16
 	$(d)/bcm2835_videocore.o
12 17
 
13
-KOBJS += $(OBJS_$(d))
18
+KOBJS += $(OBJS_$(d)_y)
14 19
 
15 20
 include $(BASEDIR)/footer.mk

+ 20 - 3
kernel/start_kernel.c

@@ -23,12 +23,19 @@
23 23
 #include <mmu.h>
24 24
 #include <mm.h>
25 25
 #include <print.h>
26
-#include <devices/pi_mini_uart.h>
27
-
28
-#include <devices/bcm2835_videocore.h>
29 26
 #include <framebuffer.h>
30 27
 #include <console.h>
31 28
 
29
+#ifdef CONFIG_VEXPRESS_A9
30
+#include <devices/pl011.h>
31
+#include <devices/pl111.h>
32
+#endif
33
+
34
+#ifdef CONFIG_RPI
35
+#include <devices/pi_mini_uart.h>
36
+#include <devices/bcm2835_videocore.h>
37
+#endif
38
+
32 39
 struct fb myfb;
33 40
 
34 41
 void print_console_logo() {
@@ -41,7 +48,12 @@ void print_console_logo() {
41 48
 }
42 49
 
43 50
 void video_init(void) {
51
+#ifdef CONFIG_VEXPRESS_A9
52
+	pl111_init(&myfb, 16);
53
+#endif
54
+#ifdef CONFIG_RPI
44 55
 	bcm2835_videocore_init(&myfb, 16);
56
+#endif
45 57
 }
46 58
 
47 59
 void test_mm() {
@@ -124,8 +136,13 @@ int main(void) {
124 136
 	mmu_reinit();
125 137
 
126 138
 	//initialize the serial console
139
+#ifdef CONFIG_VEXPRESS_A9
140
+	print_init(&pl011_putc);
141
+#endif
142
+#ifdef CONFIG_RPI
127 143
 	mini_uart_init();
128 144
 	print_init(&mini_uart_putc);
145
+#endif
129 146
 
130 147
 	//setup memory
131 148
 	mm_init();