xref: /haiku/src/system/boot/platform/u-boot/Jamfile (revision a07cdb6e9f8e484b6ba9f209fbeb144e906d3405)
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_MTOOLS_H on $(image) = 255 ;
159	SDIMAGE_MTOOLS_S on $(image) = 63 ;
160	SDIMAGE_MTOOLS_C on $(image) = 8 ;
161	BuildUBootSDImage1 $(image) : $(files) ;
162}
163
164actions BuildUBootSDImage1
165{
166	$(RM) $(1)
167	$(RM) $(1).mtools
168
169	# make an empty image
170	dd of=$(1) \
171		if=/dev/zero \
172		bs=$(SDIMAGE_BLOCK_SIZE) \
173		count=$(SDIMAGE_SIZE)
174	# generate mtools config
175	echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C)
176		heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S)
177		mformat_only' > $(1).mtools
178	# partition it
179	MTOOLSRC=$(1).mtools mpartition -cI -T 0xc i:
180	# format the image
181	MTOOLSRC=$(1).mtools mformat -L 32 -v "Haiku" i:
182
183	# generate u-boot environment variables
184	# We load the uImage 2MB above its final destination, bootm will decode
185	# it to the proper location. Our image is smaller than 2MB so this works.
186	echo 'uenvcmd=run loadImage; run mmcboot;
187		loadImage=fatload mmc0 0 0x80200000 haiku_loader_nbsd.ub
188		mmcboot=bootm 0x80200000' > uEnv.txt
189	# populate
190	MTOOLSRC=$(1).mtools mcopy $(2[1-]) i:
191	MTOOLSRC=$(1).mtools mcopy uEnv.txt i:
192	# list content
193	MTOOLSRC=$(1).mtools mdir i:
194	# cleanup
195	$(RM) $(1).mtools
196	$(RM) uEnv.txt
197	# Add haiku bootstrap partition to MMC image
198	dd if=$(2[0]) of=$(1) conv=notrunc oflag=append bs=1M
199}
200
201# uimage targets
202BuildUImage haiku_loader.ub : haiku_loader :
203	-A $(TARGET_ARCH) -O $(uImageFakeOS) -T kernel -C none
204	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_RAW)
205		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
206
207local tgzArchive = haiku-floppyboot.tgz ;
208
209BuildUImage haiku_loader_linux.ub : haiku_loader :
210	-A $(TARGET_ARCH) -O linux -T kernel -C none
211	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_LINUX)
212		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
213
214BuildUImage haiku_loader_nbsd.ub : haiku_loader $(tgzArchive) :
215	-A $(TARGET_ARCH) -O $(uImageFakeOS) -T multi -C none
216	-a $(HAIKU_BOARD_LOADER_BASE) -e $(HAIKU_BOARD_LOADER_ENTRY_NBSD)
217		-n 'haiku_loader $(TARGET_BOOT_BOARD)' ;
218
219if $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) {
220	BuildUImageScript $(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT_NAME) :
221		$(HAIKU_BOARD_SDIMAGE_UBOOT_SCRIPT) ;
222}
223
224# flash image targets
225BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img : haiku_loader :
226	$(ubootFile) ;
227NotFile haiku-flash-image ;
228Depends haiku-flash-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_raw.img ;
229
230#BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img : boot_loader_u-boot :
231#	$(ubootFile) ;
232#NotFile haiku-flash-elf-image ;
233#Depends haiku-flash-elf-image : haiku-$(HAIKU_BOOT_BOARD)_flash_image_elf.img ;
234
235BuildUBootFlashImage haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img : haiku_loader.ub :
236	$(ubootFile) ;
237NotFile haiku-flash-uimage ;
238Depends haiku-flash-uimage : haiku-$(HAIKU_BOOT_BOARD)_flash_image_uimage.img ;
239
240# SD/mmc image targets
241BuildUBootSDImage haiku-$(HAIKU_BOOT_BOARD).mmc : $(HAIKU_IMAGE) $(HAIKU_BOARD_SDIMAGE_FILES) ;
242NotFile haiku-mmc-image ;
243Depends haiku-mmc-image : haiku-$(HAIKU_BOOT_BOARD).mmc ;
244
245SEARCH on [ FGristFiles $(genericPlatformSources) ]
246	= [ FDirName $(HAIKU_TOP) src system boot platform generic ] ;
247
248SEARCH on [ FGristFiles openfirmware.cpp fdt_serial.cpp fdt_support.cpp ]
249	= [ FDirName $(HAIKU_TOP) src system kernel platform u-boot ] ;
250
251SEARCH on [ FGristFiles $(libFDTSources) ]
252	= [ FDirName $(HAIKU_TOP) src libs libfdt ] ;
253
254# Tell the build system to where stage1.bin can be found, so it can be used
255# elsewhere.
256SEARCH on stage1.bin = $(SUBDIR) ;
257
258SubInclude HAIKU_TOP src system boot platform u-boot arch ;
259