1# Set anyboot file name and directory defaults. 2HAIKU_MMC_NAME ?= $(HAIKU_DEFAULT_MMC_NAME) ; 3HAIKU_MMC_DIR ?= $(HAIKU_DEFAULT_MMC_DIR) ; 4HAIKU_MMC = $(HAIKU_MMC_NAME) ; 5HAIKU_MMC_LABEL ?= $(HAIKU_DEFAULT_MMC_LABEL) ; 6 7# SD/mmc image rule 8# Files must be in this order: 9# out : mbrtool fatshell os_image loader floppyboot everything_else 10rule BuildSDImage image : files 11{ 12 local mbrtool = <build>mbrtool ; 13 local fatshell = <build>fat_shell ; 14 15 Depends $(image) : $(HAIKU_IMAGE_NAME) ; 16 Depends $(image) : $(mbrtool) ; 17 Depends $(image) : $(fatshell) ; 18 19 SDIMAGE_OS_SIZE on $(image) = $(HAIKU_IMAGE_SIZE) ; 20 SDIMAGE_BEGIN on $(image) = $(HAIKU_BOOT_SDIMAGE_BEGIN:E=63) ; 21 22 if $(TARGET_BOOT_PLATFORM) = efi { 23 switch $(TARGET_ARCH) { 24 case x86 : 25 EFINAME on $(image) = "BOOTIA32.EFI" ; 26 case x86_64 : 27 EFINAME on $(image) = "BOOTX64.EFI" ; 28 case arm : 29 EFINAME on $(image) = "BOOTARM.EFI" ; 30 case arm64 : 31 EFINAME on $(image) = "BOOTAA64.EFI" ; 32 case riscv32 : 33 EFINAME on $(image) = "BOOTRISCV32.EFI" ; 34 case riscv64 : 35 EFINAME on $(image) = "BOOTRISCV64.EFI" ; 36 case * : 37 Exit "Error: Unknown EFI architecture!" ; 38 } 39 BuildEfiSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ; 40 } else if $(TARGET_BOOT_PLATFORM) = u-boot { 41 BuildUBootSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ; 42 } else { 43 # TODO: For now we do nothing. Maybe we want a "AddSDImage" to 44 # append additional loaders like the raw riscv one? 45 echo "Asked for $(TARGET_BOOT_PLATFORM) target boot platform" ; 46 echo "Unknown path to handle adding to image" ; 47 } 48} 49 50# Usage: 51# out : mbrtool fatshell os_image loader floppyboot everything_else 52actions BuildUBootSDImage1 53{ 54 $(RM) $(1) 55 56 export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 57 58 # in KiB 59 EFI_SIZE=32768 60 BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)` 61 MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}` 62 63 # Build "boot" disk 64 dd if=/dev/zero of=$(1) bs=1024 count=${BOOT_SIZE} 65 66 # generate u-boot environment variables 67 echo 'os=haiku' > uEnv.txt 68 echo 'platform=u-boot' >> uEnv.txt 69 echo "loader=haiku_loader.ub" >> uEnv.txt 70 71 # Lay down partition map 72 OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}` 73 74 # EFI System Partition 75 $(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE} 76 # OS Partition 77 $(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH} 78 79 FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`" 80 81 # format the image 82 ${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \ 83 --initialize "$(1)" 'Haiku Boot' 84 85 # populate 86 for i in $(2[4-]) ; do 87 echo "cp :${i} myfs/" | ${FATFS} $(1) 88 done 89 90 echo "cp :uEnv.txt myfs/" | ${FATFS} $(1) 91 92 # lay down optional FDT path 93 echo "mkdir myfs/fdt" | ${FATFS} $(1) 94 95 # list content 96 echo "ls myfs" | ${FATFS} $(1) 97 98 # cleanup 99 $(RM) uEnv.txt 100 $(RM) boot.scr 101 102 # Add haiku partition to MMC image 103 cat $(2[3-3]) >> $(1) 104} 105 106 107# Usage: 108# out : mbrtool fatshell os_image loader floppyboot everything_else 109actions BuildEfiSDImage1 110{ 111 $(RM) $(1) 112 113 export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 114 115 # in KiB 116 EFI_SIZE=32768 117 BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)` 118 MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}` 119 120 # Build "boot" disk 121 dd if=/dev/zero of=$(1) bs=1024 count=${BOOT_SIZE} 122 123 # generate u-boot environment variables 124 echo 'os=haiku' > uEnv.txt 125 echo 'platform=efi' >> uEnv.txt 126 echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt 127 128 # Lay down partition map 129 OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}` 130 131 # EFI System Partition 132 $(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE} 133 # OS Partition 134 $(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH} 135 136 FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`" 137 138 # format the image 139 ${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \ 140 --initialize "$(1)" 'Haiku Boot' 141 142 # populate 143 echo "mkdir -p myfs/EFI/BOOT" | ${FATFS} $(1) 144 echo "cp :$(2[4-4]) myfs/EFI/BOOT/$(EFINAME)" | ${FATFS} $(1) 145 146 # copy misc files 147 for i in $(2[5-]) ; do 148 echo "cp :${i} myfs/" | ${FATFS} $(1) 149 done 150 echo "cp :uEnv.txt myfs/" | ${FATFS} $(1) 151 152 # lay down optional FDT path 153 echo "mkdir myfs/fdt" | ${FATFS} $(1) 154 155 # list content 156 echo "ls myfs" | ${FATFS} $(1) 157 158 # cleanup 159 $(RM) uEnv.txt 160 $(RM) boot.scr 161 162 # Add haiku partition to MMC image 163 cat $(2[3-3]) >> $(1) 164} 165 166for platform in [ MultiBootSubDirSetup ] { 167 on $(platform) { 168 # SD/mmc image targets 169 if $(TARGET_BOOT_PLATFORM) = efi { 170 if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = riscv64 { 171 # These EFI platforms need u-boot to get them going 172 BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE) 173 haiku_loader.$(TARGET_BOOT_PLATFORM) 174 boot.scr ; 175 } else { 176 BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE) 177 haiku_loader.$(TARGET_BOOT_PLATFORM) ; 178 } 179 } else if $(TARGET_BOOT_PLATFORM) = u-boot { 180 BuildSDImage $(HAIKU_MMC_NAME) : 181 $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) boot.scr ; 182 } else { 183 BuildSDImage $(HAIKU_MMC_NAME) : 184 $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) boot.scr ; 185 } 186 } 187} 188 189#BlessSDImage haiku-$(TARGET_KERNEL_ARCH).mmc ; 190NotFile haiku-mmc-image ; 191Depends haiku-mmc-image : $(HAIKU_MMC_NAME) ; 192