xref: /haiku/src/system/boot/platform/u-boot/Jamfile (revision f8da8f3477d3c18142e59d17d05a545982faa5a8)
1SubDir HAIKU_TOP src system boot platform u-boot ;
2
3SubDirHdrs $(HAIKU_TOP) headers private kernel boot platform $(TARGET_BOOT_PLATFORM) ;
4
5SubDirHdrs $(HAIKU_TOP) src system boot arch $(TARGET_KERNEL_ARCH) ;
6
7UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
8UsePrivateHeaders [ FDirName graphics common ] ;
9UsePrivateHeaders [ FDirName graphics vesa ] ;
10UsePrivateHeaders [ FDirName storage ] ;
11UsePrivateHeaders [ FDirName kernel arch generic ] ;
12
13# TODO: move this to arch/arm !
14
15UsePrivateHeaders [ FDirName kernel arch $(TARGET_KERNEL_ARCH) board $(TARGET_BOOT_BOARD) ] ;
16
17{
18	local defines = _BOOT_MODE ;
19
20	defines = [ FDefines $(defines) ] ;
21	SubDirCcFlags $(defines) -g3 -O0 ;
22	SubDirC++Flags $(defines) -fno-rtti -g3 -O0 ;
23}
24
25UseLibraryHeaders [ FDirName libfdt ] ;
26
27local libFDTSources =
28	fdt.c
29	fdt_ro.c
30	fdt_rw.c
31	fdt_strerror.c
32	fdt_sw.c
33	fdt_wip.c
34;
35
36# we fake NetBSD since we don't have an OS ID yet for uimage,
37# and we also fake a netbsd loader anyway.
38local uImageFakeOS = "netbsd" ;
39
40SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons accelerants common ] ;
41
42# First build the non arch dependent parts
43BootMergeObject boot_platform_u-boot_common.o :
44	start.cpp
45	debug.cpp
46	console.cpp
47	serial.cpp
48	devices.cpp
49	keyboard.cpp
50	menu.cpp
51	cpu.cpp
52	uimage.cpp
53	video.cpp
54	fdt_serial.cpp
55	fdt_support.cpp
56	openfirmware.cpp
57	$(genericPlatformSources)
58	$(libFDTSources)
59
60
61	: -fno-pic
62	: boot_platform_generic.a
63;
64
65BootMergeObject boot_platform_u-boot.o :
66	: :
67	# must come first to have _start_* at correct locations
68	boot_platform_u-boot_$(TARGET_ARCH).o
69	boot_platform_u-boot_common.o
70;
71
72# bootable flash image
73rule BuildUBootFlashImage image : haikuLoader : uboot_image
74{
75	Depends $(image) : $(haikuLoader) ;
76	#Depends $(image) : $(archive) ;
77	Depends $(image) : $(uboot_image) ;
78	LocalClean clean : $(image) ;
79	FLASH_IMAGE_BLOCK_SIZE on $(image) = 128k ;
80	FLASH_IMAGE_BLOCK_COUNT on $(image) = 256 ;
81	#FLASH_IMAGE_UBOOT_OFFSET on $(image) = 0 ;
82	FLASH_IMAGE_LOADER_OFFSET on $(image) = 248 ;
83	BuildUBootFlashImage1 $(image) : $(haikuLoader) $(uboot_image) ;
84}
85
86
87actions BuildUBootFlashImage1
88{
89	$(RM) $(<)
90
91	# make an empty image
92	dd of=$(<) \
93		if=/dev/zero \
94		bs=$(FLASH_IMAGE_BLOCK_SIZE) \
95		count=$(FLASH_IMAGE_BLOCK_COUNT)
96
97	# add u-boot
98	dd of=$(<) \
99		if=$(>[2]) \
100		bs=$(FLASH_IMAGE_BLOCK_SIZE) \
101		conv=notrunc
102
103	# add root fs
104#	dd of=$(<) \
105#		if=$(>[3]) \
106#		bs=$(FLASH_IMAGE_BLOCK_SIZE) \
107#		conv=notrunc \
108#		seek=$(FLASH_IMAGE_ROOTFS_OFFSET)
109
110	# add haiku_loader (raw, elf or uimage)
111	dd of=$(<) \
112		if=$(>[1]) \
113		bs=$(FLASH_IMAGE_BLOCK_SIZE) \
114		conv=notrunc seek=$(FLASH_IMAGE_LOADER_OFFSET)
115}
116
117# uImage
118rule BuildUImage image : data : args
119{
120	Depends $(image) : $(data) ;
121	LocalClean clean : $(image) ;
122	MKIMAGE_ARGS on $(image) = $(args) ;
123	colon on $(image) = ":" ;
124	local files = $(data:G=) ;
125	BuildUImage1 $(image) : $(data) ;
126}
127
128actions BuildUImage1
129{
130	mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<)
131}
132
133rule BuildUImageScript script : content
134{
135	LocalClean clean : $(script) ;
136	SCRIPTCONTENT on $(script) = $(content) ;
137	SCRIPTNAME on $(script) = $(script) ;
138	FAKEOS on $(script) = $(uImageFakeOS) ;
139	BuildUImageScript1 $(script) : $(content) ;
140}
141
142actions BuildUImageScript1
143{
144	rm -f $(<) $(<).txt
145	echo '$(SCRIPTCONTENT)' > $(<).txt
146	mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \
147		-d $(<).txt $(<)
148	rm -f $(<).txt
149}
150
151# SD/mmc image rule
152# requires sfdisk and mtools packages on linux
153rule BuildUBootSDImage image : files
154{
155	Depends $(image) : $(files) ;
156	SDIMAGE_BLOCK_SIZE on $(image) = 1048576 ; # 1M
157	SDIMAGE_SIZE on $(image) = $(HAIKU_BOARD_SDIMAGE_SIZE) ;
158	SDIMAGE_FDISK on $(image) = $(HOST_SFDISK) ;
159	SDIMAGE_FDISK_SCRIPT on $(image) =
160		"0,$(HAIKU_BOARD_SDIMAGE_FAT_SIZE),0c,-\\\n,,eb\\\n\\\n" ;
161	SDIMAGE_FDISK_H on $(image) = 255 ;
162	SDIMAGE_FDISK_S on $(image) = 63 ;
163	SDIMAGE_FDISK_C on $(image) = ;
164	SDIMAGE_FDISK_UNIT on $(image) = M ;
165	BuildUBootSDImage1 $(image) : $(files) ;
166}
167
168actions BuildUBootSDImage1
169{
170	$(RM) $(<)
171	$(RM) $(<).mtools
172
173	# make an empty image
174	dd of=$(<) \
175		if=/dev/zero \
176		bs=$(SDIMAGE_BLOCK_SIZE) \
177		count=$(SDIMAGE_SIZE)
178	# partition it
179	printf '$(SDIMAGE_FDISK_SCRIPT)' | $(SDIMAGE_FDISK) -f -D \
180		-H $(SDIMAGE_FDISK_H) -S $(SDIMAGE_FDISK_S) \
181		-u$(SDIMAGE_FDISK_UNIT) $(<)
182		#-H $(SDIMAGE_FDISK_H) -S $(SDIMAGE_FDISK_S) -C \\\$(( $(SDIMAGE_SIZE) * 1024 * 1024 / $(SDIMAGE_FDISK_H) / $(SDIMAGE_FDISK_S))) \
183	# generate mtools config
184	echo 'drive i: file="$(<)" partition=1' > $(<).mtools
185	# format the image
186	MTOOLSRC=$(<).mtools mformat -v "Haiku" i:
187	# populate
188	MTOOLSRC=$(<).mtools mcopy $(>) i:
189	# list content
190	#MTOOLSRC=$(<).mtools mdir i:
191	# cleanup
192	$(RM) $(<).mtools
193}
194
195# uimage targets
196BuildUImage haiku_loader.ub : haiku_loader :
197	-A $(TARGET_ARCH) -O $(uImageFakeOS) -T kernel -C none
198	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_RAW)
199		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
200
201local tgzArchive = haiku-floppyboot.tgz ;
202
203BuildUImage haiku_loader_linux.ub : haiku_loader :
204	-A $(TARGET_ARCH) -O linux -T kernel -C none
205	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_LINUX)
206		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
207
208BuildUImage haiku_loader_nbsd.ub : haiku_loader $(tgzArchive) :
209	-A $(TARGET_ARCH) -O $(uImageFakeOS) -T multi -C none
210	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_NBSD)
211		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
212
213if $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) {
214	BuildUImageScript $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) :
215		$(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT) ;
216}
217
218if $(HAIKU_BOARD_MLO_IMAGE) && $(HAIKU_BOARD_MLO_IMAGE_URL) {
219	DownloadFile $(HAIKU_BOARD_MLO_IMAGE) $(HAIKU_BOARD_MLO_IMAGE_URL) ;
220}
221
222if $(HAIKU_BOARD_UBOOT_IMAGE) && $(HAIKU_BOARD_UBOOT_IMAGE_URL) {
223	# Download the u-boot binary file.
224	ubootFile = [ DownloadFile $(HAIKU_BOARD_UBOOT_IMAGE)
225		: $(HAIKU_BOARD_UBOOT_IMAGE_URL) ] ;
226}
227
228# flash image targets
229BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img : haiku_loader :
230	$(ubootFile) ;
231NotFile haiku-flash-image ;
232Depends haiku-flash-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img ;
233
234#BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img : boot_loader_u-boot :
235#	$(ubootFile) ;
236#NotFile haiku-flash-elf-image ;
237#Depends haiku-flash-elf-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img ;
238
239BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img : haiku_loader.ub :
240	$(ubootFile) ;
241NotFile haiku-flash-uimage ;
242Depends haiku-flash-uimage : haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img ;
243
244# SD/mmc image targets
245BuildUBootSDImage haiku-$(HAIKU_BOOT_BOARD).mmc : $(HAIKU_BOARD_SDIMAGE_FILES) ;
246NotFile haiku-mmc-image ;
247Depends haiku-mmc-image : haiku-$(HAIKU_BOOT_BOARD).mmc ;
248
249SEARCH on [ FGristFiles $(genericPlatformSources) ]
250	= [ FDirName $(HAIKU_TOP) src system boot platform generic ] ;
251
252SEARCH on [ FGristFiles openfirmware.cpp fdt_serial.cpp fdt_support.cpp ]
253	= [ FDirName $(HAIKU_TOP) src system kernel platform u-boot ] ;
254
255SEARCH on [ FGristFiles $(libFDTSources) ]
256	= [ FDirName $(HAIKU_TOP) src libs libfdt ] ;
257
258# Tell the build system to where stage1.bin can be found, so it can be used
259# elsewhere.
260SEARCH on stage1.bin = $(SUBDIR) ;
261
262SubInclude HAIKU_TOP src system boot platform u-boot arch ;
263