xref: /haiku/src/system/boot/Jamfile (revision acdafb571df692fab7ad89836e39590dd8d415e2)
1SubDir HAIKU_TOP src system boot ;
2
3DEFINES += _BOOT_MODE ;
4
5UsePrivateHeaders [ FDirName libroot locale ] ;
6
7rule BuildOpenFirmwareLoader {
8	local haikuLoader = $(1) ;
9	local bootLoader = $(2) ;
10
11	Depends $(haikuLoader) : $(bootLoader) ;
12	MakeLocateDebug $(haikuLoader) ;
13
14	switch $(TARGET_ARCH) {
15		case ppc :
16			BuildCoffLoader $(haikuLoader) : $(bootLoader) ;
17		case sparc :
18			BuildAoutLoader $(haikuLoader) : $(bootLoader) ;
19		case * :
20			Exit "Currently unsupported arch:" $(TARGET_ARCH) ;
21	}
22}
23
24
25#
26# A.out haiku_loader creation
27#
28rule BuildAoutLoader {
29	local haikuLoader = $(1) ;
30	local bootLoader = $(2) ;
31
32	Depends $(haikuLoader) : $(bootLoader) ;
33	MakeLocateDebug $(haikuLoader) ;
34
35	ELF2AOUT on $(haikuLoader) = <build>elf2aout ;
36	Depends $(haikuLoader) : <build>elf2aout ;
37}
38
39actions BuildAoutLoader bind ELF2AOUT {
40	rm -f $(1)
41	$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) \
42	$(ELF2AOUT) -o $(1) $(2)
43}
44
45
46#
47# Coff haiku_loader creation
48#
49rule BuildCoffLoader {
50	local coffLoader = $(1) ;
51	local bootLoader = $(2) ;
52	switch $(TARGET_ARCH) {
53		case ppc :
54			COFF_FORMAT on $(coffLoader) = xcoff-powermac ;
55		case * :
56			Exit "Currently unsupported coff arch:" $(TARGET_ARCH) ;
57	}
58	HACK_COFF on $(coffLoader) = <build>hack-coff ;
59
60	Depends $(coffLoader) : <build>hack-coff ;
61}
62
63actions BuildCoffLoader bind HACK_COFF {
64	rm -f $(1)
65	# get the address of the COFF entry
66	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms
67	EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2`
68	rm -f $(2).syms
69	# copy to XCOFF format and patch the entry point
70	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1)
71	#$(CP) $(2) $(1)
72	# fill-in some fields objcopy missed
73	$(HACK_COFF) $(1)
74}
75
76
77#
78# BIOS haiku_loader creation
79#
80rule BuildBiosLoader {
81	local haikuLoader = $(1) ;
82	local bootLoader = $(2) ;
83
84	Depends $(haikuLoader) : $(bootLoader) ;
85	MakeLocateDebug $(haikuLoader) ;
86
87	on $(1) ResAttr $(1) : $(RESFILES) : false ;
88	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
89		SetType $(1) ;
90		MimeSet $(1) ;
91	}
92}
93
94actions BuildBiosLoader {
95	rm -f $(1)
96	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O binary $(2) $(1)
97}
98
99
100#
101# EFI loader creation
102#
103rule BuildEFILoader {
104	local efiLoader = $(1) ;
105	local bootLoader = $(2) ;
106
107	Depends $(efiLoader) : $(bootLoader) ;
108
109	switch $(TARGET_ARCH) {
110		case x86_64 :
111			OUTPUT_TARGET on $(efiLoader) = pei-x86-64 ;
112		case arm :
113			OUTPUT_TARGET on $(efiLoader) = binary ;
114		case arm64 :
115			OUTPUT_TARGET on $(efiLoader) = binary ;
116		case riscv64 :
117			OUTPUT_TARGET on $(efiLoader) = binary ;
118		case * :
119			Exit "Currently unsupported arch:" $(TARGET_ARCH) ;
120	}
121
122	MakeLocateDebug $(efiLoader) ;
123}
124
125actions BuildEFILoader
126{
127	rm -f $(1)
128	if [ "$(OUTPUT_TARGET)" = "binary" ]; then
129		# no bfd support, fake efi Pe header
130		$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \
131			-j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \
132			--output-target=$(OUTPUT_TARGET) $(2) $(1)
133	else
134		# bfd supports pe + efi for arch
135		$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \
136			-j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \
137			--output-target=$(OUTPUT_TARGET) \
138			--subsystem=efi-app $(2) $(1)
139	fi
140}
141
142
143#
144# U-boot image creation
145#
146rule BuildUImage image : data : args
147{
148    Depends $(image) : $(data) ;
149    LocalClean clean : $(image) ;
150    MKIMAGE_ARGS on $(image) = $(args) ;
151    colon on $(image) = ":" ;
152    local files = $(data:G=) ;
153    BuildUImage1 $(image) : $(data) ;
154}
155
156actions BuildUImage1
157{
158    mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<)
159}
160
161#
162# Given a txt, generate a binary u-boot script
163#
164rule BuildUImageScript script : source
165{
166	Depends $(script) : $(source) ;
167	LocalClean clean : $(script) ;
168	SCRIPTNAME on $(script) = $(script) ;
169	FAKEOS on $(script) = "linux" ;
170	ARCH on $(script) = $(TARGET_ARCH) ;
171
172	if $(TARGET_ARCH) = "riscv64" || $(TARGET_ARCH) = "riscv32" {
173		ARCH on $(script) = "riscv" ;
174	}
175
176	BuildUImageScript1 $(script) : $(source) ;
177}
178
179actions BuildUImageScript1
180{
181	rm -f $(1)
182	mkimage -A $(ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \
183		-d $(2) $(1)
184}
185
186# the bootsector on haiku_loader.amiga_m68k must be checksummed
187rule ChecksumAmigaLoader
188{
189	local haikuLoader = $(1) ;
190	local checksummer = <build>fixup_amiga_boot_checksum ;
191
192	Depends $(haikuLoader) : $(checksummer) ;
193
194	TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ;
195}
196
197actions ChecksumAmigaLoader bind TARGET_CHECKSUM
198{
199	$(TARGET_CHECKSUM) $(1)
200}
201
202# the bootsector on haiku_loader.atari_m68k must be checksummed
203rule ChecksumAtariLoader
204{
205	local haikuLoader = $(1) ;
206	local checksummer = <build>fixup_tos_boot_checksum ;
207
208	Depends $(haikuLoader) : $(checksummer) ;
209
210	TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ;
211}
212
213actions ChecksumAtariLoader bind TARGET_CHECKSUM {
214	$(TARGET_CHECKSUM) $(1)
215}
216
217
218
219# atari_m68k: AUTO folder PRG target
220# based on KernelLd
221rule AtariBootPrgLd
222{
223	# AtariBootPrgLd <name> : <objs> : <linkerscript> : <args> ;
224
225	LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
226
227	LINKFLAGS on $(1) = $(4) ;
228	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
229
230	# Remove any preset LINKLIBS
231	LINKLIBS on $(1) = ;
232
233	# TODO: Do we really want to invoke SetupKernel here? The objects should
234	# have been compiled with KernelObjects anyway, so we're doing that twice.
235	SetupKernel $(2) ;
236
237	# Show that we depend on the libraries we need
238	LocalClean clean : $(1) ;
239	LocalDepends all : $(1) ;
240	Depends $(1) : $(2) ;
241
242	MakeLocateDebug $(1) ;
243
244}
245
246actions AtariBootPrgLd
247{
248	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
249}
250
251
252local extraSources = ;
253if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_PACKAGING_ARCH)) = 1 {
254	extraSources += atomic.S ;
255}
256
257for platform in [ MultiBootSubDirSetup ] {
258	on $(platform) {
259		if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi {
260			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
261								x86_64 ] ;
262		} else {
263			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
264									$(TARGET_KERNEL_ARCH) ] ;
265		}
266
267		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ;
268		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ;
269		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ;
270		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ;
271
272		BootMergeObject boot_libroot_$(platform:G=).o :
273			abs.c
274			ctype.cpp
275			LocaleData.cpp
276			qsort.c
277			kernel_vsprintf.cpp
278			memchr.c
279			memcmp.c
280			memmove.c
281			strdup.cpp
282			strndup.cpp
283			strlen.cpp
284			strnlen.cpp
285			strcmp.c
286			strcasecmp.c
287			strncmp.c
288			strcat.c
289			strcpy.c
290			strerror.c
291			strlcat.c
292			strlcpy.c
293			strchr.c
294			strrchr.c
295			strtol.c
296			strtoul.c
297			$(extraSources)
298		;
299
300		AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ;
301
302		local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ;
303		local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ;
304		local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ;
305		ldflags ?= $(TARGET_BOOT_LDFLAGS) ;
306
307		# efi loader needs to be shared.
308		if $(TARGET_BOOT_PLATFORM) = efi {
309			ldflags += -shared ;
310			ldflags += -Map=efi.map ;
311		}
312
313		BootLd boot_loader_$(platform:G=) :
314			boot_platform_$(platform:G=).o
315			$(archObject:G=$(archGrist))
316			[ MultiBootGristFiles
317				boot_loader.a
318				boot_net.a
319				boot_partitions.a
320
321				# file systems
322				boot_bfs.a
323				boot_amiga_ffs.a
324				boot_tarfs.a
325				boot_fatfs.a
326				boot_packagefs.a
327
328				boot_loader.a
329					# a second time, so undefined references in the file systems can be
330					# resolved
331
332				# needed by tarfs, packagefs, and video_splash.cpp
333				boot_zlib.a
334			]
335			# libroot functions needed by the stage2 boot loader
336			boot_libroot_$(platform:G=).o
337
338			: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld
339			: $(ldflags)
340		;
341
342		switch $(TARGET_BOOT_PLATFORM) {
343			case efi :
344				BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
345				if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 || $(TARGET_ARCH) = riscv64 {
346					# These EFI platforms need u-boot to get them going
347					BuildUImageScript boot.scr
348						: [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ;
349				}
350
351			case bios_ia32 :
352				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
353
354			case pxe_ia32 :
355				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
356
357			case openfirmware :
358				BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
359
360			case u-boot :
361				local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ;
362				BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM)
363					:
364					-A $(TARGET_ARCH) -O linux -T kernel -C none
365					-a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry)
366					-n 'Haiku $(TARGET_KERNEL_ARCH) loader' ;
367				BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz :
368					-A $(TARGET_ARCH) -O linux -T ramdisk -C none
369					-n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ;
370				BuildUImageScript boot.scr
371					: [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ;
372
373			case amiga_m68k :
374				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
375				ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ;
376
377			case atari_m68k :
378				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
379				ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ;
380
381				AtariBootPrgLd haiku.prg :
382					boot_loader_$(TARGET_BOOT_PLATFORM)
383					: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld
384					: -Bstatic
385				;
386
387			case next_m68k :
388				BuildAoutLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
389
390			case * :
391				Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ;
392		}
393	}
394}
395
396SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ;
397SubInclude HAIKU_TOP src system boot loader ;
398SubInclude HAIKU_TOP src system boot platform ;
399