xref: /haiku/src/system/boot/Jamfile (revision 89f1fd6512c10854013d231a85289797e47c7543)
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	switch $(TARGET_ARCH) {
32		case sparc :
33			AOUT_FORMAT on $(haikuLoader) = a.out-sunos-big ;
34		case * :
35			Exit "Currently unsupported coff arch:" $(TARGET_ARCH) ;
36	}
37}
38
39actions BuildAoutLoader {
40	rm -f $(1)
41	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(AOUT_FORMAT) $(2) $(1)
42}
43
44
45#
46# Coff haiku_loader creation
47#
48rule BuildCoffLoader {
49	local coffLoader = $(1) ;
50	local bootLoader = $(2) ;
51	switch $(TARGET_ARCH) {
52		case ppc :
53			COFF_FORMAT on $(coffLoader) = xcoff-powermac ;
54		case * :
55			Exit "Currently unsupported coff arch:" $(TARGET_ARCH) ;
56	}
57	HACK_COFF on $(coffLoader) = <build>hack-coff ;
58
59	Depends $(coffLoader) : <build>hack-coff ;
60}
61
62actions BuildCoffLoader bind HACK_COFF {
63	rm -f $(1)
64	# get the address of the COFF entry
65	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms
66	EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2`
67	rm -f $(2).syms
68	# copy to XCOFF format and patch the entry point
69	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1)
70	#$(CP) $(2) $(1)
71	# fill-in some fields objcopy missed
72	$(HACK_COFF) $(1)
73}
74
75
76#
77# BIOS haiku_loader creation
78#
79rule BuildBiosLoader {
80	local haikuLoader = $(1) ;
81	local bootLoader = $(2) ;
82
83	Depends $(haikuLoader) : $(bootLoader) ;
84	MakeLocateDebug $(haikuLoader) ;
85
86	on $(1) ResAttr $(1) : $(RESFILES) : false ;
87	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
88		SetType $(1) ;
89		MimeSet $(1) ;
90	}
91}
92
93actions BuildBiosLoader {
94	rm -f $(1)
95	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O binary $(2) $(1)
96}
97
98
99#
100# EFI loader creation
101#
102rule BuildEFILoader {
103	local efiLoader = $(1) ;
104	local bootLoader = $(2) ;
105
106	Depends $(efiLoader) : $(bootLoader) ;
107	MakeLocateDebug $(efiLoader) ;
108}
109
110actions BuildEFILoader
111{
112	rm -f $(1)
113	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \
114		-j .dynamic -j .dynsym -j .rel -j .rela -j .reloc -j .dynstr \
115		--input-target=efi-app-x86_64 --output-target=efi-app-x86_64 \
116		$(2) $(1)
117}
118
119
120#
121# U-boot image creation
122#
123rule BuildUImage image : data : args
124{
125    Depends $(image) : $(data) ;
126    LocalClean clean : $(image) ;
127    MKIMAGE_ARGS on $(image) = $(args) ;
128    colon on $(image) = ":" ;
129    local files = $(data:G=) ;
130    BuildUImage1 $(image) : $(data) ;
131}
132
133actions BuildUImage1
134{
135    mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<)
136}
137
138rule BuildUImageScript script : content
139{
140    LocalClean clean : $(script) ;
141    SCRIPTCONTENT on $(script) = $(content) ;
142    SCRIPTNAME on $(script) = $(script) ;
143    FAKEOS on $(script) = "linux" ;
144    BuildUImageScript1 $(script) : $(content) ;
145}
146
147actions BuildUImageScript1
148{
149    rm -f $(<) $(<).txt
150    echo '$(SCRIPTCONTENT)' > $(<).txt
151    mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \
152        -d $(<).txt $(<)
153    rm -f $(<).txt
154}
155
156
157local extraSources = ;
158if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 {
159	extraSources += atomic.S ;
160}
161
162for platform in [ MultiBootSubDirSetup ] {
163	on $(platform) {
164		if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi {
165			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
166								x86_64 ] ;
167		} else {
168			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
169									$(TARGET_KERNEL_ARCH) ] ;
170		}
171
172		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ;
173		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ;
174		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ;
175		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ;
176
177		BootMergeObject boot_libroot_$(platform:G=).o :
178			abs.c
179			ctype.cpp
180			LocaleData.cpp
181			qsort.c
182			kernel_vsprintf.cpp
183			memchr.c
184			memcmp.c
185			memmove.c
186			strdup.cpp
187			strndup.cpp
188			strlen.cpp
189			strnlen.cpp
190			strcmp.c
191			strcasecmp.c
192			strncmp.c
193			strcat.c
194			strcpy.c
195			strerror.c
196			strlcat.c
197			strlcpy.c
198			strchr.c
199			strrchr.c
200			strtol.c
201			strtoul.c
202			$(extraSources)
203		;
204
205		AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ;
206
207		local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ;
208		local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ;
209		local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ;
210		ldflags ?= $(TARGET_BOOT_LDFLAGS) ;
211
212		# efi loader needs to be shared.
213		if $(TARGET_BOOT_PLATFORM) = efi {
214			ldflags += -shared ;
215		}
216
217		BootLd boot_loader_$(platform:G=) :
218			boot_platform_$(platform:G=).o
219			$(archObject:G=$(archGrist))
220			[ MultiBootGristFiles
221				boot_loader.a
222				boot_net.a
223				boot_partitions.a
224
225				# file systems
226				boot_bfs.a
227				boot_amiga_ffs.a
228				boot_tarfs.a
229				boot_fatfs.a
230				boot_packagefs.a
231
232				boot_loader.a
233					# a second time, so undefined references in the file systems can be
234					# resolved
235
236				# needed by tarfs, packagefs, and video_splash.cpp
237				boot_zlib.a
238			]
239			# libroot functions needed by the stage2 boot loader
240			boot_libroot_$(platform:G=).o
241
242			: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld
243			: $(ldflags)
244		;
245
246		switch $(TARGET_BOOT_PLATFORM) {
247			case efi :
248				BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
249
250			case bios_ia32 :
251				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
252
253			case pxe_ia32 :
254				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
255
256			case openfirmware :
257				BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
258
259			case u-boot :
260				local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ;
261				BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM)
262					:
263					-A $(TARGET_ARCH) -O linux -T kernel -C none
264					-a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry)
265					-n 'Haiku $(TARGET_KERNEL_ARCH) loader' ;
266				BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz :
267					-A $(TARGET_ARCH) -O linux -T ramdisk -C none
268					-n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ;
269				BuildUImageScript boot.scr : $(HAIKU_MMC_UBOOT_SCRIPT) ;
270
271			case * :
272				Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ;
273		}
274	}
275}
276
277SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ;
278SubInclude HAIKU_TOP src system boot loader ;
279SubInclude HAIKU_TOP src system boot platform ;
280