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