xref: /haiku/src/system/boot/platform/u-boot/Jamfile (revision 6d2f2ec177bf615a117a7428d71be4330545b320)
1SubDir HAIKU_TOP src system boot platform u-boot ;
2
3SubDirHdrs $(HAIKU_TOP) headers private kernel boot platform $(TARGET_BOOT_PLATFORM) ;
4SubDirHdrs $(HAIKU_TOP) headers private kernel platform $(TARGET_BOOT_PLATFORM) ;
5
6SubDirHdrs $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ;
7
8UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
9UsePrivateHeaders [ FDirName graphics common ] ;
10UsePrivateHeaders [ FDirName graphics vesa ] ;
11UsePrivateHeaders [ FDirName storage ] ;
12UsePrivateHeaders [ FDirName kernel arch generic ] ;
13
14# TODO: move this to arch/arm !
15
16UsePrivateHeaders [ FDirName kernel arch $(TARGET_KERNEL_ARCH) board $(TARGET_BOOT_BOARD) ] ;
17
18{
19	local defines = _BOOT_MODE ;
20
21	defines = [ FDefines $(defines) ] ;
22	SubDirCcFlags $(defines) -g3 -O0 ;
23	SubDirC++Flags $(defines) -fno-rtti -g3 -O0 ;
24}
25
26UseLibraryHeaders [ FDirName libfdt ] ;
27
28local libFDTSources =
29	fdt.c
30	fdt_ro.c
31	fdt_rw.c
32	fdt_strerror.c
33	fdt_sw.c
34	fdt_wip.c
35;
36
37# we fake NetBSD since we don't have an OS ID yet for uimage,
38# and we also fake a netbsd loader anyway.
39local uImageFakeOS = "netbsd" ;
40
41SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons accelerants common ] ;
42
43# First build the non arch dependent parts
44BootMergeObject boot_platform_u-boot_common.o :
45	start.cpp
46	debug.cpp
47	console.cpp
48	serial.cpp
49	devices.cpp
50	keyboard.cpp
51	menu.cpp
52	cpu.cpp
53	uimage.cpp
54	video.cpp
55	fdt_serial.cpp
56	fdt_support.cpp
57	openfirmware.cpp
58	$(genericPlatformSources)
59	$(libFDTSources)
60
61
62	: -fno-pic
63	: boot_platform_generic.a
64;
65
66BootMergeObject boot_platform_u-boot.o :
67	: :
68	# must come first to have _start_* at correct locations
69	boot_platform_u-boot_$(TARGET_ARCH).o
70	boot_platform_u-boot_common.o
71;
72
73# TODO: handle flash and SD images as Container stuff ?
74
75# bootable flash image
76rule BuildUBootFlashImage image : haikuLoader : parts
77{
78	Depends $(image) : $(haikuLoader) ;
79	#Depends $(image) : $(archive) ;
80	Depends $(image) : $(parts) ;
81	LocalClean clean : $(image) ;
82	FLASH_IMAGE_BLOCK_SIZE on $(image) = 1024 ;
83	FLASH_IMAGE_BLOCK_COUNT on $(image) = 32768 ;
84	#FLASH_IMAGE_UBOOT_OFFSET on $(image) = 0 ;
85	FLASH_IMAGE_LOADER_OFFSET on $(image) = 248 ;
86
87	# add u-boot
88	FLASH_OFFSET on $(haikuLoader) = $(FLASH_IMAGE_LOADER_OFFSET) ;
89	local offsets = ;
90	for dep in $(haikuLoader) $(parts) {
91		offsets += [ on $(dep) return $(FLASH_OFFSET) ] ;
92	}
93	FLASH_OFFSETS on $(image) = $(offsets) ;
94
95	# create empty image
96	BuildUBootFlashImage1 $(image) : $(haikuLoader) $(parts) ;
97}
98
99
100actions BuildUBootFlashImage1
101{
102	$(RM) $(<)
103
104	# make an empty image
105	dd of=$(<) \
106		if=/dev/zero \
107		bs=$(FLASH_IMAGE_BLOCK_SIZE) \
108		count=$(FLASH_IMAGE_BLOCK_COUNT)
109
110	# add binaries
111	# ugly HACK
112	FLASH_OFFSETS=" $(FLASH_OFFSETS) "
113	FLASH_OFFSETS=${FLASH_OFFSETS# }
114	for b in $(>) ; do
115		s="${FLASH_OFFSETS%% *}"
116		FLASH_OFFSETS="${FLASH_OFFSETS#* }"
117		dd of=$(<) \
118			if=$b \
119			bs=$(FLASH_IMAGE_BLOCK_SIZE) \
120			conv=notrunc seek=$s
121	done
122}
123
124# uImage
125rule BuildUImage image : data : args
126{
127	Depends $(image) : $(data) ;
128	LocalClean clean : $(image) ;
129	MKIMAGE_ARGS on $(image) = $(args) ;
130	colon on $(image) = ":" ;
131	local files = $(data:G=) ;
132	BuildUImage1 $(image) : $(data) ;
133}
134
135actions BuildUImage1
136{
137	mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<)
138}
139
140rule BuildUImageScript script : content
141{
142	LocalClean clean : $(script) ;
143	SCRIPTCONTENT on $(script) = $(content) ;
144	SCRIPTNAME on $(script) = $(script) ;
145	FAKEOS on $(script) = $(uImageFakeOS) ;
146	BuildUImageScript1 $(script) : $(content) ;
147}
148
149actions BuildUImageScript1
150{
151	rm -f $(<) $(<).txt
152	echo '$(SCRIPTCONTENT)' > $(<).txt
153	mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \
154		-d $(<).txt $(<)
155	rm -f $(<).txt
156}
157
158# SD/mmc image rule
159# requires mtools package on linux
160rule BuildUBootSDImage image : files
161{
162	Depends $(image) : $(files) ;
163	SDIMAGE_BLOCK_SIZE on $(image) = 1048576 ; # 1MiB
164	SDIMAGE_MTOOLS_H on $(image) = 255 ;
165	SDIMAGE_MTOOLS_S on $(image) = 63 ;
166	SDIMAGE_MTOOLS_C on $(image) = 8 ;
167	SDIMAGE_SIZE on $(image) = $(HAIKU_BOARD_SDIMAGE_SIZE) ;
168	SDIMAGE_BEGIN on $(image) = $(HAIKU_BOARD_SDIMAGE_BEGIN:E=63) ;
169	BuildUBootSDImage1 $(image) : $(files) ;
170}
171
172actions BuildUBootSDImage1
173{
174	$(RM) $(1)
175	$(RM) $(1).mtools
176
177	# make an empty image
178	dd of=$(1) \
179		if=/dev/zero \
180		bs=$(SDIMAGE_BLOCK_SIZE) \
181		count=$(SDIMAGE_SIZE)
182	# generate mtools config
183	echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C)
184		heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S)
185		mformat_only' > $(1).mtools
186	# partition it
187	MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i:
188	# format the image
189	MTOOLSRC=$(1).mtools mformat -L 32 -v "Haiku" i:
190
191	# generate u-boot environment variables
192	echo '$(HAIKU_BOARD_SDIMAGE_UBOOT_UENV)' > uEnv.txt
193	# populate
194	MTOOLSRC=$(1).mtools mcopy $(2[1-]) i:
195	MTOOLSRC=$(1).mtools mcopy uEnv.txt i:
196	# list content
197	MTOOLSRC=$(1).mtools mdir i:
198	# cleanup
199	$(RM) $(1).mtools
200	$(RM) uEnv.txt
201	# Add haiku bootstrap partition to MMC image
202	#cat $(2[0]) >> $(1)
203}
204
205
206rule BlessSDImage image
207{
208	# "Blesses" SD cards by writing out data to a fixed point outside of the
209	# filesystem. Handy if your board needs an SPL or boot0 at a fixed point.
210	if $(HAIKU_BOARD_SDIMAGE_BOOT0_FILE) {
211		Depends $(image) : $(HAIKU_BOARD_SDIMAGE_BOOT0_FILE) ;
212	}
213
214	if $(HAIKU_BOARD_SDIMAGE_BOOT1_FILE) {
215		Depends $(image) : $(HAIKU_BOARD_SDIMAGE_BOOT1_FILE) ;
216	}
217
218	BlessSDImage1 $(image) : $(HAIKU_BOARD_SDIMAGE_BOOT0_FILE) $(HAIKU_BOARD_SDIMAGE_BOOT1_FILE) ;
219}
220
221
222actions BlessSDImage1 bind HAIKU_BOARD_SDIMAGE_BOOT0_SEEK HAIKU_BOARD_SDIMAGE_BOOT1_SEEK
223{
224	if [ $(HAIKU_BOARD_SDIMAGE_BOOT0_SEEK:E=-1) -ge 0 ]; then
225		dd if=$(2[1]) of=$(1) bs=1 seek=$(HAIKU_BOARD_SDIMAGE_BOOT0_SEEK) conv=notrunc
226	fi
227
228	if [ $(HAIKU_BOARD_SDIMAGE_BOOT1_SEEK:E=-1) -ge 0 ]; then
229		dd if=$(2[2]) of=$(1) bs=1 seek=$(HAIKU_BOARD_SDIMAGE_BOOT1_SEEK) conv=notrunc
230	fi
231}
232
233
234# uimage targets
235BuildUImage haiku_loader.ub : haiku_loader :
236	-A $(TARGET_ARCH) -O $(uImageFakeOS) -T kernel -C none
237	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_RAW)
238		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
239
240local tgzArchive = haiku-floppyboot.tgz ;
241
242BuildUImage $(tgzArchive).ub : $(tgzArchive) :
243	-A $(TARGET_ARCH) -O linux -T ramdisk -C none
244		-n '$(tgzArchive) $(TARGET_BOOT_BOARD)' ;
245
246BuildUImage haiku_loader_linux.ub : haiku_loader :
247	-A $(TARGET_ARCH) -O linux -T kernel -C none
248	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_LINUX)
249		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
250
251if $(HAIKU_BOARD_FDT_NAME) {
252	local fdtBinary = $(HAIKU_BOARD_FDT_NAME).dtb ;
253	CompileDTS $(fdtBinary) : [ FDirName $(HAIKU_TOP) src data dts arch $(TARGET_ARCH) $(HAIKU_BOARD_FDT_NAME).dts ] ;
254
255	BuildUImage haiku_loader_nbsd.ub : haiku_loader $(tgzArchive) $(fdtBinary) :
256		-A $(TARGET_ARCH) -O $(uImageFakeOS) -T multi -C none
257		-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_NBSD)
258			-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
259}
260
261if $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) {
262	BuildUImageScript $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) :
263		$(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT) ;
264}
265
266# flash image targets
267
268BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img : haiku_loader :
269	$(FLASH_IMAGE_PARTS) ;
270NotFile haiku-flash-image ;
271Depends haiku-flash-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img ;
272
273#BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img : boot_loader_u-boot :
274#	$(FLASH_IMAGE_PARTS) ;
275#NotFile haiku-flash-elf-image ;
276#Depends haiku-flash-elf-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img ;
277
278BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img : haiku_loader.ub :
279	$(FLASH_IMAGE_PARTS) ;
280NotFile haiku-flash-uimage ;
281Depends haiku-flash-uimage : haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img ;
282
283# SD/mmc image targets
284BuildUBootSDImage haiku-$(HAIKU_BOOT_BOARD).mmc : $(HAIKU_IMAGE) $(HAIKU_BOARD_SDIMAGE_FILES) ;
285BlessSDImage haiku-$(HAIKU_BOOT_BOARD).mmc ;
286NotFile haiku-mmc-image ;
287Depends haiku-mmc-image : haiku-$(HAIKU_BOOT_BOARD).mmc ;
288
289SEARCH on [ FGristFiles $(genericPlatformSources) ]
290	= [ FDirName $(HAIKU_TOP) src system boot platform generic ] ;
291
292SEARCH on [ FGristFiles openfirmware.cpp fdt_serial.cpp fdt_support.cpp ]
293	= [ FDirName $(HAIKU_TOP) src system kernel platform u-boot ] ;
294
295SEARCH on [ FGristFiles $(libFDTSources) ]
296	= [ FDirName $(HAIKU_TOP) src libs libfdt ] ;
297
298# Tell the build system to where stage1.bin can be found, so it can be used
299# elsewhere.
300SEARCH on stage1.bin = $(SUBDIR) ;
301
302SubInclude HAIKU_TOP src system boot platform u-boot arch ;
303