From 5a85ebb08bef24fa798710a2fe73bd43d51a29c3 Mon Sep 17 00:00:00 2001 From: Zoltan HERPAI Date: Thu, 31 Aug 2023 23:35:27 +0200 Subject: [PATCH] sunxi: t113: add eMMC image generation support Signed-off-by: Zoltan HERPAI --- target/linux/sunxi/image/Makefile | 22 +++++++++++++- target/linux/sunxi/image/cortexa7.mk | 4 +++ .../linux/sunxi/image/gen_sunxi_emmc_img.sh | 30 +++++++++++++++++++ .../sunxi/image/mmc.bootscript.ttyS5-emmc.txt | 8 +++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 target/linux/sunxi/image/gen_sunxi_emmc_img.sh create mode 100644 target/linux/sunxi/image/mmc.bootscript.ttyS5-emmc.txt diff --git a/target/linux/sunxi/image/Makefile b/target/linux/sunxi/image/Makefile index ee36df598a..283a7b973c 100644 --- a/target/linux/sunxi/image/Makefile +++ b/target/linux/sunxi/image/Makefile @@ -11,6 +11,11 @@ FAT32_BLOCKS=$(shell echo $$(($(CONFIG_SUNXI_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32 DEVICE_VARS := SUNXI_DTS SUNXI_DTS_DIR +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) @@ -27,7 +32,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 diff --git a/target/linux/sunxi/image/cortexa7.mk b/target/linux/sunxi/image/cortexa7.mk index 85eb5100d0..91e0cf580f 100644 --- a/target/linux/sunxi/image/cortexa7.mk +++ b/target/linux/sunxi/image/cortexa7.mk @@ -266,7 +266,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 @@ -283,6 +285,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 index 0000000000..710dccd3af --- /dev/null +++ b/target/linux/sunxi/image/gen_sunxi_emmc_img.sh @@ -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 " + 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 index 0000000000..353429bd09 --- /dev/null +++ b/target/linux/sunxi/image/mmc.bootscript.ttyS5-emmc.txt @@ -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 -- 2.30.2