removed base_partitions

This commit is contained in:
Miguel Fuertes committed 2025-10-04 14:27:23 +02:00
1 parent 60e55b3c53
commit 11a1d89e62
17 files changed
+250 -242

No files matched your search

+76 -50
View File
@@ -1,20 +1,22 @@
#!/usr/bin/env bash
# Prerequisites: EDL mode.
# Prerequisites: EDL mode and fastboot.
# Usage: Execute from bin/targets/XXX/YYY/ directory
# Notes:
# - Automatically detects "*-firmware.zip" in the current directory, extracts .mbn files to a temp dir, and uses them.
# - Falls back to manual directory selection if the ZIP is not found.
# Function to find file by pattern in directory
set -euo pipefail
# Find a file by pattern at a given directory depth.
find_image() {
local dir="$1"
local pattern="$2"
local file
file=$(find "$dir" -maxdepth 1 -type f -name "$pattern" 2>/dev/null | head -n 1)
if [[ -z "$file" ]]; then
file=$(find "$dir" -maxdepth 1 -type f -name "$pattern" 2>/dev/null | head -n 1 || true)
if [[ -z "${file:-}" ]]; then
echo "[-] Error: Image not found with pattern: $pattern" >&2
return 1
fi
echo "$file"
}
@@ -22,12 +24,12 @@ echo "=== OpenWrt EXT4 Flash Script ==="
echo "[*] Filesystem: EXT4 (full writable)"
echo
# OpenWrt images are in current directory
# Use current directory for images.
openwrt_dir="."
echo "[*] Using current directory: $(pwd)"
echo
# Find required OpenWrt images
# Detect required OpenWrt images.
echo "[*] Detecting OpenWrt images..."
gpt_path=$(find_image "$openwrt_dir" "*-gpt_both0.bin") || exit 1
boot_path=$(find_image "$openwrt_dir" "*-ext4-boot.img") || exit 1
@@ -37,31 +39,44 @@ echo "[+] GPT: $(basename "$gpt_path")"
echo "[+] Boot: $(basename "$boot_path")"
echo "[+] Rootfs: $(basename "$system_path")"
# Ask for firmware directory (where .mbn files are)
# Detect firmware ZIP and extract .mbn files.
echo
echo "=== Qualcomm Firmware Directory ==="
read -e -r -p "Drag the folder with .mbn files (aboot, hyp, rpm, sbl1, tz): " firmware_dir
echo "=== Firmware bundle (.zip) ==="
zip_path="$(find_image "$openwrt_dir" "*-firmware.zip" || true)"
# Clean quotes and spaces
firmware_dir="${firmware_dir//\"/}"
firmware_dir="${firmware_dir//\'/}"
firmware_dir="${firmware_dir// /}"
firmware_tmp=""
firmware_dir=""
# Validate directory exists
if [[ -z "$firmware_dir" ]]; then
echo "[-] Error: You must specify the directory with .mbn files"
if [[ -n "${zip_path:-}" ]]; then
echo "[*] Found firmware ZIP: $(basename "$zip_path")"
firmware_tmp="$(mktemp -d)"
trap 'if [[ -n "$firmware_tmp" && -d "$firmware_tmp" ]]; then rm -rf "$firmware_tmp"; fi' EXIT
echo "[*] Extracting .mbn files..."
unzip -q -j -d "$firmware_tmp" "$zip_path" "*.mbn" || {
echo "[-] Error: Failed to extract .mbn files from ZIP"
exit 1
}
firmware_dir="$firmware_tmp"
else
echo "[!] No firmware ZIP found in the current directory"
echo "=== Qualcomm Firmware Directory (fallback) ==="
read -e -r -p "Drag the folder with .mbn files (aboot, hyp, rpm, sbl1, tz): " firmware_dir
# Normalize quotes and spaces (useful for drag-and-drop from GUI).
firmware_dir="${firmware_dir//\"/}"
firmware_dir="${firmware_dir//\'/}"
firmware_dir="${firmware_dir// /}"
fi
# Validate firmware directory.
if [[ -z "$firmware_dir" || ! -d "$firmware_dir" ]]; then
echo "[-] Error: Invalid firmware directory: $firmware_dir"
exit 1
fi
if [[ ! -d "$firmware_dir" ]]; then
echo "[-] Error: Directory not found: $firmware_dir"
exit 1
fi
echo "[*] Searching for firmware in: $firmware_dir"
echo "[*] Using firmware directory: $firmware_dir"
echo
# Check for firmware partitions (.mbn files)
# Verify required .mbn files.
echo "[*] Verifying Qualcomm firmware partitions..."
missing_mbn=false
for part in aboot hyp rpm sbl1 tz; do
@@ -73,14 +88,14 @@ for part in aboot hyp rpm sbl1 tz; do
fi
done
if [ "$missing_mbn" = true ]; then
if [[ "$missing_mbn" == true ]]; then
echo
echo "[-] ERROR: Missing required .mbn files for flashing."
echo "[!] These files must be extracted from the original Android firmware."
echo "[!] Place them in: $firmware_dir"
echo "[!] Ensure ZIP extraction succeeded or provide a correct directory."
exit 1
fi
# Confirm before flashing.
echo
read -p "Continue with flashing? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
@@ -90,60 +105,71 @@ fi
mkdir -p saved
# Backup important partitions
# Backup critical partitions via EDL.
echo
echo "=== Partition Backup ==="
echo "=== Partition Backup (EDL) ==="
for n in fsc fsg modemst1 modemst2 modem persist sec; do
echo "[*] Backing up partition $n ..."
edl r "$n" "saved/$n.bin" || { echo "[-] Error backing up $n"; exit 1; }
done
# Install aboot
# Flash aboot via EDL to get a known-good aboot.
echo
echo "=== Flashing Partitions ==="
echo "=== Flashing Partitions (EDL) ==="
echo "[*] Flashing aboot via EDL..."
edl w aboot "$firmware_dir/aboot.mbn" || { echo "[-] Error flashing aboot"; exit 1; }
# Reboot to fastboot
# Reboot to fastboot using EDL commands.
echo "[*] Rebooting to fastboot..."
edl e boot || { echo "[-] Error rebooting to fastboot"; exit 1; }
edl reset || { echo "[-] Error resetting device"; exit 1; }
# Wait for fastboot mode
echo "[*] Waiting for fastboot mode (5 seconds)..."
sleep 5
# Wait for fastboot to come up.
echo "[*] Waiting for fastboot mode (up to 10s)..."
for i in {1..10}; do
if fastboot devices | grep -qE "fastboot$"; then
echo "[+] Fastboot device detected"
break
fi
sleep 1
if [[ $i -eq 10 ]]; then
echo "[-] Error: Fastboot device not detected"
exit 1
fi
done
# Flash firmware
# Flash GPT and firmware via fastboot.
echo
echo "=== Flashing partitions via fastboot ==="
echo "=== Flashing partitions (fastboot) ==="
echo "[*] Flashing GPT..."
fastboot flash partition "$gpt_path" || { echo "[-] Error flashing partition"; exit 1; }
echo "[*] Flashing firmware..."
echo "[*] Flashing firmware (.mbn files)..."
fastboot flash aboot "$firmware_dir/aboot.mbn" || { echo "[-] Error flashing aboot"; exit 1; }
fastboot flash hyp "$firmware_dir/hyp.mbn" || { echo "[-] Error flashing hyp"; exit 1; }
fastboot flash rpm "$firmware_dir/rpm.mbn" || { echo "[-] Error flashing rpm"; exit 1; }
fastboot flash sbl1 "$firmware_dir/sbl1.mbn" || { echo "[-] Error flashing sbl1"; exit 1; }
fastboot flash tz "$firmware_dir/tz.mbn" || { echo "[-] Error flashing tz"; exit 1; }
fastboot flash hyp "$firmware_dir/hyp.mbn" || { echo "[-] Error flashing hyp"; exit 1; }
fastboot flash rpm "$firmware_dir/rpm.mbn" || { echo "[-] Error flashing rpm"; exit 1; }
fastboot flash sbl1 "$firmware_dir/sbl1.mbn" || { echo "[-] Error flashing sbl1"; exit 1; }
fastboot flash tz "$firmware_dir/tz.mbn" || { echo "[-] Error flashing tz"; exit 1; }
echo "[*] Flashing OpenWrt..."
fastboot flash boot "$boot_path" || { echo "[-] Error flashing boot"; exit 1; }
echo "[*] Flashing OpenWrt images..."
fastboot flash boot "$boot_path" || { echo "[-] Error flashing boot"; exit 1; }
fastboot flash rootfs "$system_path" || { echo "[-] Error flashing rootfs"; exit 1; }
# Reboot back to EDL to restore radio-cal data partitions.
echo "[*] Rebooting to EDL mode..."
fastboot oem reboot-edl || { echo "[-] Error rebooting to EDL"; exit 1; }
# Wait for EDL mode
# Small wait for EDL to be available.
echo "[*] Waiting for EDL mode (3 seconds)..."
sleep 3
# Restore original partitions
# Restore backed-up partitions via EDL.
echo
echo "=== Partition Restoration ==="
echo "=== Partition Restoration (EDL) ==="
for n in fsc fsg modemst1 modemst2 modem persist sec; do
echo "[*] Restoring partition $n ..."
edl w "$n" "saved/$n.bin" || { echo "[-] Error restoring $n"; exit 1; }
done
echo
echo "[+] Process completed successfully"
echo "[+] Process completed successfully"
+158
View File
@@ -0,0 +1,158 @@
#!/bin/bash
# Build firmware bundle: compiles qhypstub (AArch64 asm) and lk2nd (ARM), signs them, and packs a ZIP.
# Works inside OpenWrt build by restoring implicit make rules only for qhypstub and using detected toolchains.
set -e
OUT_FILE="${1:-uz801v3-firmware.zip}"
# Respect OpenWrt-provided TMPDIR if present; otherwise create a private one and clean up on exit.
CLEANUP_DIR=""
if [ -z "$TMPDIR" ]; then
TMPDIR="$(mktemp -d)"
CLEANUP_DIR="$TMPDIR"
fi
trap 'if [ -n "$CLEANUP_DIR" ]; then rm -rf "$CLEANUP_DIR"; fi' EXIT
# Reusable working directories under TMPDIR (OpenWrt maps TMPDIR to openwrt/tmp/)
BUILDDIR="$TMPDIR/msm8916-firmware-build"
mkdir -p "$BUILDDIR"
# Detect OpenWrt toolchain (preferred) and fall back to host tools if necessary.
# Populate AARCH64_* for qhypstub and ARM_CROSS for lk2nd.
if [ -n "$STAGING_DIR" ]; then
# Try to locate OpenWrt AArch64 toolchain (musl or non-musl prefix)
TOOLCHAIN_DIR="$(find "$STAGING_DIR/../toolchain-"* -maxdepth 0 -type d 2>/dev/null | head -1 || true)"
if [ -n "$TOOLCHAIN_DIR" ] && [ -d "$TOOLCHAIN_DIR/bin" ]; then
export PATH="$TOOLCHAIN_DIR/bin:$PATH"
AARCH64_PREFIX="$(ls "$TOOLCHAIN_DIR/bin/"aarch64-openwrt-linux-musl-gcc "$TOOLCHAIN_DIR/bin/"aarch64-openwrt-linux-gcc 2>/dev/null | head -1 | xargs -r basename | sed 's/-gcc$//' || true)"
if [ -n "$AARCH64_PREFIX" ]; then
AARCH64_CROSS="${AARCH64_PREFIX}-"
AARCH64_CC="${AARCH64_PREFIX}-gcc"
AARCH64_AS="${AARCH64_PREFIX}-as"
AARCH64_LD="${AARCH64_PREFIX}-ld"
AARCH64_AR="${AARCH64_PREFIX}-ar"
AARCH64_OBJCOPY="${AARCH64_PREFIX}-objcopy"
fi
fi
# Add OpenWrt host tools (may contain arm-none-eabi-* if installed there)
if [ -d "$STAGING_DIR/../host/bin" ]; then
export PATH="$STAGING_DIR/../host/bin:$PATH"
fi
fi
# Reasonable defaults if detection above was not conclusive.
: "${AARCH64_CROSS:=aarch64-openwrt-linux-}"
: "${AARCH64_CC:=aarch64-openwrt-linux-gcc}"
: "${AARCH64_AS:=aarch64-openwrt-linux-as}"
: "${AARCH64_LD:=aarch64-openwrt-linux-ld}"
: "${AARCH64_AR:=aarch64-openwrt-linux-ar}"
: "${AARCH64_OBJCOPY:=aarch64-openwrt-linux-objcopy}"
: "${ARM_CROSS:=arm-none-eabi-}"
# Sanity checks with clear logs.
echo "[+] Checking toolchains..."
if ! command -v "${AARCH64_CC}" >/dev/null 2>&1; then
echo "[!] Error: ${AARCH64_CC} not found in PATH"
exit 1
fi
if ! command -v "${AARCH64_AS}" >/dev/null 2>&1; then
echo "[!] Error: ${AARCH64_AS} not found in PATH"
exit 1
fi
if ! command -v "${ARM_CROSS}gcc" >/dev/null 2>&1; then
echo "[!] Error: ${ARM_CROSS}gcc not found in PATH"
exit 1
fi
echo "[+] Found aarch64 toolchain: $(command -v ${AARCH64_CC})"
echo "[+] Found aarch64 assembler: $(command -v ${AARCH64_AS})"
echo "[+] Found arm toolchain: $(command -v ${ARM_CROSS}gcc)"
# Clone sources (idempotent; reuse if already present to speed up rebuilds).
for repo in qhypstub:qhypstub lk2nd:lk2nd qtestsign:qtestsign; do
name="${repo%:*}"
dir="${repo#*:}"
if [ ! -d "$BUILDDIR/$dir/.git" ]; then
echo "[+] Cloning $name..."
git clone "https://github.com/msm8916-mainline/$name.git" "$BUILDDIR/$dir"
else
echo "[+] Reusing existing $name..."
fi
done
# Build qhypstub (pure AArch64 assembly).
# OpenWrt disables GNU make implicit rules by default (-rR), so clear MAKEFLAGS only for this sub-make.
echo "[+] Compiling qhypstub..."
if [ ! -f "$BUILDDIR/qhypstub/qhypstub.elf" ]; then
env -u MAKEFLAGS MAKEFLAGS= \
make -C "$BUILDDIR/qhypstub" clean \
CROSS_COMPILE="$AARCH64_CROSS" \
CC="$AARCH64_CC" AS="$AARCH64_AS" LD="$AARCH64_LD" AR="$AARCH64_AR" OBJCOPY="$AARCH64_OBJCOPY" || true
env -u MAKEFLAGS MAKEFLAGS= \
make -C "$BUILDDIR/qhypstub" \
CROSS_COMPILE="$AARCH64_CROSS" \
CC="$AARCH64_CC" AS="$AARCH64_AS" LD="$AARCH64_LD" AR="$AARCH64_AR" OBJCOPY="$AARCH64_OBJCOPY"
else
echo "[+] qhypstub already compiled"
fi
# Patch (idempotent) and build lk2nd using ARM EABI toolchain.
echo "[+] Compiling lk2nd..."
if [ ! -f "$BUILDDIR/lk2nd/build-lk1st-msm8916/emmc_appsboot.mbn" ]; then
(
cd "$BUILDDIR/lk2nd"
grep -qxF 'DEFINES += USE_TARGET_HS200_CAPS=1' project/lk1st-msm8916.mk || \
echo 'DEFINES += USE_TARGET_HS200_CAPS=1' >> project/lk1st-msm8916.mk
make clean || true
make \
LK2ND_BUNDLE_DTB="msm8916-512mb-mtp.dtb" \
LK2ND_COMPATIBLE="yiming,uz801-v3" \
TOOLCHAIN_PREFIX="$ARM_CROSS" \
lk1st-msm8916
)
else
echo "[+] lk2nd already compiled"
fi
# Prepare output area.
OUTDIR="$BUILDDIR/output"
mkdir -p "$OUTDIR"
# Download base Qualcomm bootloader bundle if missing (rpm/sbl1/tz).
echo "[+] Downloading Qualcomm firmware..."
FWZIP="$BUILDDIR/dragonboard-410c-bootloader-emmc-linux-176.zip"
if [ ! -f "$FWZIP" ]; then
wget -q --show-progress -O "$FWZIP" \
"https://github.com/Mio-sha512/openstick-stuff/raw/refs/heads/main/builder-stuff/dragonboard-410c-bootloader-emmc-linux-176.zip"
fi
# Extract required files only.
unzip -o -j -d "$OUTDIR" "$FWZIP" \
dragonboard-410c-bootloader-emmc-linux-176/rpm.mbn \
dragonboard-410c-bootloader-emmc-linux-176/sbl1.mbn \
dragonboard-410c-bootloader-emmc-linux-176/tz.mbn
# Sign hyp (qhypstub) and aboot (lk2nd) using qtestsign.
echo "[+] Signing binaries..."
python3 "$BUILDDIR/qtestsign/qtestsign.py" hyp \
"$BUILDDIR/qhypstub/qhypstub.elf" -o "$OUTDIR/hyp.mbn"
python3 "$BUILDDIR/qtestsign/qtestsign.py" aboot \
"$BUILDDIR/lk2nd/build-lk1st-msm8916/emmc_appsboot.mbn" -o "$OUTDIR/aboot.mbn"
# Pack final ZIP with all MBN parts.
echo "[+] Creating firmware package..."
(
cd "$OUTDIR"
zip -9 "$(basename "$OUT_FILE")" *.mbn
)
# Place result in the requested path (create directory if needed).
DEST_DIR="$(dirname "$OUT_FILE")"
mkdir -p "$DEST_DIR"
mv -f "$OUTDIR/$(basename "$OUT_FILE")" "$OUT_FILE"
echo "[+] Build completed successfully"
echo "[+] Output file: $OUT_FILE"
ls -lh "$OUT_FILE"
+8 -2
View File
@@ -12,6 +12,11 @@ define Build/install-flasher
chmod +x $@
endef
define Build/generate-firmware
chmod +x $(TOPDIR)/target/linux/$(BOARD)/image/generate_firmware.sh
$(TOPDIR)/target/linux/$(BOARD)/image/generate_firmware.sh $@
endef
define Device/msm8916
SOC := msm8916
CMDLINE := "earlycon console=tty0 console=ttyMSM0,115200 root=/dev/mmcblk0p14 rootwait"
@@ -25,9 +30,10 @@ define Device/yiming-uz801v3
DEVICE_MODEL := uz801v3
DEVICE_PACKAGES := uz801-tweaks wpad-basic-wolfssl msm-firmware-dumper rmtfs rootfs-resizer msm8916-usb-gadget
IMAGE/system.img := append-rootfs | append-metadata | sparse-img
ARTIFACTS := gpt_both0.bin flash.sh
ARTIFACT/gpt_both0.bin := generate-gpt
ARTIFACTS := ext4-gpt_both0.bin flash.sh firmware.zip
ARTIFACT/ext4-gpt_both0.bin := generate-gpt
ARTIFACT/flash.sh := install-flasher
ARTIFACT/firmware.zip := generate-firmware
endef
TARGET_DEVICES += yiming-uz801v3