build/mmc: Drop usage of mtools, use internal tooling

* Fixes the ARM image to actually include Haiku within
  a partition on the SD card.
* Drops the mtools requirement
* Drops the C/H/S requirements

Change-Id: Ie2776a09399ac181daab7a503e96e27ab7093af4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3608
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Alexander von Gluck IV
2021-01-07 21:34:00 +00:00
committed by Alex von Gluck IV
parent fa1f5839be
commit 58332722cd
2 changed files with 101 additions and 74 deletions
+3 -8
View File
@@ -240,9 +240,8 @@ rule KernelArchitectureSetup architecture
HAIKU_KERNEL_PLATFORM ?= efi ; HAIKU_KERNEL_PLATFORM ?= efi ;
HAIKU_BOOT_TARGETS += efi ; HAIKU_BOOT_TARGETS += efi ;
HAIKU_BOOT_SDIMAGE_SIZE ?= 32 ;
# SOC's like allwinner need an offset to skip the hardcoded initial loader # SOC's like allwinner need an offset to skip the hardcoded initial loader
HAIKU_BOOT_SDIMAGE_BEGIN = 40950 ; # 512-byte sectors (divisible by 63) HAIKU_BOOT_SDIMAGE_BEGIN = 20475 ; # in KiB
HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
# offset in floppy image (>= sizeof(haiku_loader)) # offset in floppy image (>= sizeof(haiku_loader))
@@ -253,9 +252,7 @@ rule KernelArchitectureSetup architecture
HAIKU_KERNEL_PLATFORM ?= efi ; HAIKU_KERNEL_PLATFORM ?= efi ;
HAIKU_BOOT_TARGETS += efi ; HAIKU_BOOT_TARGETS += efi ;
HAIKU_BOOT_SDIMAGE_SIZE ?= 32 ; HAIKU_BOOT_SDIMAGE_BEGIN = 0 ; # in KiB
# SOC's like allwinner need an offset to skip the hardcoded initial loader
HAIKU_BOOT_SDIMAGE_BEGIN = 40950 ; # 512-byte sectors (divisible by 63)
HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
# offset in floppy image (>= sizeof(haiku_loader)) # offset in floppy image (>= sizeof(haiku_loader))
@@ -280,9 +277,7 @@ rule KernelArchitectureSetup architecture
HAIKU_KERNEL_PLATFORM ?= efi ; HAIKU_KERNEL_PLATFORM ?= efi ;
HAIKU_BOOT_TARGETS += efi ; HAIKU_BOOT_TARGETS += efi ;
HAIKU_BOOT_SDIMAGE_SIZE ?= 128 ; HAIKU_BOOT_SDIMAGE_BEGIN = 0 ; # KiB
# SOC's like allwinner need an offset to skip the hardcoded initial loader
HAIKU_BOOT_SDIMAGE_BEGIN = 40950 ; # 512-byte sectors (divisible by 63)
HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ;
# offset in floppy image (>= sizeof(haiku_loader)) # offset in floppy image (>= sizeof(haiku_loader))
+98 -66
View File
@@ -5,16 +5,20 @@ HAIKU_MMC = $(HAIKU_MMC_NAME) ;
HAIKU_MMC_LABEL ?= $(HAIKU_DEFAULT_MMC_LABEL) ; HAIKU_MMC_LABEL ?= $(HAIKU_DEFAULT_MMC_LABEL) ;
# SD/mmc image rule # SD/mmc image rule
# requires mtools package on linux # Files must be in this order:
# Files must be in this order: loader floppyboot everything_else # out : mbrtool fatshell os_image loader floppyboot everything_else
rule BuildSDImage image : files rule BuildSDImage image : files
{ {
local mbrtool = <build>mbrtool ;
local fatshell = <build>fat_shell ;
Depends $(image) : $(files) $(TARGET_DEVICE_TREES) ; Depends $(image) : $(files) $(TARGET_DEVICE_TREES) ;
SDIMAGE_BLOCK_SIZE on $(image) = 1048576 ; # 1MiB Depends $(image) : $(HAIKU_IMAGE_NAME) ;
SDIMAGE_MTOOLS_H on $(image) = 255 ; Depends $(image) : $(mbrtool) ;
SDIMAGE_MTOOLS_S on $(image) = 63 ; Depends $(image) : $(fatshell) ;
SDIMAGE_MTOOLS_C on $(image) = 8 ;
SDIMAGE_SIZE on $(image) = $(HAIKU_BOOT_SDIMAGE_SIZE) ; SDIMAGE_OS_NAME on $(image) = $(HAIKU_IMAGE_NAME) ;
SDIMAGE_OS_SIZE on $(image) = $(HAIKU_IMAGE_SIZE) ;
SDIMAGE_BEGIN on $(image) = $(HAIKU_BOOT_SDIMAGE_BEGIN:E=63) ; SDIMAGE_BEGIN on $(image) = $(HAIKU_BOOT_SDIMAGE_BEGIN:E=63) ;
if $(TARGET_BOOT_PLATFORM) = efi { if $(TARGET_BOOT_PLATFORM) = efi {
@@ -32,100 +36,128 @@ rule BuildSDImage image : files
case * : case * :
Exit "Error: Unknown EFI architecture!" ; Exit "Error: Unknown EFI architecture!" ;
} }
BuildEfiSDImage1 $(image) : $(files) ; BuildEfiSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ;
} else { } else {
BuildUBootSDImage1 $(image) : $(files) ; BuildUBootSDImage1 $(image) : $(mbrtool) $(fatshell) $(files) ;
} }
} }
# Usage: image : loader floppyboot everything_else # Usage:
# out : mbrtool fatshell os_image loader floppyboot everything_else
actions BuildUBootSDImage1 actions BuildUBootSDImage1
{ {
$(RM) $(1) $(RM) $(1)
$(RM) $(1).mtools
# make an empty image # in KiB
dd of=$(1) \ EFI_SIZE=32768
if=/dev/zero \ BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)`
bs=$(SDIMAGE_BLOCK_SIZE) \ MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}`
count=$(SDIMAGE_SIZE)
# generate mtools config # Build "boot" disk
echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) dd if=/dev/zero of=$(1) bs=1K count=${BOOT_SIZE}
heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S)
mformat_only' > $(1).mtools
# partition it
MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i:
# format the image
MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i:
# generate u-boot environment variables # generate u-boot environment variables
echo 'os=haiku' > uEnv.txt echo 'os=haiku' > uEnv.txt
echo 'platform=u-boot' >> uEnv.txt echo 'platform=u-boot' >> uEnv.txt
echo 'loader=haiku_loader.ub' >> uEnv.txt echo "loader=haiku_loader.ub" >> uEnv.txt
# Lay down partition map
OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}`
# EFI System Partition
$(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE}
# OS Partition
$(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH}
FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`"
# format the image
${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \
--initialize "$(1)" 'Haiku Boot'
# populate # populate
MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/haiku_loader.ub for i in $(2[4-]) ; do
MTOOLSRC=$(1).mtools mcopy $(2[3-3]) i:/haiku_floppyboot.ub echo "cp :${i} myfs/" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mcopy $(2[4-]) i: done
MTOOLSRC=$(1).mtools mcopy uEnv.txt i:
# populate fdts echo "cp :uEnv.txt myfs/" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mmd i:/fdt
MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ # lay down FDT's
echo "mkdir myfs/fdt" | ${FATFS} $(1)
for i in $(TARGET_DEVICE_TREES[1-]) ; do
echo "cp :${i} myfs/fdt/" | ${FATFS} $(1)
done
# list content # list content
MTOOLSRC=$(1).mtools mdir i: echo "ls myfs" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mdir i:/fdt
# cleanup # cleanup
$(RM) $(1).mtools
$(RM) uEnv.txt $(RM) uEnv.txt
$(RM) boot.scr $(RM) boot.scr
# Add haiku bootstrap partition to MMC image
cat $(2[0]) >> $(1) # Add haiku partition to MMC image
cat $(2[3-3]) >> $(1)
} }
# Usage: image : loader everything_else
# Usage:
# out : mbrtool fatshell os_image loader floppyboot everything_else
actions BuildEfiSDImage1 actions BuildEfiSDImage1
{ {
$(RM) $(1) $(RM) $(1)
$(RM) $(1).mtools
# make an empty image # in KiB
dd of=$(1) \ EFI_SIZE=32768
if=/dev/zero \ BOOT_SIZE=`expr ${EFI_SIZE} + $(SDIMAGE_BEGIN)`
bs=$(SDIMAGE_BLOCK_SIZE) \ MMC_SIZE=`expr $(SDIMAGE_OS_SIZE) \* 1024 + ${BOOT_SIZE}`
count=$(SDIMAGE_SIZE)
# generate mtools config # Build "boot" disk
echo 'drive i: file="$(1)" partition=1 cylinders=$(SDIMAGE_MTOOLS_C) dd if=/dev/zero of=$(1) bs=1K count=${BOOT_SIZE}
heads=$(SDIMAGE_MTOOLS_H) sectors=$(SDIMAGE_MTOOLS_S)
mformat_only' > $(1).mtools
# partition it
MTOOLSRC=$(1).mtools mpartition -b$(SDIMAGE_BEGIN) -cI -T 0xc i:
# format the image
MTOOLSRC=$(1).mtools mformat -L 32 -v "HAIKU" i:
# generate u-boot environment variables # generate u-boot environment variables
echo 'os=haiku' > uEnv.txt echo 'os=haiku' > uEnv.txt
echo 'platform=efi' >> uEnv.txt echo 'platform=efi' >> uEnv.txt
echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt echo "loader=EFI/BOOT/$(EFINAME)" >> uEnv.txt
# Lay down partition map
OS_LENGTH=`expr ${MMC_SIZE} - ${BOOT_SIZE}`
# EFI System Partition
$(2[1]) $(1) 0 0xef $(SDIMAGE_BEGIN) ${EFI_SIZE}
# OS Partition
$(2[1]) $(1) 1 0xeb ${BOOT_SIZE} ${OS_LENGTH}
FATFS="$(2[2]) --start-offset `expr $(SDIMAGE_BEGIN) \* 1024`"
# format the image
${FATFS} --end-offset `expr ${BOOT_SIZE} \* 1024` \
--initialize "$(1)" 'Haiku Boot'
# populate # populate
MTOOLSRC=$(1).mtools mmd i:/EFI echo "mkdir -p myfs/EFI/BOOT" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mmd i:/EFI/BOOT echo "cp :$(2[4-4]) myfs/EFI/BOOT/$(EFINAME)" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mcopy $(2[2-2]) i:/EFI/BOOT/$(EFINAME)
MTOOLSRC=$(1).mtools mcopy $(2[3-]) i: # copy misc files
MTOOLSRC=$(1).mtools mcopy uEnv.txt i: for i in $(2[5-]) ; do
# populate fdts echo "cp :${i} myfs/" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mmd i:/fdt done
MTOOLSRC=$(1).mtools mcopy $(TARGET_DEVICE_TREES[1-]) i:/fdt/ echo "cp :uEnv.txt myfs/" | ${FATFS} $(1)
# lay down FDT's
echo "mkdir myfs/fdt" | ${FATFS} $(1)
for i in $(TARGET_DEVICE_TREES[1-]) ; do
echo "cp :${i} myfs/fdt/" | ${FATFS} $(1)
done
# list content # list content
MTOOLSRC=$(1).mtools mdir i: echo "ls myfs" | ${FATFS} $(1)
MTOOLSRC=$(1).mtools mdir i:/fdt
MTOOLSRC=$(1).mtools mdir i:/EFI/BOOT
# cleanup # cleanup
$(RM) $(1).mtools
$(RM) uEnv.txt $(RM) uEnv.txt
$(RM) boot.scr $(RM) boot.scr
# Add haiku bootstrap partition to MMC image
cat $(2[0]) >> $(1) # Add haiku partition to MMC image
cat $(2[3-3]) >> $(1)
} }
for platform in [ MultiBootSubDirSetup ] { for platform in [ MultiBootSubDirSetup ] {