summaryrefslogtreecommitdiff
path: root/src/config/Config.lb
blob: 3c703c62036ff68fd735b0eaa9bb082fb311e07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
## This is Architecture independant part of the makefile

uses HAVE_OPTION_TABLE
uses CONFIG_AP_CODE_IN_CAR

makedefine CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
makedefine LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
makedefine GCC_INC_DIR := $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")

makedefine CPPFLAGS := -I$(TOP)/src/include -I$(TOP)/src/arch/$(ARCH)/include -I$(GCC_INC_DIR) $(CPUFLAGS)
makedefine CFLAGS := $(CPU_OPT) $(DISTRO_CFLAGS) $(CPPFLAGS) -Os -nostdinc -nostdlib -fno-builtin  -Wall

makedefine HOSTCFLAGS:= -Os -Wall

makerule ldscript.ld   
	depends	"ldoptions $(LDSUBSCRIPTS-1)" 
	action	"echo '/*ldoptions*/' > $@; cat ldoptions >> $@ ; for file in $(LDSUBSCRIPTS-1) ; do echo /\* $$file \*/ >> $@; cat $$file >> $@ ; done"
end

#makerule cpuflags   
#	depends	"Makefile.settings" 
#	action	"perl -e 'print \"CPUFLAGS :=\n\"; foreach $$var (split(\" \", $$ENV{VARIABLES})) { if (exists($$ENV{$$var})) { print \"CPUFLAGS += -D$$var\" . (length($$ENV{$$var})?\"=\x27$$ENV{$$var}\x27\":\"\") .\"\n\"} else { print \"CPUFLAGS += -U$$var\n\"} }' > $@"
#end

#makerule ldoptions   
#	depends	"Makefile.settings" 
#	action	"perl -e 'foreach $$var (split(\" \", $$ENV{VARIABLES})) { if ($$ENV{$$var} =~ m/^(0x[0-9a-fA-F]+|0[0-7]+|[0-9]+)$$/) { print \"$$var = $$ENV{$$var};\n\"; }}' > $@"
#end

makerule coreboot.strip  
	depends	"coreboot" 
	action	"$(OBJCOPY) -O binary coreboot coreboot.strip"
end

makerule coreboot.a
        depends "$(OBJECTS)"
        action  "rm -f coreboot.a"
        action  "$(CROSS_COMPILE)ar cr coreboot.a $(OBJECTS)"
end


makerule coreboot_ram.o
	depends	"$(DRIVER) coreboot.a $(LIBGCC_FILE_NAME)" 
	action	"$(CC) $(DISTRO_LFLAGS) -nostdlib -r -o $@ c_start.o $(DRIVER) coreboot.a $(LIBGCC_FILE_NAME)"
end

makerule coreboot_ram
	depends	"coreboot_ram.o $(TOP)/src/config/coreboot_ram.ld ldoptions" 
	action	"$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T $(TOP)/src/config/coreboot_ram.ld coreboot_ram.o"
	action 	"$(CROSS_COMPILE)nm -n coreboot_ram | sort > coreboot_ram.map"
end

##
## By default compress the part of coreboot that runs from RAM
##
makedefine COREBOOT_RAM-$(CONFIG_COMPRESS):=coreboot_ram.nrv2b
makedefine COREBOOT_RAM-$(CONFIG_UNCOMPRESSED):=coreboot_ram.bin

makerule coreboot_ram.bin 
	depends	"coreboot_ram" 
	action	"$(OBJCOPY) -O binary $< $@"
end

makerule coreboot_ram.nrv2b 
	depends	"coreboot_ram.bin nrv2b" 
	action	"./nrv2b e $< $@"
end

makerule coreboot_ram.rom
	depends	"$(COREBOOT_RAM-1)" 
	action	"cp $(COREBOOT_RAM-1) coreboot_ram.rom"
end

makedefine COREBOOT_APC:=

