[openwrt/openwrt] mediatek: mt7623: add scatter file for unbricking with SP Flash Tool
LEDE Commits
lede-commits at lists.infradead.org
Sun Jul 26 05:50:15 EDT 2020
981213 pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/5787684cb4e241bd5d28237fbcad5d4a0dca7ba1
commit 5787684cb4e241bd5d28237fbcad5d4a0dca7ba1
Author: David Woodhouse <dwmw2 at infradead.org>
AuthorDate: Tue Jul 21 17:43:12 2020 +0100
mediatek: mt7623: add scatter file for unbricking with SP Flash Tool
Many MediaTek SoCs can be unbricked by using the SP Flash Tool from
http://spflashtool.com/ along with a "scatter list" file, which is
just a text file listing which image gets loaded where.
We use a trivial partition layout for the tool, with the whole eMMC
image as a single "partition", which means users just need to unzip
the sysupgrade image. Doing the real partition layout would be overly
complex and would require the individual partitions to be shipped
as artifacts — or users to extract them out of the sysupgrade image
just for the tool to put them adjacent to each other on the eMMC
anyway.
The tool does require a copy of the preloader in order to operate,
even when it isn't flashing the preloader to the eMMC boot region.
So drop that into the bin directory as an artifact too.
Signed-off-by: David Woodhouse <dwmw2 at infradead.org>
---
target/linux/mediatek/image/gen_scatterfile.sh | 75 ++++++++++++++++++++++++++
target/linux/mediatek/image/mt7623.mk | 13 +++++
2 files changed, 88 insertions(+)
diff --git a/target/linux/mediatek/image/gen_scatterfile.sh b/target/linux/mediatek/image/gen_scatterfile.sh
new file mode 100755
index 0000000000..f23cf819b8
--- /dev/null
+++ b/target/linux/mediatek/image/gen_scatterfile.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+#
+# Copyright © 2020 David Woodhouse <dwmw2 at infradead.org>
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# Generate as "scatter file" for use with the MediaTek SP Flash tool for
+# writing images to MediaTek boards. This can be used to write images
+# even on a bricked board which has no preloader installed, or broken
+# U-Boot.
+#
+# NOTE: At the time of writing (2020-07-20), the Linux tool linked from
+# the front page of https://spflashtool.com/ is out of date and does not
+# support MT7623. The newer v5.1916 found on the download page at
+# https://spflashtool.com/download/ has been tested on UniElec U7623 and
+# Banana Pi R2 from Linux, and does work.
+#
+
+SOC=$1
+IMAGE=${2%.gz}
+PROJECT=${3%-scatter.txt}
+DEVICENAME="$4"
+
+cat <<EOF
+# OpenWrt eMMC scatter file for ${DEVICENAME}
+# For use with SP Flash Tool: https://spflashtool.com/download/
+#
+# Unzip the file system file ${PROJECT}-${IMAGE}.gz before flashing.
+# Connect the device's USB port, although it won't appear to the host yet.
+# Load this scatter file into the SP Flash Tool, select 'Format All + Download'
+# After pressing the 'Download' button, power on the board.
+# The /dev/ttyACM0 device should appear on USB and the tool should find it.
+
+- general: MTK_PLATFORM_CFG
+ info:
+ - config_version: V1.1.2
+ platform: ${SOC}
+ project: ${PROJECT}
+ storage: EMMC
+ boot_channel: MSDC_0
+ block_size: 0x20000
+
+- partition_index: SYS0
+ partition_name: PRELOADER
+ file_name: ${PROJECT}-preloader.bin
+ is_download: true
+ type: SV5_BL_BIN
+ linear_start_addr: 0x0
+ physical_start_addr: 0x0
+ partition_size: 0x40000
+ region: EMMC_BOOT_1
+ storage: HW_STORAGE_EMMC
+ boundary_check: true
+ is_reserved: false
+ operation_type: BOOTLOADERS
+ d_type: FALSE
+ reserve: 0x00
+
+- partition_index: SYS1
+ partition_name: OPENWRT
+ file_name: ${PROJECT}-${IMAGE}
+ is_download: true
+ type: NORMAL_ROM
+ linear_start_addr: 0x00000
+ physical_start_addr: 0x00000
+ partition_size: 0x4000000
+ region: EMMC_USER
+ storage: HW_STORAGE_EMMC
+ boundary_check: true
+ is_reserved: false
+ operation_type: UPDATE
+ d_type: FALSE
+ reserve: 0x00
+EOF
diff --git a/target/linux/mediatek/image/mt7623.mk b/target/linux/mediatek/image/mt7623.mk
index 4ed8cb0a69..ef14969029 100644
--- a/target/linux/mediatek/image/mt7623.mk
+++ b/target/linux/mediatek/image/mt7623.mk
@@ -1,4 +1,5 @@
KERNEL_LOADADDR := 0x80008000
+DEVICE_VARS += UBOOT_TARGET
ifneq ($(CONFIG_BANANA_PI_BOOT_PARTSIZE),)
BOOTFS_BLOCK_SIZE := 1024
@@ -25,6 +26,15 @@ define Build/banana-pi-sdcard
$(CONFIG_TARGET_ROOTFS_PARTSIZE)
endef
+define Build/preloader
+ $(CP) $(STAGING_DIR_IMAGE)/$1-preloader.bin $@
+endef
+
+define Build/scatterfile
+ ./gen_scatterfile.sh $(subst mt,MT,$(SUBTARGET)) "$1" \
+ $(subst -scatter.txt,,$(notdir $@)) "$(DEVICE_TITLE)" > $@
+endef
+
define Device/bpi_bananapi-r2
DEVICE_VENDOR := Bpi
DEVICE_MODEL := Banana Pi R2
@@ -34,6 +44,9 @@ define Device/bpi_bananapi-r2
UBOOT_TARGET := mt7623n_bpir2
IMAGES := img.gz
IMAGE/img.gz := banana-pi-sdcard | gzip | append-metadata
+ ARTIFACT/preloader.bin := preloader $$(UBOOT_TARGET)
+ ARTIFACT/scatter.txt := scatterfile $$(firstword $$(FILESYSTEMS))-$$(firstword $$(IMAGES))
+ ARTIFACTS = preloader.bin scatter.txt
SUPPORTED_DEVICES := bananapi,bpi-r2
endef
TARGET_DEVICES += bpi_bananapi-r2
More information about the lede-commits
mailing list