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