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_PACKAGING_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_PACKAGING_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_PACKAGING_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_PACKAGING_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_PACKAGING_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 BuildUImageScript1 $(script) : $(source) ; 171} 172 173actions BuildUImageScript1 174{ 175 rm -f $(1) 176 mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ 177 -d $(2) $(1) 178} 179 180# the bootsector on haiku_loader.amiga_m68k must be checksummed 181rule ChecksumAmigaLoader 182{ 183 local haikuLoader = $(1) ; 184 local checksummer = <build>fixup_amiga_boot_checksum ; 185 186 Depends $(haikuLoader) : $(checksummer) ; 187 188 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 189} 190 191actions ChecksumAmigaLoader bind TARGET_CHECKSUM 192{ 193 $(TARGET_CHECKSUM) $(1) 194} 195 196# the bootsector on haiku_loader.atari_m68k must be checksummed 197rule ChecksumAtariLoader 198{ 199 local haikuLoader = $(1) ; 200 local checksummer = <build>fixup_tos_boot_checksum ; 201 202 Depends $(haikuLoader) : $(checksummer) ; 203 204 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 205} 206 207actions ChecksumAtariLoader bind TARGET_CHECKSUM { 208 $(TARGET_CHECKSUM) $(1) 209} 210 211 212 213# atari_m68k: AUTO folder PRG target 214# based on KernelLd 215rule AtariBootPrgLd 216{ 217 # AtariBootPrgLd <name> : <objs> : <linkerscript> : <args> ; 218 219 LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 220 221 LINKFLAGS on $(1) = $(4) ; 222 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 223 224 # Remove any preset LINKLIBS 225 LINKLIBS on $(1) = ; 226 227 # TODO: Do we really want to invoke SetupKernel here? The objects should 228 # have been compiled with KernelObjects anyway, so we're doing that twice. 229 SetupKernel $(2) ; 230 231 # Show that we depend on the libraries we need 232 LocalClean clean : $(1) ; 233 LocalDepends all : $(1) ; 234 Depends $(1) : $(2) ; 235 236 MakeLocateDebug $(1) ; 237 238} 239 240actions AtariBootPrgLd 241{ 242 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 243} 244 245 246local extraSources = ; 247if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 { 248 extraSources += atomic.S ; 249} 250 251for platform in [ MultiBootSubDirSetup ] { 252 on $(platform) { 253 if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi { 254 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 255 x86_64 ] ; 256 } else { 257 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 258 $(TARGET_KERNEL_ARCH) ] ; 259 } 260 261 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ; 262 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ; 263 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ; 264 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ; 265 266 BootMergeObject boot_libroot_$(platform:G=).o : 267 abs.c 268 ctype.cpp 269 LocaleData.cpp 270 qsort.c 271 kernel_vsprintf.cpp 272 memchr.c 273 memcmp.c 274 memmove.c 275 strdup.cpp 276 strndup.cpp 277 strlen.cpp 278 strnlen.cpp 279 strcmp.c 280 strcasecmp.c 281 strncmp.c 282 strcat.c 283 strcpy.c 284 strerror.c 285 strlcat.c 286 strlcpy.c 287 strchr.c 288 strrchr.c 289 strtol.c 290 strtoul.c 291 $(extraSources) 292 ; 293 294 AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ; 295 296 local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ; 297 local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ; 298 local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ; 299 ldflags ?= $(TARGET_BOOT_LDFLAGS) ; 300 301 # efi loader needs to be shared. 302 if $(TARGET_BOOT_PLATFORM) = efi { 303 ldflags += -shared ; 304 ldflags += -Map=efi.map ; 305 } 306 307 BootLd boot_loader_$(platform:G=) : 308 boot_platform_$(platform:G=).o 309 $(archObject:G=$(archGrist)) 310 [ MultiBootGristFiles 311 boot_loader.a 312 boot_net.a 313 boot_partitions.a 314 315 # file systems 316 boot_bfs.a 317 boot_amiga_ffs.a 318 boot_tarfs.a 319 boot_fatfs.a 320 boot_packagefs.a 321 322 boot_loader.a 323 # a second time, so undefined references in the file systems can be 324 # resolved 325 326 # needed by tarfs, packagefs, and video_splash.cpp 327 boot_zlib.a 328 ] 329 # libroot functions needed by the stage2 boot loader 330 boot_libroot_$(platform:G=).o 331 332 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld 333 : $(ldflags) 334 ; 335 336 switch $(TARGET_BOOT_PLATFORM) { 337 case efi : 338 BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 339 if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 { 340 # These EFI platforms need u-boot to get them going 341 BuildUImageScript boot.scr 342 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 343 } 344 345 case bios_ia32 : 346 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 347 348 case pxe_ia32 : 349 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 350 351 case openfirmware : 352 BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 353 354 case u-boot : 355 local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ; 356 BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) 357 : 358 -A $(TARGET_ARCH) -O linux -T kernel -C none 359 -a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry) 360 -n 'Haiku $(TARGET_KERNEL_ARCH) loader' ; 361 BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : 362 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 363 -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; 364 BuildUImageScript boot.scr 365 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 366 367 case amiga_m68k : 368 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 369 ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 370 371 case atari_m68k : 372 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 373 ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 374 375 AtariBootPrgLd haiku.prg : 376 boot_loader_$(TARGET_BOOT_PLATFORM) 377 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld 378 : -Bstatic 379 ; 380 381 case next_m68k : 382 BuildAoutLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 383 384 case * : 385 Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ; 386 } 387 } 388} 389 390SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ; 391SubInclude HAIKU_TOP src system boot loader ; 392SubInclude HAIKU_TOP src system boot platform ; 393