sunxi: t113: add eMMC image generation support
authorZoltan HERPAI <wigyori@uid0.hu>
Thu, 31 Aug 2023 21:35:27 +0000 (23:35 +0200)
committerZoltan HERPAI <wigyori@uid0.hu>
Wed, 6 Mar 2024 22:51:05 +0000 (23:51 +0100)
Signed-off-by: Zoltan HERPAI <wigyori@uid0.hu>
target/linux/sunxi/image/Makefile
target/linux/sunxi/image/cortexa7.mk
target/linux/sunxi/image/gen_sunxi_emmc_img.sh [new file with mode: 0755]
target/linux/sunxi/image/mmc.bootscript.ttyS5-emmc.txt [new file with mode: 0644]

index 738585accc86cc7983b9c0fd56f56989ec2780a8..35ccc2ba6e210a546dc2cf50df2228036d861581 100644 (file)
@@ -12,6 +12,11 @@ FAT32_BLOCKS=$(shell echo $$(($(CONFIG_SUNXI_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32
 DEVICE_VARS := SUNXI_DTS SUNXI_DTS_DIR
 KERNEL_LOADADDR:=0x40008000
 
+define Build/boot-scr-emmc
+       rm -f $@-boot.scr
+       mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d mmc.bootscript.ttyS5-emmc.txt $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-emmcboot.scr
+endef
+
 define Build/sunxi-sdcard
        rm -f $@.boot
        mkfs.fat $@.boot -C $(FAT32_BLOCKS)
@@ -28,7 +33,22 @@ define Build/sunxi-sdcard
        rm -f $@.boot
 endef
 
-# why \x00\x00\x00\x00 for zImage-initramfs
+define Build/sunxi-emmc
+       rm -f $@.boot-emmc
+       mkfs.fat $@.boot-emmc -C $(FAT32_BLOCKS)
+
+       mcopy -i $@.boot-emmc $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-emmcboot.scr ::boot.scr
+       mcopy -i $@.boot-emmc $(DTS_DIR)/$(SUNXI_DTS).dtb ::dtb
+       mcopy -i $@.boot-emmc $(IMAGE_KERNEL) ::uImage
+
+       ./gen_sunxi_emmc_img.sh $@ \
+               $@.boot-emmc \
+               $(IMAGE_ROOTFS) \
+               $(CONFIG_SUNXI_SD_BOOT_PARTSIZE) \
+               $(CONFIG_TARGET_ROOTFS_PARTSIZE)
+       rm -f $@.boot
+endef
+
 define Device/Default
   PROFILES := Default
   KERNEL_NAME := zImage
index 9536e9a6e40217f01e8563bbbc8a98a5e1435943..377e95b8c1ace3e936c1a03f524c2fa04e2bf83b 100644 (file)
@@ -263,7 +263,9 @@ define Device/myir_myd-yt113x
   DEVICE_MODEL := MYD-YT113X
   DEVICE_PACKAGES := kmod-rtc-sunxi kmod-eeprom-at24 kmod-gpio-pca953x kmod-rtc-rx8025
   SOC := sun8i-t113s
+  IMAGES += emmc.img.gz
   IMAGE/sdcard.img.gz := sunxi-sdcard | append-metadata | gzip
+  IMAGE/emmc.img.gz := boot-scr-emmc | sunxi-emmc | append-metadata | gzip
 endef
 TARGET_DEVICES += myir_myd-yt113x
 
@@ -280,6 +282,8 @@ define Device/rongpin_rp-t113
   DEVICE_MODEL := RP-T113
   DEVICE_PACKAGES:=kmod-rtc-sunxi
   SOC := sun8i-t113s
+  IMAGES += emmc.img.gz
   IMAGE/sdcard.img.gz := sunxi-sdcard | append-metadata | gzip
+  IMAGE/emmc.img.gz := boot-scr-emmc | sunxi-emmc | append-metadata | gzip
 endef
 TARGET_DEVICES += rongpin_rp-t113
diff --git a/target/linux/sunxi/image/gen_sunxi_emmc_img.sh b/target/linux/sunxi/image/gen_sunxi_emmc_img.sh
new file mode 100755 (executable)
index 0000000..710dccd
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright (C) 2023 OpenWrt.org
+
+set -ex
+[ $# -eq 5 ] || {
+    echo "SYNTAX: $0 <file> <bootfs> <rootfs image> <bootfs size> <rootfs size>"
+    exit 1
+}
+
+OUTPUT="$1"
+BOOTFS="$2"
+ROOTFS="$3"
+BOOTFSSIZE="$4"
+ROOTFSSIZE="$5"
+
+head=4
+sect=63
+
+set $(ptgen -o $OUTPUT -h $head -s $sect -l 1024 -t c -p ${BOOTFSSIZE}M -t 83 -p ${ROOTFSSIZE}M)
+
+BOOTOFFSET="$(($1 / 512))"
+BOOTSIZE="$(($2 / 512))"
+ROOTFSOFFSET="$(($3 / 512))"
+ROOTFSSIZE="$(($4 / 512))"
+
+dd bs=512 if="$BOOTFS" of="$OUTPUT" seek="$BOOTOFFSET" conv=notrunc
+dd bs=512 if="$ROOTFS" of="$OUTPUT" seek="$ROOTFSOFFSET" conv=notrunc
+
diff --git a/target/linux/sunxi/image/mmc.bootscript.ttyS5-emmc.txt b/target/linux/sunxi/image/mmc.bootscript.ttyS5-emmc.txt
new file mode 100644 (file)
index 0000000..353429b
--- /dev/null
@@ -0,0 +1,8 @@
+setenv fdt_high ffffffff
+setenv mmc_rootpart 2
+part uuid mmc ${mmc_bootdev}:${mmc_rootpart} uuid
+setenv loadkernel fatload mmc \$mmc_bootdev \$kernel_addr_r uImage
+setenv loaddtb fatload mmc \$mmc_bootdev \$fdt_addr_r dtb
+setenv bootargs console=ttyS5,115200 earlyprintk root=PARTUUID=${uuid} rootwait
+setenv uenvcmd run loadkernel \&\& run loaddtb \&\& bootm \$kernel_addr_r - \$fdt_addr_r
+run uenvcmd