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 ELF2AOUT on $(haikuLoader) = <build>elf2aout ; 32 Depends $(haikuLoader) : <build>elf2aout ; 33} 34 35actions BuildAoutLoader bind ELF2AOUT { 36 rm -f $(1) 37 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) \ 38 $(ELF2AOUT) -o $(1) $(2) 39} 40 41 42# 43# Coff haiku_loader creation 44# 45rule BuildCoffLoader { 46 local coffLoader = $(1) ; 47 local bootLoader = $(2) ; 48 switch $(TARGET_ARCH) { 49 case ppc : 50 COFF_FORMAT on $(coffLoader) = xcoff-powermac ; 51 case * : 52 Exit "Currently unsupported coff arch:" $(TARGET_ARCH) ; 53 } 54 HACK_COFF on $(coffLoader) = <build>hack-coff ; 55 56 Depends $(coffLoader) : <build>hack-coff ; 57} 58 59actions BuildCoffLoader bind HACK_COFF { 60 rm -f $(1) 61 # get the address of the COFF entry 62 $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms 63 EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2` 64 rm -f $(2).syms 65 # copy to XCOFF format and patch the entry point 66 $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1) 67 #$(CP) $(2) $(1) 68 # fill-in some fields objcopy missed 69 $(HACK_COFF) $(1) 70} 71 72 73# 74# BIOS haiku_loader creation 75# 76rule BuildBiosLoader { 77 local haikuLoader = $(1) ; 78 local bootLoader = $(2) ; 79 80 Depends $(haikuLoader) : $(bootLoader) ; 81 MakeLocateDebug $(haikuLoader) ; 82 83 on $(1) ResAttr $(1) : $(RESFILES) : false ; 84 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 85 SetType $(1) ; 86 MimeSet $(1) ; 87 } 88} 89 90actions BuildBiosLoader { 91 rm -f $(1) 92 $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O binary $(2) $(1) 93} 94 95 96# 97# EFI loader creation 98# 99rule BuildEFILoader { 100 local efiLoader = $(1) ; 101 local bootLoader = $(2) ; 102 103 Depends $(efiLoader) : $(bootLoader) ; 104 105 switch $(TARGET_ARCH) { 106 case x86_64 : 107 OUTPUT_TARGET on $(efiLoader) = efi-app-x86_64 ; 108 case arm : 109 OUTPUT_TARGET on $(efiLoader) = binary ; 110 case arm64 : 111 OUTPUT_TARGET on $(efiLoader) = binary ; 112 case * : 113 Exit "Currently unsupported arch:" $(TARGET_ARCH) ; 114 } 115 116 MakeLocateDebug $(efiLoader) ; 117} 118 119actions BuildEFILoader 120{ 121 rm -f $(1) 122 $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \ 123 -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc -j .dynstr \ 124 --output-target=$(OUTPUT_TARGET) $(2) $(1) 125} 126 127 128# 129# U-boot image creation 130# 131rule BuildUImage image : data : args 132{ 133 Depends $(image) : $(data) ; 134 LocalClean clean : $(image) ; 135 MKIMAGE_ARGS on $(image) = $(args) ; 136 colon on $(image) = ":" ; 137 local files = $(data:G=) ; 138 BuildUImage1 $(image) : $(data) ; 139} 140 141actions BuildUImage1 142{ 143 mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<) 144} 145 146# 147# Given a txt, generate a binary u-boot script 148# 149rule BuildUImageScript script : source 150{ 151 Depends $(script) : $(source) ; 152 LocalClean clean : $(script) ; 153 SCRIPTNAME on $(script) = $(script) ; 154 FAKEOS on $(script) = "linux" ; 155 BuildUImageScript1 $(script) : $(source) ; 156} 157 158actions BuildUImageScript1 159{ 160 rm -f $(1) 161 mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ 162 -d $(2) $(1) 163} 164 165# the bootsector on haiku_loader.amiga_m68k must be checksummed 166rule ChecksumAmigaLoader 167{ 168 local haikuLoader = $(1) ; 169 local checksummer = <build>fixup_amiga_boot_checksum ; 170 171 Depends $(haikuLoader) : $(checksummer) ; 172 173 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 174} 175 176actions ChecksumAmigaLoader bind TARGET_CHECKSUM 177{ 178 $(TARGET_CHECKSUM) $(1) 179} 180 181# the bootsector on haiku_loader.atari_m68k must be checksummed 182rule ChecksumAtariLoader 183{ 184 local haikuLoader = $(1) ; 185 local checksummer = <build>fixup_tos_boot_checksum ; 186 187 Depends $(haikuLoader) : $(checksummer) ; 188 189 TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; 190} 191 192actions ChecksumAtariLoader bind TARGET_CHECKSUM { 193 $(TARGET_CHECKSUM) $(1) 194} 195 196 197 198# atari_m68k: AUTO folder PRG target 199# based on KernelLd 200rule AtariBootPrgLd 201{ 202 # AtariBootPrgLd <name> : <objs> : <linkerscript> : <args> ; 203 204 LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 205 206 LINKFLAGS on $(1) = $(4) ; 207 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 208 209 # Remove any preset LINKLIBS 210 LINKLIBS on $(1) = ; 211 212 # TODO: Do we really want to invoke SetupKernel here? The objects should 213 # have been compiled with KernelObjects anyway, so we're doing that twice. 214 SetupKernel $(2) ; 215 216 # Show that we depend on the libraries we need 217 LocalClean clean : $(1) ; 218 LocalDepends all : $(1) ; 219 Depends $(1) : $(2) ; 220 221 MakeLocateDebug $(1) ; 222 223} 224 225actions AtariBootPrgLd 226{ 227 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 228} 229 230 231local extraSources = ; 232if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 { 233 extraSources += atomic.S ; 234} 235 236for platform in [ MultiBootSubDirSetup ] { 237 on $(platform) { 238 if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi { 239 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 240 x86_64 ] ; 241 } else { 242 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 243 $(TARGET_KERNEL_ARCH) ] ; 244 } 245 246 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ; 247 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ; 248 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ; 249 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ; 250 251 BootMergeObject boot_libroot_$(platform:G=).o : 252 abs.c 253 ctype.cpp 254 LocaleData.cpp 255 qsort.c 256 kernel_vsprintf.cpp 257 memchr.c 258 memcmp.c 259 memmove.c 260 strdup.cpp 261 strndup.cpp 262 strlen.cpp 263 strnlen.cpp 264 strcmp.c 265 strcasecmp.c 266 strncmp.c 267 strcat.c 268 strcpy.c 269 strerror.c 270 strlcat.c 271 strlcpy.c 272 strchr.c 273 strrchr.c 274 strtol.c 275 strtoul.c 276 $(extraSources) 277 ; 278 279 AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ; 280 281 local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ; 282 local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ; 283 local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ; 284 ldflags ?= $(TARGET_BOOT_LDFLAGS) ; 285 286 # efi loader needs to be shared. 287 if $(TARGET_BOOT_PLATFORM) = efi { 288 ldflags += -shared ; 289 ldflags += -Map=efi.map ; 290 } 291 292 BootLd boot_loader_$(platform:G=) : 293 boot_platform_$(platform:G=).o 294 $(archObject:G=$(archGrist)) 295 [ MultiBootGristFiles 296 boot_loader.a 297 boot_net.a 298 boot_partitions.a 299 300 # file systems 301 boot_bfs.a 302 boot_amiga_ffs.a 303 boot_tarfs.a 304 boot_fatfs.a 305 boot_packagefs.a 306 307 boot_loader.a 308 # a second time, so undefined references in the file systems can be 309 # resolved 310 311 # needed by tarfs, packagefs, and video_splash.cpp 312 boot_zlib.a 313 ] 314 # libroot functions needed by the stage2 boot loader 315 boot_libroot_$(platform:G=).o 316 317 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld 318 : $(ldflags) 319 ; 320 321 switch $(TARGET_BOOT_PLATFORM) { 322 case efi : 323 BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 324 if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 { 325 # These platforms sometimes need u-boot to get them going 326 BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : 327 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 328 -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; 329 BuildUImageScript boot.scr 330 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 331 } 332 333 case bios_ia32 : 334 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 335 336 case pxe_ia32 : 337 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 338 339 case openfirmware : 340 BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 341 342 case u-boot : 343 local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ; 344 BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) 345 : 346 -A $(TARGET_ARCH) -O linux -T kernel -C none 347 -a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry) 348 -n 'Haiku $(TARGET_KERNEL_ARCH) loader' ; 349 BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : 350 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 351 -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; 352 BuildUImageScript boot.scr 353 : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; 354 355 case amiga_m68k : 356 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 357 ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 358 359 case atari_m68k : 360 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 361 ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; 362 363 AtariBootPrgLd haiku.prg : 364 boot_loader_$(TARGET_BOOT_PLATFORM) 365 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld 366 : -Bstatic 367 ; 368 369 case * : 370 Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ; 371 } 372 } 373} 374 375SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ; 376SubInclude HAIKU_TOP src system boot loader ; 377SubInclude HAIKU_TOP src system boot platform ; 378