xref: /haiku/src/system/boot/Jamfile (revision a5061ecec55353a5f394759473f1fd6df04890da)
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=$(HAIKU_OUTPUT_DIR)/efi.map ;
311		}
312
313		if $(TARGET_BOOT_PLATFORM) = riscv {
314			ldflags += -z,notext ;
315		}
316
317		BootLd boot_loader_$(platform:G=) :
318			boot_platform_$(platform:G=).o
319			$(archObject:G=$(archGrist))
320			[ MultiBootGristFiles
321				boot_loader.a
322				boot_net.a
323				boot_partitions.a
324
325				# file systems
326				boot_bfs.a
327				boot_amiga_ffs.a
328				boot_tarfs.a
329				boot_fatfs.a
330				boot_packagefs.a
331
332				boot_loader.a
333					# a second time, so undefined references in the file systems can be
334					# resolved
335
336				# needed by tarfs, packagefs, and video_splash.cpp
337				boot_zlib.a
338			]
339			# libroot functions needed by the stage2 boot loader
340			boot_libroot_$(platform:G=).o
341
342			: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld
343			: $(ldflags)
344		;
345
346		switch $(TARGET_BOOT_PLATFORM) {
347			case efi :
348				BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
349				if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 || $(TARGET_ARCH) = riscv64 {
350					# These EFI platforms need u-boot to get them going
351					BuildUImageScript boot.scr
352						: [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ;
353				}
354
355			case bios_ia32 :
356				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
357
358			case pxe_ia32 :
359				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
360
361			case openfirmware :
362				BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
363
364			case u-boot :
365				local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ;
366				BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM)
367					:
368					-A $(TARGET_ARCH) -O linux -T kernel -C none
369					-a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry)
370					-n 'Haiku $(TARGET_KERNEL_ARCH) loader' ;
371				BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz :
372					-A $(TARGET_ARCH) -O linux -T ramdisk -C none
373					-n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ;
374				BuildUImageScript boot.scr
375					: [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ;
376
377			case amiga_m68k :
378				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
379				ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ;
380
381			case atari_m68k :
382				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
383				ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ;
384
385				AtariBootPrgLd haiku.prg :
386					boot_loader_$(TARGET_BOOT_PLATFORM)
387					: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld
388					: -Bstatic
389				;
390
391			case riscv :
392				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
393
394			case next_m68k :
395				BuildAoutLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
396
397			case * :
398				Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ;
399		}
400	}
401}
402
403SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ;
404SubInclude HAIKU_TOP src system boot loader ;
405SubInclude HAIKU_TOP src system boot platform ;
406