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