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 41actions BuildUBootSDImage1 42{ 43 $(RM) $(1) 44 $(RM) $(1).mtools 45 46 # make an empty image 47 dd of=$(1) \ 48 if=/dev/zero \ 49 bs=$(SDIMAGE_BLOCK_SIZE) \ 50 count=$(SDIMAGE_SIZE) 51 # generate mtools config 52 echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) 53 heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S) 54 mformat_only' > $(1).mtools 55 # partition it 56 MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i: 57 # format the image 58 MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i: 59 60 # generate u-boot environment variables 61 echo 'os=haiku' > uEnv.txt 62 echo 'platform=u-boot' >> uEnv.txt 63 echo 'loader=haiku_loader.ub' >> uEnv.txt 64 65 # populate 66 MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/haiku_loader.ub 67 MTOOLSRC=$(1).mtools mcopy $(2[3-3]) i:/haiku_floppyboot.ub 68 MTOOLSRC=$(1).mtools mcopy $(2[4-]) i: 69 MTOOLSRC=$(1).mtools mcopy uEnv.txt i: 70 # populate fdts 71 MTOOLSRC=$(1).mtools mmd i:/fdt 72 MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ 73 # list content 74 MTOOLSRC=$(1).mtools mdir i: 75 MTOOLSRC=$(1).mtools mdir i:/fdt 76 # cleanup 77 $(RM) $(1).mtools 78 $(RM) uEnv.txt 79 $(RM) boot.scr 80 # Add haiku bootstrap partition to MMC image 81 cat $(2[0]) >> $(1) 82} 83 84 85actions BuildEfiSDImage1 86{ 87 $(RM) $(1) 88 $(RM) $(1).mtools 89 90 # make an empty image 91 dd of=$(1) \ 92 if=/dev/zero \ 93 bs=$(SDIMAGE_BLOCK_SIZE) \ 94 count=$(SDIMAGE_SIZE) 95 # generate mtools config 96 echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) 97 heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S) 98 mformat_only' > $(1).mtools 99 # partition it 100 MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i: 101 # format the image 102 MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i: 103 104 # generate u-boot environment variables 105 echo 'os=haiku' > uEnv.txt 106 echo 'platform=efi' >> uEnv.txt 107 echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt 108 109 # populate 110 MTOOLSRC=$(1).mtools mmd i:/EFI 111 MTOOLSRC=$(1).mtools mmd i:/EFI/BOOT 112 MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/EFI/BOOT/$(EFINAME) 113 # Not really needed on EFI since we use EFI runtime services. 114 #MTOOLSRC=$(1).mtools mcopy $(2[3-3]) i:/haiku_floppyboot.ub 115 MTOOLSRC=$(1).mtools mcopy $(2[4-]) i: 116 MTOOLSRC=$(1).mtools mcopy uEnv.txt i: 117 # populate fdts 118 MTOOLSRC=$(1).mtools mmd i:/fdt 119 MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ 120 # list content 121 MTOOLSRC=$(1).mtools mdir i: 122 MTOOLSRC=$(1).mtools mdir i:/fdt 123 MTOOLSRC=$(1).mtools mdir i:/EFI/BOOT 124 # cleanup 125 $(RM) $(1).mtools 126 $(RM) uEnv.txt 127 $(RM) boot.scr 128 # Add haiku bootstrap partition to MMC image 129 cat $(2[0]) >> $(1) 130} 131 132for platform in [ MultiBootSubDirSetup ] { 133 on $(platform) { 134 # SD/mmc image targets 135 if $(TARGET_BOOT_PLATFORM) = efi { 136 BuildSDImage $(HAIKU_MMC_NAME) : 137 $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) boot.scr ; 138 } else { 139 BuildSDImage $(HAIKU_MMC_NAME) : 140 $(HAIKU_IMAGE) haiku_loader.$(TARGET_BOOT_PLATFORM) haiku-floppyboot.tgz.$(TARGET_BOOT_PLATFORM) boot.scr ; 141 } 142 } 143} 144 145#BlessSDImage haiku-$(TARGET_KERNEL_ARCH).mmc ; 146NotFile haiku-mmc-image ; 147Depends haiku-mmc-image : $(HAIKU_MMC_NAME) ; 148