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