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_KERNEL_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_KERNEL_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_KERNEL_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 : 111 OUTPUT_TARGET on $(efiLoader) = pei-i386 ; 112 case x86_64 : 113 OUTPUT_TARGET on $(efiLoader) = pei-x86-64 ; 114 case arm : 115 OUTPUT_TARGET on $(efiLoader) = binary ; 116 case arm64 : 117 OUTPUT_TARGET on $(efiLoader) = binary ; 118 case riscv64 : 119 OUTPUT_TARGET on $(efiLoader) = binary ; 120 case * : 121 Exit "Currently unsupported arch:" $(TARGET_ARCH) ; 122 } 123 124 MakeLocateDebug $(efiLoader) ; 125} 126 127actions BuildEFILoader 128{ 129 $(RM) -f $(1) 130 if [ "$(OUTPUT_TARGET)" = "binary" ]; then 131 # no bfd support, fake efi Pe header 132 $(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -j .text -j .sdata -j .data \ 133 -j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \ 134 --output-target=$(OUTPUT_TARGET) $(2) $(1) 135 else 136 # bfd supports pe + efi for arch 137 $(TARGET_OBJCOPY_$(TARGET_KERNEL_ARCH)) -j .text -j .sdata -j .data \ 138 -j .dynamic -j .dynsym -j .rel* -j .rela* -j .reloc -j .dynstr \ 139 --output-target=$(OUTPUT_TARGET) \ 140 --subsystem=efi-app $(2) $(1) 141 fi 142} 143 144 145# 146# U-boot image creation 147# 148rule BuildUImage image : data : args 149{ 150 Depends $(image) : $(data) ; 151 LocalClean clean : $(image) ; 152 MKIMAGE_ARGS on $(image) = $(args) ; 153 colon on $(image) = ":" ; 154 local files = $(data:G=) ; 155 BuildUImage1 $(image) : $(data) ; 156} 157 158actions BuildUImage1 159{ 160 mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<) 161} 162 163# 164# Given a txt, generate a binary u-boot script 165# 166rule BuildUImageScript script : source 167{ 168 Depends $(script) : $(source) ; 169 LocalClean clean : $(script) ; 170 SCRIPTNAME on $(script) = $(script) ; 171 FAKEOS on $(script) = "linux" ; 172 ARCH on $(script) = $(TARGET_ARCH) ; 173 174 if $(TARGET_ARCH) = "riscv64" || $(TARGET_ARCH) = "riscv32" { 175 ARCH on $(script) = "riscv" ; 176 } 177 178 BuildUImageScript1 $(script) : $(source) ; 179} 180 181actions BuildUImageScript1 182{ 183 $(RM) -f $(1) 184 mkimage -A $(ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ 185 -d $(2) $(1) 186} 187 188# the bootsector on haiku_loader.amiga_m68k must be checksummed 189rule ChecksumAmigaLoader 190{ 191 local haikuLoader = $(1) ; 192 local checksummer = <build>fixup_amiga_boot_checksum ; 193 194 Depends $(haikuLoader) : $(checksummer) ; 195 196 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 197} 198 199actions ChecksumAmigaLoader bind TARGET_CHECKSUM 200{ 201 $(TARGET_CHECKSUM) $(1) 202} 203 204# the bootsector on haiku_loader.atari_m68k must be checksummed 205rule ChecksumAtariLoader 206{ 207 local haikuLoader = $(1) ; 208 local checksummer = <build>fixup_tos_boot_checksum ; 209 210 Depends $(haikuLoader) : $(checksummer) ; 211 212 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 213} 214 215actions ChecksumAtariLoader bind TARGET_CHECKSUM { 216 $(TARGET_CHECKSUM) $(1) 217} 218 219 220 221# atari_m68k: AUTO folder PRG target 222# based on KernelLd 223rule AtariBootPrgLd 224{ 225 # AtariBootPrgLd <name> : <objs> : <linkerscript> : <args> ; 226 227 LINK on $(1) = $(TARGET_LD_$(TARGET_KERNEL_ARCH)) ; 228 229 LINKFLAGS on $(1) = $(4) ; 230 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 231 232 # Remove any preset LINKLIBS 233 LINKLIBS on $(1) = ; 234 235 # TODO: Do we really want to invoke SetupKernel here? The objects should 236 # have been compiled with KernelObjects anyway, so we're doing that twice. 237 SetupKernel $(2) ; 238 239 # Show that we depend on the libraries we need 240 LocalClean clean : $(1) ; 241 LocalDepends all : $(1) ; 242 Depends $(1) : $(2) ; 243 244 MakeLocateDebug $(1) ; 245 246} 247 248actions AtariBootPrgLd 249{ 250 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 251} 252 253 254local extraSources = ; 255if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_KERNEL_ARCH)) = 1 { 256 extraSources += atomic.S ; 257} 258 259for platform in [ MultiBootSubDirSetup ] { 260 on $(platform) { 261 if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi { 262 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 263 x86_64 ] ; 264 } else { 265 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 266 $(TARGET_KERNEL_ARCH_DIR) ] ; 267 } 268 269 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ; 270 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ; 271 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ; 272 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ; 273 274 BootMergeObject boot_libroot_$(platform:G=).o : 275 abs.c 276 ctype.cpp 277 LocaleData.cpp 278 qsort.c 279 kernel_vsprintf.cpp 280 memchr.c 281 memcmp.c 282 memmove.c 283 strdup.cpp 284 strndup.cpp 285 strlen.cpp 286 strnlen.cpp 287 strcmp.c 288 strcasecmp.c 289 strncmp.c 290 strcat.c 291 strcpy.c 292 strerror.c 293 strlcat.c 294 strlcpy.c 295 strchr.c 296 strrchr.c 297 strtol.c 298 strtoul.c 299 $(extraSources) 300 ; 301 302 AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ; 303 304 local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH_DIR) $(platform:G=) ] ; 305 local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ; 306 local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ; 307 ldflags ?= $(TARGET_BOOT_LDFLAGS) ; 308 309 # needed by tarfs, packagefs, and video_splash.cpp 310 local supportLibs = [ FGrist boot_zlib.a ] ; 311 if [ FIsBuildFeatureEnabled zstd ] { 312 supportLibs += boot_zstd.a ; 313 } 314 315 # efi loader needs to be shared. 316 if $(TARGET_BOOT_PLATFORM) = efi { 317 ldflags += -shared ; 318 ldflags += -Map=$(HAIKU_OUTPUT_DIR)/efi.map ; 319 } 320 321 if $(TARGET_BOOT_PLATFORM) = riscv { 322 ldflags += -z,notext ; 323 } 324 325 BootLd boot_loader_$(platform:G=) : 326 boot_platform_$(platform:G=).o 327 $(archObject:G=$(archGrist)) 328 [ MultiBootGristFiles 329 boot_loader.a 330 boot_net.a 331 boot_partitions.a 332 333 # file systems 334 boot_bfs.a 335 boot_amiga_ffs.a 336 boot_tarfs.a 337 boot_fatfs.a 338 boot_packagefs.a 339 340 boot_loader.a 341 # a second time, so undefined references in the file systems can be 342 # resolved 343 $(supportLibs) 344 ] 345 346 # libroot functions needed by the stage2 boot loader 347 boot_libroot_$(platform:G=).o 348 349 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld 350 : $(ldflags) 351 ; 352 353 switch $(TARGET_BOOT_PLATFORM) { 354 case efi : 355 BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 356 if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = riscv64 { 357 # These EFI platforms need u-boot to get them going 358 BuildUImageScript boot.scr 359 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 360 } 361 362 case bios_ia32 : 363 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 364 365 case pxe_ia32 : 366 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 367 368 case openfirmware : 369 BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 370 371 case u-boot : 372 local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ; 373 BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) 374 : 375 -A $(TARGET_ARCH) -O linux -T kernel -C none 376 -a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry) 377 -n 'Haiku $(TARGET_KERNEL_ARCH) loader' ; 378 BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : 379 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 380 -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; 381 BuildUImageScript boot.scr 382 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 383 384 case amiga_m68k : 385 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 386 ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 387 388 case atari_m68k : 389 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 390 ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 391 392 AtariBootPrgLd haiku.prg : 393 boot_loader_$(TARGET_BOOT_PLATFORM) 394 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld 395 : -Bstatic 396 ; 397 398 case riscv : 399 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 400 401 case next_m68k : 402 BuildAoutLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 403 404 case * : 405 Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ; 406 } 407 } 408} 409 410SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH_DIR) ; 411SubInclude HAIKU_TOP src system boot libs ; 412SubInclude HAIKU_TOP src system boot loader ; 413SubInclude HAIKU_TOP src system boot platform ; 414