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