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