xref: /haiku/src/system/boot/Jamfile (revision 2897df967633aab846ff4917b53e2af7d1e54eeb)
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	rm -f $(1)
72	$(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
73	-j .rel -j .rela -j .reloc --target=efi-app-x86_64 $(2) $(1)
74}
75
76
77#
78# U-boot image creation
79#
80rule BuildUImage image : data : args
81{
82    Depends $(image) : $(data) ;
83    LocalClean clean : $(image) ;
84    MKIMAGE_ARGS on $(image) = $(args) ;
85    colon on $(image) = ":" ;
86    local files = $(data:G=) ;
87    BuildUImage1 $(image) : $(data) ;
88}
89
90actions BuildUImage1
91{
92    mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<)
93}
94
95rule BuildUImageScript script : content
96{
97    LocalClean clean : $(script) ;
98    SCRIPTCONTENT on $(script) = $(content) ;
99    SCRIPTNAME on $(script) = $(script) ;
100    FAKEOS on $(script) = "linux" ;
101    BuildUImageScript1 $(script) : $(content) ;
102}
103
104actions BuildUImageScript1
105{
106    rm -f $(<) $(<).txt
107    echo '$(SCRIPTCONTENT)' > $(<).txt
108    mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \
109        -d $(<).txt $(<)
110    rm -f $(<).txt
111}
112
113
114local extraSources = ;
115if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 {
116	extraSources += atomic.S ;
117}
118
119for platform in [ MultiBootSubDirSetup ] {
120	on $(platform) {
121		if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi {
122			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
123								x86_64 ] ;
124		} else {
125			SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch
126									$(TARGET_KERNEL_ARCH) ] ;
127		}
128
129		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ;
130		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ;
131		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ;
132		SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ;
133
134		BootMergeObject boot_libroot_$(platform:G=).o :
135			abs.c
136			ctype.cpp
137			LocaleData.cpp
138			qsort.c
139			kernel_vsprintf.cpp
140			memchr.c
141			memcmp.c
142			memmove.c
143			strdup.cpp
144			strndup.cpp
145			strlen.cpp
146			strnlen.cpp
147			strcmp.c
148			strcasecmp.c
149			strncmp.c
150			strcat.c
151			strcpy.c
152			strerror.c
153			strlcat.c
154			strlcpy.c
155			strchr.c
156			strrchr.c
157			strtol.c
158			strtoul.c
159			$(extraSources)
160		;
161
162		AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ;
163
164		local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ;
165		local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ;
166		local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ;
167		ldflags ?= $(TARGET_BOOT_LDFLAGS) ;
168
169		# efi loader needs to be shared.
170		if $(TARGET_BOOT_PLATFORM) = efi {
171			ldflags += -shared ;
172		}
173
174		BootLd boot_loader_$(platform:G=) :
175			boot_platform_$(platform:G=).o
176			$(archObject:G=$(archGrist))
177			[ MultiBootGristFiles
178				boot_loader.a
179				boot_net.a
180				boot_partitions.a
181
182				# file systems
183				boot_bfs.a
184				boot_amiga_ffs.a
185				boot_tarfs.a
186				boot_fatfs.a
187				boot_packagefs.a
188
189				boot_loader.a
190					# a second time, so undefined references in the file systems can be
191					# resolved
192
193				# needed by tarfs, packagefs, and video_splash.cpp
194				boot_zlib.a
195			]
196			# libroot functions needed by the stage2 boot loader
197			boot_libroot_$(platform:G=).o
198
199			: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld
200			: $(ldflags)
201		;
202
203		switch $(TARGET_BOOT_PLATFORM) {
204			case efi :
205				BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
206
207			case bios_ia32 :
208				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
209
210			case pxe_ia32 :
211				BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
212
213			case openfirmware :
214				BuildCoffLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ;
215
216			case u-boot :
217				local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ;
218				BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM)
219					:
220					-A $(TARGET_ARCH) -O linux -T kernel -C none
221					-a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry)
222					-n 'Haiku $(TARGET_KERNEL_ARCH) loader' ;
223				BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz :
224					-A $(TARGET_ARCH) -O linux -T ramdisk -C none
225					-n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ;
226				BuildUImageScript boot.scr : $(HAIKU_MMC_UBOOT_SCRIPT) ;
227
228			case * :
229				Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ;
230		}
231	}
232}
233
234SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ;
235SubInclude HAIKU_TOP src system boot loader ;
236SubInclude HAIKU_TOP src system boot platform ;
237