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 MakeLocateDebug $(efiLoader) ; 105} 106 107actions BuildEFILoader 108{ 109 rm -f $(1) 110 $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -j .text -j .sdata -j .data \ 111 -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc -j .dynstr \ 112 --input-target=efi-app-x86_64 --output-target=efi-app-x86_64 \ 113 $(2) $(1) 114} 115 116 117# 118# U-boot image creation 119# 120rule BuildUImage image : data : args 121{ 122 Depends $(image) : $(data) ; 123 LocalClean clean : $(image) ; 124 MKIMAGE_ARGS on $(image) = $(args) ; 125 colon on $(image) = ":" ; 126 local files = $(data:G=) ; 127 BuildUImage1 $(image) : $(data) ; 128} 129 130actions BuildUImage1 131{ 132 mkimage $(MKIMAGE_ARGS) -d $(>:J=$(colon)) $(<) 133} 134 135rule BuildUImageScript script : content 136{ 137 LocalClean clean : $(script) ; 138 SCRIPTCONTENT on $(script) = $(content) ; 139 SCRIPTNAME on $(script) = $(script) ; 140 FAKEOS on $(script) = "linux" ; 141 BuildUImageScript1 $(script) : $(content) ; 142} 143 144actions BuildUImageScript1 145{ 146 rm -f $(<) $(<).txt 147 echo '$(SCRIPTCONTENT)' > $(<).txt 148 mkimage -A $(TARGET_ARCH) -O $(FAKEOS) -T script -C none -n $(SCRIPTNAME) \ 149 -d $(<).txt $(<) 150 rm -f $(<).txt 151} 152 153 154local extraSources = ; 155if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) = 2 { 156 extraSources += atomic.S ; 157} 158 159for platform in [ MultiBootSubDirSetup ] { 160 on $(platform) { 161 if $(TARGET_ARCH) = x86_64 && $(TARGET_BOOT_PLATFORM) = efi { 162 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 163 x86_64 ] ; 164 } else { 165 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot os arch 166 $(TARGET_KERNEL_ARCH) ] ; 167 } 168 169 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix string ] ; 170 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix stdlib ] ; 171 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) libroot posix locale ] ; 172 SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) kernel lib ] ; 173 174 BootMergeObject boot_libroot_$(platform:G=).o : 175 abs.c 176 ctype.cpp 177 LocaleData.cpp 178 qsort.c 179 kernel_vsprintf.cpp 180 memchr.c 181 memcmp.c 182 memmove.c 183 strdup.cpp 184 strndup.cpp 185 strlen.cpp 186 strnlen.cpp 187 strcmp.c 188 strcasecmp.c 189 strncmp.c 190 strcat.c 191 strcpy.c 192 strerror.c 193 strlcat.c 194 strlcpy.c 195 strchr.c 196 strrchr.c 197 strtol.c 198 strtoul.c 199 $(extraSources) 200 ; 201 202 AddResources haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader.rdef ; 203 204 local archGrist = [ FGrist src system boot arch $(TARGET_KERNEL_ARCH) $(platform:G=) ] ; 205 local archObject = boot_arch_$(TARGET_KERNEL_ARCH).o ; 206 local ldflags = $(HAIKU_BOOT_LDFLAGS) $(HAIKU_BOOT_$(platform:G=:U)_LDFLAGS) ; 207 ldflags ?= $(TARGET_BOOT_LDFLAGS) ; 208 209 # efi loader needs to be shared. 210 if $(TARGET_BOOT_PLATFORM) = efi { 211 ldflags += -shared ; 212 } 213 214 BootLd boot_loader_$(platform:G=) : 215 boot_platform_$(platform:G=).o 216 $(archObject:G=$(archGrist)) 217 [ MultiBootGristFiles 218 boot_loader.a 219 boot_net.a 220 boot_partitions.a 221 222 # file systems 223 boot_bfs.a 224 boot_amiga_ffs.a 225 boot_tarfs.a 226 boot_fatfs.a 227 boot_packagefs.a 228 229 boot_loader.a 230 # a second time, so undefined references in the file systems can be 231 # resolved 232 233 # needed by tarfs, packagefs, and video_splash.cpp 234 boot_zlib.a 235 ] 236 # libroot functions needed by the stage2 boot loader 237 boot_libroot_$(platform:G=).o 238 239 : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_$(platform:G=).ld 240 : $(ldflags) 241 ; 242 243 switch $(TARGET_BOOT_PLATFORM) { 244 case efi : 245 BuildEFILoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 246 247 case bios_ia32 : 248 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 249 250 case pxe_ia32 : 251 BuildBiosLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 252 253 case openfirmware : 254 BuildOpenFirmwareLoader haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) ; 255 256 case u-boot : 257 local loader_entry = `printf \"obase=16;ibase=16;10 + %x\\n\" $(HAIKU_BOOT_LOADER_BASE)|bc` ; 258 BuildUImage haiku_loader.$(TARGET_BOOT_PLATFORM) : boot_loader_$(TARGET_BOOT_PLATFORM) 259 : 260 -A $(TARGET_ARCH) -O linux -T kernel -C none 261 -a $(HAIKU_BOOT_LOADER_BASE) -e $(loader_entry) 262 -n 'Haiku $(TARGET_KERNEL_ARCH) loader' ; 263 BuildUImage haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) : haiku-floppyboot.tgz : 264 -A $(TARGET_ARCH) -O linux -T ramdisk -C none 265 -n 'Haiku $(TARGET_KERNEL_ARCH) floppyboot' ; 266 BuildUImageScript boot.scr : $(HAIKU_MMC_UBOOT_SCRIPT) ; 267 268 case * : 269 Exit "Currently unsupported haiku_loader:" $(TARGET_BOOT_PLATFORM) ; 270 } 271 } 272} 273 274SubInclude HAIKU_TOP src system boot arch $(TARGET_KERNEL_ARCH) ; 275SubInclude HAIKU_TOP src system boot loader ; 276SubInclude HAIKU_TOP src system boot platform ; 277