if CONFIG_AP_CODE_IN_CAR
	#for ap code in cache

	makerule coreboot_apc.a
		depends "apc_auto.o"
		action  "rm -f coreboot_apc.a"
		action  "$(CROSS_COMPILE)ar cr coreboot_apc.a apc_auto.o"
	end

	makerule coreboot_apc.o
		depends "coreboot_apc.a c_start.o $(LIBGCC_FILE_NAME)"
        	action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -r -o $@ c_start.o coreboot_apc.a $(LIBGCC_FILE_NAME)"
	end

	makerule coreboot_apc
		depends "coreboot_apc.o $(TOP)/src/config/coreboot_apc.ld ldoptions"
		action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T $(TOP)/src/config/coreboot_apc.ld coreboot_apc.o"
		action  "$(CROSS_COMPILE)nm -n coreboot_apc | sort > coreboot_apc.map"
	end

	##
	## By default compress the part of coreboot that runs from cache as ram
	##
	makedefine COREBOOT_APC-$(CONFIG_COMPRESS):=coreboot_apc.nrv2b
	makedefine COREBOOT_APC-$(CONFIG_UNCOMPRESSED):=coreboot_apc.bin

	makerule coreboot_apc.bin
		depends "coreboot_apc"
		action  "$(OBJCOPY) -O binary $< $@"
	end

	makerule coreboot_apc.nrv2b
        depends "coreboot_apc.bin nrv2b"
        action  "./nrv2b e $< $@"
	end

	makerule coreboot_apc.rom
		depends "$(COREBOOT_APC-1)"
		action  "cp $(COREBOOT_APC-1) coreboot_apc.rom"
	end

	makedefine COREBOOT_APC:=coreboot_apc.rom

end

makedefine COREBOOT_RAM_ROM:=coreboot_ram.rom

makerule coreboot   
	depends	"crt0.o $(INIT-OBJECTS) $(COREBOOT_APC) $(COREBOOT_RAM_ROM) ldscript.ld"
	action	"$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T ldscript.ld crt0.o $(INIT-OBJECTS)"
	action	"$(CROSS_COMPILE)nm -n coreboot | sort > coreboot.map"
	action 	"$(CROSS_COMPILE)objdump -dS coreboot > coreboot.disasm"	
end

# the buildrom tool
makerule buildrom 
	depends	"$(TOP)/util/buildrom/buildrom.c" 
	action	"$(HOSTCC) -o $@ $<"
end

# Force crt0.s (which has build time version code in it to rebuild every time)
makedefine .PHONY : crt0.s
makerule crt0.s   
	depends	"crt0.S $(CRT0_INCLUDES)" 
	action	"$(CPP) $(CPPFLAGS) -I. -I$(TOP)/src  $< > $@.new && mv $@.new $@"
end

# generate an assembly listing via -a switch.
makerule crt0.o  
	depends	"crt0.s" 
	action	"$(CC) -Wa,-acdlns -c $(CPU_OPT) -o $@ $< >crt0.disasm"
end

makerule etags   
	depends	"$(SOURCES)" 
	action	"etags $(SOURCES)"
end
makerule tags   
	depends	"$(SOURCES)" 
	action	"ctags $(SOURCES)"
end
makerule corebootDoc.config
	depends	"$(TOP)/src/config/corebootDoc.config" 
	action "cat $(TOP)/src/config/corebootDoc.config > corebootDoc.config"
        action "echo 'INPUT=$(SOURCES)' >> corebootDoc.config"
end
makerule documentation   
	depends	"corebootDoc.config"
	action	"doxygen corebootDoc.config"
end

# Yes, the rule doesn't seem to make sense, but multiple images could try to
# create a romcc binary at the same time, clobbering each other.
# Our makefile architecture won't allow us to easily have the romcc target
# in the main makefile, so keep it here and move the race condition winner
# in place. That way, romcc may get compiled twice, but the binary will always
# be in a correct and valid state if it exists because the move is atomic.
makerule ../romcc   
	depends	"$(TOP)/util/romcc/romcc.c" 
	action	"$(HOSTCC) -g $(HOSTCFLAGS) $< -o romcc.tmpfile"
	action	"mv romcc.tmpfile $@"
end

makerule build_opt_tbl   
	depends	"$(TOP)/util/options/build_opt_tbl.c $(TOP)/src/include/pc80/mc146818rtc.h $(TOP)/src/include/boot/coreboot_tables.h Makefile.settings Makefile"
	action	"$(HOSTCC) $(HOSTCFLAGS) $(CPUFLAGS) $< -o $@" 
end

makerule option_table.h option_table.c
	depends	"build_opt_tbl $(MAINBOARD)/cmos.layout" 
	action	"./build_opt_tbl --config $(MAINBOARD)/cmos.layout --header option_table.h --option option_table.c"
end

if HAVE_OPTION_TABLE
object ./option_table.o 
end

makerule clean 
	action	"rm -f coreboot.* *~"
	action	"rm -f coreboot"
	action	"rm -f ldscript.ld"
	action	"rm -f a.out *.s *.l *.o *.E *.inc"
	action	"rm -f TAGS tags romcc*"
	action	"rm -f docipl buildrom* chips.c *chip.c coreboot_apc* coreboot_ram* coreboot_pay*"
	action	"rm -f build_opt_tbl* nrv2b* option_table.c crt0.S"
end

# do standard config files that the user need not specify
# for now, this is just 'lib', but it may be more later. 
dir /lib
dir /console
dir /stream
dir /devices
dir /pc80
dir /boot