SubDir HAIKU_TOP src system boot ; DEFINES += _BOOT_MODE ; UsePrivateHeaders [ FDirName libroot locale ] ; rule BuildOpenFirmwareLoader { local haikuLoader = $(1) ; local bootLoader = $(2) ; Depends $(haikuLoader) : $(bootLoader) ; MakeLocateDebug $(haikuLoader) ; switch $(TARGET_ARCH) { case ppc : BuildCoffLoader $(haikuLoader) : $(bootLoader) ; case sparc : BuildAoutLoader $(haikuLoader) : $(bootLoader) ; case * : Exit "Currently unsupported arch:" $(TARGET_ARCH) ; } } # # A.out haiku_loader creation # rule BuildAoutLoader { local haikuLoader = $(1) ; local bootLoader = $(2) ; ELF2AOUT on $(haikuLoader) = elf2aout ; Depends $(haikuLoader) : elf2aout ; } actions BuildAoutLoader bind ELF2AOUT { rm -f $(1) $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) \ $(ELF2AOUT) -o $(1) $(2) } # # Coff haiku_loader creation # rule BuildCoffLoader { local coffLoader = $(1) ; local bootLoader = $(2) ; switch $(TARGET_ARCH) { case ppc : COFF_FORMAT on $(coffLoader) = xcoff-powermac ; case * : Exit "Currently unsupported coff arch:" $(TARGET_ARCH) ; } HACK_COFF on $(coffLoader) = hack-coff ; Depends $(coffLoader) : hack-coff ; } actions BuildCoffLoader bind HACK_COFF { rm -f $(1) # get the address of the COFF entry $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2` rm -f $(2).syms # copy to XCOFF format and patch the entry point $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1) #$(CP) $(2) $(1) # fill-in some fields objcopy missed $(HACK_COFF) $(1) } # # BIOS haiku_loader creation # rule BuildBiosLoader { local haikuLoader = $(1) ; local bootLoader = $(2) ; Depends $(haikuLoader) : $(bootLoader) ; MakeLocateDebug $(haikuLoader) ; on $(1) ResAttr $(1) : $(RESFILES) : false ; if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { SetType $(1) ; MimeSet $(1) ; } } actions BuildBiosLoader { rm -f $(1) $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O binary $(2) $(1) } # # EFI loader creation # rule BuildEFILoader { local efiLoader = $(1) ; local bootLoader = $(2) ; Depends $(efiLoader) : $(bootLoader) ; switch $(TARGET_ARCH) { case x86_64 : OUTPUT_TARGET on $(efiLoader) = efi-app-x86_64 ; case arm : OUTPUT_TARGET on $(efiLoader) = binary ; case arm64 : OUTPUT_TARGET on $(efiLoader) = binary ; case * : Exit "Currently unsupported arch:" $(TARGET_ARCH) ; } MakeLocateDebug $(efiLoader) ; } actions BuildEFILoader { rm -f $(1) $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc -j .dynstr \ --output-target=$(OUTPUT_TARGET) $(2) $(1) } # # U-boot image creation # rule BuildUImage image : data : args { Depends $(image) : $(data) ; LocalClean clean : $(image) ; MKIMAGE_ARGS on $(image) = $(args) ; colon on $(image) = ":" ; local files = $(data:G=) ; BuildUImage1 $(image) : $(data) ; } actions BuildUImage1 { mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<) } # # Given a txt, generate a binary u-boot script # rule BuildUImageScript script : source { Depends $(script) : $(source) ; LocalClean clean : $(script) ; SCRIPTNAME on $(script) = $(script) ; FAKEOS on $(script) = "linux" ; BuildUImageScript1 $(script) : $(source) ; } actions BuildUImageScript1 { rm -f $(1) mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ -d $(2) $(1) } # the bootsector on haiku_loader.amiga_m68k must be checksummed rule ChecksumAmigaLoader { local haikuLoader = $(1) ; local checksummer = fixup_amiga_boot_checksum ; Depends $(haikuLoader) : $(checksummer) ; TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; } actions ChecksumAmigaLoader bind TARGET_CHECKSUM { $(TARGET_CHECKSUM) $(1) } # the bootsector on haiku_loader.atari_m68k must be checksummed rule ChecksumAtariLoader { local haikuLoader = $(1) ; local checksummer = fixup_tos_boot_checksum ; Depends $(haikuLoader) : $(checksummer) ; TARGET_CHECKSUM on $(haikuLoader) = $(checksummer) ; } actions ChecksumAtariLoader bind TARGET_CHECKSUM { $(TARGET_CHECKSUM) $(1) } # atari_m68k: AUTO folder PRG target # based on KernelLd rule AtariBootPrgLd { # AtariBootPrgLd : : : ; LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; LINKFLAGS on $(1) = $(4) ; if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } # Remove any preset LINKLIBS LINKLIBS on $(1) = ; # TODO: Do we really want to invoke SetupKernel here? The objects should # have been compiled with KernelObjects anyway, so we're doing that twice. SetupKernel $(2) ; # Show that we depend on the libraries we need LocalClean clean : $(1) ; LocalDepends all : $(1) ; Depends $(1) : $(2) ; MakeLocateDebug $(1) ; } actions AtariBootPrgLd { $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; } local extraSources = ; if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 { extraSources += atomic.S ; } for platform in [ MultiBootSubDirSetup ] { on $(platform) { if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi { SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch x86_64 ] ; } else { SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch $(TARGET_KERNEL_ARCH) ] ; } SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ; BootMergeObject boot_libroot_$(platform:G=).o : abs.c ctype.cpp LocaleData.cpp qsort.c kernel_vsprintf.cpp memchr.c memcmp.c memmove.c strdup.cpp strndup.cpp strlen.cpp strnlen.cpp strcmp.c strcasecmp.c strncmp.c strcat.c strcpy.c strerror.c strlcat.c strlcpy.c strchr.c strrchr.c strtol.c strtoul.c $(extraSources) ; AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ; local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ; local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ; local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ; ldflags ?= $(TARGET_BOOT_LDFLAGS) ; # efi loader needs to be shared. if $(TARGET_BOOT_PLATFORM) = efi { ldflags += -shared ; ldflags += -Map=efi.map ; } BootLd boot_loader_$(platform:G=) : boot_platform_$(platform:G=).o $(archObject:G=$(archGrist)) [ MultiBootGristFiles boot_loader.a boot_net.a boot_partitions.a # file systems boot_bfs.a boot_amiga_ffs.a boot_tarfs.a boot_fatfs.a boot_packagefs.a boot_loader.a # a second time, so undefined references in the file systems can be # resolved # needed by tarfs, packagefs, and video_splash.cpp boot_zlib.a ] # libroot functions needed by the stage2 boot loader boot_libroot_$(platform:G=).o : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld : $(ldflags) ; switch $(TARGET_BOOT_PLATFORM) { case efi : BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 { # These platforms sometimes need u-boot to get them going BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : -A $(TARGET_ARCH) -O linux -T ramdisk -C none -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; BuildUImageScript boot.scr : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; } case bios_ia32 : BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; case pxe_ia32 : BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; case openfirmware : BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; case u-boot : local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ; BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) : -A $(TARGET_ARCH) -O linux -T kernel -C none -a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry) -n 'Haiku $(TARGET_KERNEL_ARCH) loader' ; BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : -A $(TARGET_ARCH) -O linux -T ramdisk -C none -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; BuildUImageScript boot.scr : [ FDirName $(HAIKU_TOP) data boot u-boot boot-$(TARGET_ARCH).scr.txt ] ; case amiga_m68k : BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; ChecksumAmigaLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; case atari_m68k : BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; ChecksumAtariLoader haiku_loader.$(TARGET_BOOT_PLATFORM) ; AtariBootPrgLd haiku.prg : boot_loader_$(TARGET_BOOT_PLATFORM) : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_prg_$(TARGET_BOOT_PLATFORM).ld : -Bstatic ; case * : Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ; } } } SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ; SubInclude HAIKU_TOP src system boot loader ; SubInclude HAIKU_TOP src system boot platform ;