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# requires mtools package on linux 9# Files must be in this order: loader floppyboot everything_else 10rule BuildSDImage image : files 11{ 12 Depends $(image) : $(files) $(TARGET_DEVICE_TREES) ; 13 SDIMAGE_BLOCK_SIZE on $(image) = 1048576 ; # 1MiB 14 SDIMAGE_MTOOLS_H on $(image) = 255 ; 15 SDIMAGE_MTOOLS_S on $(image) = 63 ; 16 SDIMAGE_MTOOLS_C on $(image) = 8 ; 17 SDIMAGE_SIZE on $(image) = $(HAIKU_BOOT_SDIMAGE_SIZE) ; 18 SDIMAGE_BEGIN on $(image) = $(HAIKU_BOOT_SDIMAGE_BEGIN:E=63) ; 19 20 if $(TARGET_BOOT_PLATFORM) = efi { 21 switch $(TARGET_ARCH) { 22 case x86_64 : 23 EFINAME on $(image) = "BOOTX64.EFI" ; 24 case arm : 25 EFINAME on $(image) = "BOOTARM.EFI" ; 26 case arm64 : 27 EFINAME on $(image) = "BOOTAA64.EFI" ; 28 case riscv32 : 29 EFINAME on $(image) = "BOOTRISCV32.EFI" ; 30 case riscv64 : 31 EFINAME on $(image) = "BOOTRISCV64.EFI" ; 32 case * : 33 Exit "Error: Unknown EFI architecture!" ; 34 } 35 BuildEfiSDImage1 $(image) : $(files) ; 36 } else { 37 BuildUBootSDImage1 $(image) : $(files) ; 38 } 39} 40 41# Usage: image : loader floppyboot everything_else 42actions BuildUBootSDImage1 43{ 44 $(RM) $(1) 45 $(RM) $(1).mtools 46 47 # make an empty image 48 dd of=$(1) \ 49 if=/dev/zero \ 50 bs=$(SDIMAGE_BLOCK_SIZE) \ 51 count=$(SDIMAGE_SIZE) 52 # generate mtools config 53 echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) 54 heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S) 55 mformat_only' > $(1).mtools 56 # partition it 57 MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i: 58 # format the image 59 MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i: 60 61 # generate u-boot environment variables 62 echo 'os=haiku' > uEnv.txt 63 echo 'platform=u-boot' >> uEnv.txt 64 echo 'loader=haiku_loader.ub' >> uEnv.txt 65 66 # populate 67 MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/haiku_loader.ub 68 MTOOLSRC=$(1).mtools mcopy $(2[3-3]) i:/haiku_floppyboot.ub 69 MTOOLSRC=$(1).mtools mcopy $(2[4-]) i: 70 MTOOLSRC=$(1).mtools mcopy uEnv.txt i: 71 # populate fdts 72 MTOOLSRC=$(1).mtools mmd i:/fdt 73 MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ 74 # list content 75 MTOOLSRC=$(1).mtools mdir i: 76 MTOOLSRC=$(1).mtools mdir i:/fdt 77 # cleanup 78 $(RM) $(1).mtools 79 $(RM) uEnv.txt 80 $(RM) boot.scr 81 # Add haiku bootstrap partition to MMC image 82 cat $(2[0]) >> $(1) 83} 84 85# Usage: image : loader everything_else 86actions BuildEfiSDImage1 87{ 88 $(RM) $(1) 89 $(RM) $(1).mtools 90 91 # make an empty image 92 dd of=$(1) \ 93 if=/dev/zero \ 94 bs=$(SDIMAGE_BLOCK_SIZE) \ 95 count=$(SDIMAGE_SIZE) 96 # generate mtools config 97 echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) 98 heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S) 99 mformat_only' > $(1).mtools 100 # partition it 101 MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i: 102 # format the image 103 MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i: 104 105 # generate u-boot environment variables 106 echo 'os=haiku' > uEnv.txt 107 echo 'platform=efi' >> uEnv.txt 108 echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt 109 110 # populate 111 MTOOLSRC=$(1).mtools mmd i:/EFI 112 MTOOLSRC=$(1).mtools mmd i:/EFI/BOOT 113 MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/EFI/BOOT/$(EFINAME) 114 MTOOLSRC=$(1).mtools mcopy $(2[3-]) i: 115 MTOOLSRC=$(1).mtools mcopy uEnv.txt i: 116 # populate fdts 117 MTOOLSRC=$(1).mtools mmd i:/fdt 118 MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ 119 # list content 120 MTOOLSRC=$(1).mtools mdir i: 121 MTOOLSRC=$(1).mtools mdir i:/fdt 122 MTOOLSRC=$(1).mtools mdir i:/EFI/BOOT 123 # cleanup 124 $(RM) $(1).mtools 125 $(RM) uEnv.txt 126 $(RM) boot.scr 127 # Add haiku bootstrap partition to MMC image 128 cat $(2[0]) >> $(1) 129} 130 131for platform in [ MultiBootSubDirSetup ] { 132 on $(platform) { 133 # SD/mmc image targets 134 if $(TARGET_BOOT_PLATFORM) = efi { 135 if $(TARGET_ARCH) = arm || $(TARGET_ARCH) = arm64 || $(TARGET_ARCH) = riscv64 { 136 # These EFI platforms need u-boot to get them going 137 BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE) 138 haiku_loader.$(TARGET_BOOT_PLATFORM) 139 boot.scr ; 140 } else { 141 BuildSDImage $(HAIKU_MMC_NAME) : $(HAIKU_IMAGE) 142 haiku_loader.$(TARGET_BOOT_PLATFORM) ; 143 } 144 } else { 145 BuildSDImage $(HAIKU_MMC_NAME) : 146 $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) boot.scr ; 147 } 148 } 149} 150 151#BlessSDImage haiku-$(TARGET_KERNEL_ARCH).mmc ; 152NotFile haiku-mmc-image ; 153Depends haiku-mmc-image : $(HAIKU_MMC_NAME) ; 154