most likely working!

This commit is contained in:
Miguel Fuertes committed 2025-09-29 22:21:07 +02:00
1 parent c38543d597
commit 22c14fd397
10 files changed
+78 -283

No files matched your search

+2 -2
View File
@@ -27,7 +27,7 @@ read_path() {
mkdir -p saved
# Backup important partitions
for n in fsc fsg modemst1 modemst2; do
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
@@ -60,7 +60,7 @@ echo "Rebooting to EDL mode..."
fastboot oem reboot-edl || { echo "Error rebooting to EDL"; exit 1; }
# Restore original partitions
for n in fsc fsg modemst1 modemst2; do
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
+3 -4
View File
@@ -11,7 +11,7 @@ CONFIG_MODEMMANAGER_WITH_MBIM=y
CONFIG_MODEMMANAGER_WITH_NETIFD=y
CONFIG_MODEMMANAGER_WITH_QMI=y
CONFIG_MODEMMANAGER_WITH_QRTR=y
CONFIG_PACKAGE_bash=y
CONFIG_PACKAGE_blkid=y
CONFIG_PACKAGE_cgi-io=y
CONFIG_PACKAGE_coreutils=y
CONFIG_PACKAGE_coreutils-dd=y
@@ -46,14 +46,14 @@ CONFIG_PACKAGE_libattr=y
CONFIG_PACKAGE_libdbus=y
CONFIG_PACKAGE_libexpat=y
CONFIG_PACKAGE_libffi=y
CONFIG_PACKAGE_libiwinfo=y
CONFIG_PACKAGE_libiwinfo-data=y
CONFIG_PACKAGE_liblucihttp=y
CONFIG_PACKAGE_liblucihttp-ucode=y
CONFIG_PACKAGE_libmbim=y
CONFIG_PACKAGE_libncurses=y
CONFIG_PACKAGE_libpcre2=y
CONFIG_PACKAGE_libqmi=y
CONFIG_PACKAGE_libqrtr-glib=y
CONFIG_PACKAGE_libreadline=y
CONFIG_PACKAGE_luci=y
CONFIG_PACKAGE_luci-app-firewall=y
CONFIG_PACKAGE_luci-app-package-manager=y
@@ -81,7 +81,6 @@ CONFIG_PACKAGE_rpcd-mod-iwinfo=y
CONFIG_PACKAGE_rpcd-mod-luci=y
CONFIG_PACKAGE_rpcd-mod-rrdns=y
CONFIG_PACKAGE_rpcd-mod-ucode=y
CONFIG_PACKAGE_terminfo=y
CONFIG_PACKAGE_ucode-mod-html=y
CONFIG_PACKAGE_ucode-mod-log=y
CONFIG_PACKAGE_ucode-mod-math=y
+1 -1
View File
@@ -11,7 +11,7 @@ define Device/yiming-uz801v3
$(Device/msm8916)
DEVICE_VENDOR := YiMing
DEVICE_MODEL := uz801v3
DEVICE_PACKAGES := uz801-tweaks wpad-basic-wolfssl qcom-msm8916-uz801-wcnss-firmware qcom-msm8916-wcnss-uz801-nv qcom-msm8916-modem-uz801-firmware
DEVICE_PACKAGES := uz801-tweaks wpad-basic-wolfssl msm-firmware-loader
endef
TARGET_DEVICES += yiming-uz801v3
+8 -5
View File
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=msm-firmware-loader
PKG_VERSION:=1.0
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_PROTO:=git
@@ -17,16 +17,15 @@ define Package/$(PKG_NAME)
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Loads firmware blobs from firmware partitions on qcom devices.
DEPENDS:=+bash
DEPENDS:=+bash +kmod-fs-ext4 +e2fsprogs +kmod-fs-vfat +kmod-nls-cp437 +kmod-nls-iso8859-1
endef
define Build/Configure
endef
define Build/Compile
@echo "" >> $(PKG_BUILD_DIR)/msm-firmware-loader.sh
@echo "# Custom remoteproc restart after firmware path is set:" >> $(PKG_BUILD_DIR)/msm-firmware-loader.sh
cat ./files/remoteproc-restart-extra.addon >> $(PKG_BUILD_DIR)/msm-firmware-loader.sh
# Suppress dirname error by redirecting stderr
sed -i 's|xargs dirname|xargs dirname 2>/dev/null || echo ""|' $(PKG_BUILD_DIR)/msm-firmware-loader.sh
endef
define Package/$(PKG_NAME)/install
@@ -35,6 +34,10 @@ define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/msm-firmware-loader.sh $(1)/usr/sbin/msm-firmware-loader
$(INSTALL_BIN) ./files/msm-firmware-post.sh $(1)/usr/sbin/msm-firmware-post
$(INSTALL_DIR) $(1)/lib/firmware
$(INSTALL_BIN) ./files/mcfg_sw.mbn $(1)/lib/firmware/MCFG_SW.MBN
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
Binary file not shown.
@@ -6,11 +6,26 @@ STOP=90
NAME=msm-firmware-loader
PROG=/usr/sbin/msm-firmware-loader
POST_SCRIPT=/usr/sbin/msm-firmware-post
start_service() {
# Main firmware loader
procd_open_instance loader
procd_set_param command "$PROG"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
# Post-firmware tasks (se ejecuta DESPUÉS del firmware loader)
procd_open_instance post_tasks
procd_set_param command "$POST_SCRIPT"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
stop_service() {
logger -t msm-firmware-loader "Stopping firmware loader service"
echo stop > /sys/class/remoteproc/remoteproc0/state 2>/dev/null || true
echo stop > /sys/class/remoteproc/remoteproc1/state 2>/dev/null || true
}
@@ -0,0 +1,48 @@
#!/bin/bash
logger -t msm-firmware-loader "Starting post-firmware tasks"
# Wait a bit for firmware path to be fully processed
sleep 5
# Link MCFG from /lib/firmware to firmware search path (BEFORE restart)
FIRMWARE_PATH=$(cat /sys/module/firmware_class/parameters/path)
ln -sf /lib/firmware/MCFG_SW.MBN "$FIRMWARE_PATH/MCFG_SW.MBN" 2>/dev/null || true
logger -t msm-firmware-loader "Linked MCFG_SW.MBN to firmware search path"
# Check remoteproc states
MODEM_STATE=$(cat /sys/class/remoteproc/remoteproc0/state 2>/dev/null || echo "offline")
WIFI_STATE=$(cat /sys/class/remoteproc/remoteproc1/state 2>/dev/null || echo "offline")
logger -t msm-firmware-loader "Current states - Modem: $MODEM_STATE, WiFi: $WIFI_STATE"
# Only restart modem if it's not running
if [ "$MODEM_STATE" != "running" ]; then
logger -t msm-firmware-loader "Restarting modem remoteproc"
echo stop > /sys/class/remoteproc/remoteproc0/state 2>/dev/null || true
sleep 2
echo start > /sys/class/remoteproc/remoteproc0/state 2>/dev/null || true
else
logger -t msm-firmware-loader "Modem already running, skipping restart"
fi
# Only restart WiFi if it's not running
if [ "$WIFI_STATE" != "running" ]; then
logger -t msm-firmware-loader "Restarting WiFi remoteproc"
echo stop > /sys/class/remoteproc/remoteproc1/state 2>/dev/null || true
sleep 2
echo start > /sys/class/remoteproc/remoteproc1/state 2>/dev/null || true
else
logger -t msm-firmware-loader "WiFi already running, skipping restart"
fi
logger -t msm-firmware-loader "Remoteproc restart completed"
# Wait for stability
sleep 3
# Reload WiFi service so it detects the new firmware
logger -t msm-firmware-loader "Reloading WiFi service"
wifi reload 2>/dev/null || true
logger -t msm-firmware-loader "All post-firmware tasks completed"
@@ -1,13 +0,0 @@
# Wait a bit for firmware path to be fully processed
sleep 3
# Now restart remoteproc so it can find the new firmware
logger -t msm-firmware-loader "Firmware path set, restarting remoteproc devices"
echo stop > /sys/class/remoteproc/remoteproc0/state 2>/dev/null || true
echo stop > /sys/class/remoteproc/remoteproc1/state 2>/dev/null || true
sleep 2
echo start > /sys/class/remoteproc/remoteproc0/state 2>/dev/null || true
echo start > /sys/class/remoteproc/remoteproc1/state 2>/dev/null || true
logger -t msm-firmware-loader "Remoteproc restart completed"
@@ -1,258 +0,0 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
#
# This script is responsible for loading firmware blobs from firmware
# partitions on qcom devices. It will make a dir in tmp, mount all of the
# interesting partitions there and then symlink blobs to a single dir that can
# be then provided to the kernel. (At this time only single additional
# directory can be provided)
#
# This script attempts to load everything at runtime and be as generic
# as possible between the target devices: It should allow a single rootfs
# to be used on multiple different devices as long as all the blobs
# are present on dedicated partitions.
# (Usually the case, Samsung devices ship all blobs, other devices may miss
# venus but that still allows for WiFi and modem to work)
#
# Get the slot suffix for A/B devices.
# If qbootctl is available query the active slot using that, otherwise rely on
# the kernel cmdline to contain the slot suffix.
# On non-A/B devices the return value will be empty.
# https://source.android.com/docs/core/architecture/bootloader/updating#slots
ab_get_slot() {
if command -v qbootctl > /dev/null; then
ab_slot_suffix=$(qbootctl -a | grep -o 'Active slot: _[ab]' | cut -d ":" -f2 | xargs) || :
else
ab_slot_suffix=$(grep -o 'androidboot\.slot_suffix=..' /proc/cmdline | cut -d "=" -f2) || :
fi
echo "$ab_slot_suffix"
}
# Configurations:
# List of partitions to be mounted and inspected for blobs.
FW_PARTITIONS="
apnhlos
bluetooth$(ab_get_slot)
dsp$(ab_get_slot)
modem$(ab_get_slot)
persist
vendor$(ab_get_slot)
RADIO
"
# List of partitions to mount dynamic partitions from.
SUPER_PARTITIONS="
super
system
"
# Base directory to be used to unfold the partitions into.
BASEDIR="/run/msm-firmware-loader"
# Preparations:
# This script is intended to run before udev. This means that writeable fs
# may not be available yet. Since this script only creates symlinks, it
# uses tmpfs to work around the early-run limitations as well as to reduce
# disk wear slightly.
mount -o mode=755,nodev,noexec,nosuid -t tmpfs none "$BASEDIR"
mkdir -p "$BASEDIR/mnt"
mkdir -p "$BASEDIR/target"
# Scanning and mounting partitions we're interested in:
# Modern android devices use dynamic partitions for the system.
# To gather firmware from such partitions, search for a "super"
# or "system" partition, and if one is present, map it and try
# to locate firmware partitions of interest inside.
if command -v make-dynpart-mappings > /dev/null
then
for part in /sys/block/mmcblk*/mmcblk*p* /sys/block/sd*/sd*
do
if ! [ -e "$part" ]; then continue; fi;
DEVNAME="$(grep DEVNAME "$part"/uevent | sed 's/DEVNAME=//g')"
PARTNAME="$(grep PARTNAME "$part"/uevent | sed 's/PARTNAME=//g')"
if [ -z "${SUPER_PARTITIONS##*"$PARTNAME"*}" ] && [ -n "$PARTNAME" ]
then
# system is for retrofit targets, not all devices may be
# retrofit, in which case make-dynpart-mappings will fail.
if ! make-dynpart-mappings "/dev/$DEVNAME"; then continue; fi;
for dynpart in /dev/mapper/*
do
PARTNAME="$(basename "$dynpart")"
if [ -z "${FW_PARTITIONS##*"$PARTNAME"*}" ] && [ -n "$PARTNAME" ]
then
mkdir -p "$BASEDIR/mnt/$PARTNAME"
mount -o ro,nodev,noexec,nosuid \
"$dynpart" "$BASEDIR/mnt/$PARTNAME"
fi
done
break
fi
done
fi
# /dev/disk/by-partlabel symlinks don't exist yet, scan sysfs for names instead
for part in /sys/block/mmcblk*/mmcblk*p* /sys/block/sd*/sd*
do
if ! [ -e "$part" ]; then continue; fi;
DEVNAME="$(grep DEVNAME "$part"/uevent | sed 's/DEVNAME=//g')"
PARTNAME="$(grep PARTNAME "$part"/uevent | sed 's/PARTNAME=//g')"
if [ -z "${FW_PARTITIONS##*"$PARTNAME"*}" ] && [ -n "$PARTNAME" ] && [ ! -d "$BASEDIR/mnt/$PARTNAME" ]
then
mkdir -p "$BASEDIR/mnt/$PARTNAME"
mount -o ro,nodev,noexec,nosuid \
"/dev/$DEVNAME" "$BASEDIR/mnt/$PARTNAME"
fi
done
# Linking blobs from all partitions:
# Backup the preselected path, link all of the installed blobs.
# This is needed for devices that require blobs either not present
# on the partitions (e.g. venus on many msm8916 devices) or if
# the device has secure-boot disabled and can run newer blobs.
EXTRA_PATH="$(cat /sys/module/firmware_class/parameters/path)"
if [ -d "$EXTRA_PATH" ]
then
for blob in "$EXTRA_PATH"/*
do
if ! [ -e "$blob" ]; then break; fi
ln -s "$blob" "$BASEDIR/target/$(basename "$blob")"
done
fi
# Scan through mounted partitions and symlink all of the blobs.
# This loop ignores blobs with names already present in the
# target to allow preinstalled blobs to override ones in the partitions.
for blob in "$BASEDIR"/mnt/*/image/* "$BASEDIR"/mnt/*/firmware/*
do
if ! [ -e "$blob" ]; then continue; fi;
DIR="$(dirname "$blob")"
BLOBBASE="${blob##*/}"
BLOBBASE="${BLOBBASE%.*}"
# Skip blob prefix if it's already present.
for prefix in "$BASEDIR/target/$BLOBBASE."*
do
if [ -e "$prefix" ]; then continue 2; fi
done
for part in "$DIR"/"$BLOBBASE"*
do
if [ -f "$part" ]
then
ln -s "$part" "$BASEDIR/target/$(basename "$part")"
fi
done
done
# Check for sns.reg in persist partition
if [ -f "$BASEDIR"/mnt/persist/sensors/sns.reg ]
then
mkdir -p "$BASEDIR/target/qcom/sensors"
ln -s "$BASEDIR"/mnt/persist/sensors/sns.reg "$BASEDIR"/target/qcom/sensors/sns.reg
fi
# Check WCNSS_qcom_wlan_nv.bin in persist partition
if [ -f "$BASEDIR"/mnt/persist/WCNSS_qcom_wlan_nv.bin ]
then
ln -s "$BASEDIR"/mnt/persist/WCNSS_qcom_wlan_nv.bin "$BASEDIR"/target/WCNSS_qcom_wlan_nv.bin
fi
# Fixup the directory structure:
# venus (video encoder/decoder) blobs are expected to be in a subdir.
# Re-link the blobs if the venus firmware wasn't already preinstalled.
# Different platforms expect firmware in different subdirs
# (as in linux-firmware-qcom) so the venus dir is duplicated multiple times
# under possible names for the script to be generic without complex detection.
if [ -f "$BASEDIR/target/venus.mdt" ] && ! [ -d "$BASEDIR/target/qcom/venus-x" ]
then
mkdir -p "$BASEDIR/target/qcom/venus-x"
for part in "$BASEDIR"/target/venus.*
do
ln -s "$part" "$BASEDIR/target/qcom/venus-x/$(basename "$part")"
done
fi
VENUS_DIRS="
venus-1.8
venus-3.0
venus-4.2
venus-4.4
venus-5.2
venus-5.4
vpu-1.0
vpu-2.0
"
for vdir in $VENUS_DIRS
do
if ! [ -d "$BASEDIR/target/qcom/$vdir" ] && [ -f "$BASEDIR/target/venus.mdt" ]
then
ln -s "$BASEDIR/target/qcom/venus-x" \
"$BASEDIR/target/qcom/$vdir"
fi
done
# WCNSS_qcom_wlan_nv.bin needs to be relocated too
if [ -h "$BASEDIR"/target/WCNSS_qcom_wlan_nv.bin ]
then
if ! [ -f "$BASEDIR"/target/wlan/prima/WCNSS_qcom_wlan_nv.bin ]
then
mkdir -p "$BASEDIR"/target/wlan/prima
ln -s "$BASEDIR"/target/WCNSS_qcom_wlan_nv.bin "$BASEDIR"/target/wlan/prima/
fi
fi
# Devices with ath10k wcn3990 wifi/bt have bluetooth firmware on a separate
# "bluetooth" partition. Files from it need to be placed into qca/ subdir.
# Check if bluetooth partition was mounted, and if so, link files into qca/
if [ -d "$BASEDIR/mnt/bluetooth$(ab_get_slot)" ]
then
mkdir -p "$BASEDIR"/target/qca
for btblob in "$BASEDIR/mnt/bluetooth$(ab_get_slot)/image"/*
do
ln -s "$btblob" "$BASEDIR"/target/qca/
done
fi
# Some kernel versions expect .mbn instead of legacy .mdt
# Symlink these files together, the kernel can autodetect the type.
find "$BASEDIR"/target/ \
-name '*.mdt' \
-exec sh -c 'ln -s $0 ${0%.mdt}.mbn' {} \;
# It's customary to define device-model-specific firmware prefix in
# devicetree to separate similarly named but differently signed blobs
# between different devices. This script handles those by guessing
# the common prefix and symlinking the firmware tree to it, which
# relies on following implications:
# - The device uses the same firmware prefix for all blobs;
# - All blob file names in the prefix are same as in downstream,
# with the exception that .mbn instead of legacy .mdt may be used
FIRMWARE_PREFIX=$(find /sys/firmware/devicetree -name "firmware-name" | head -n1 | xargs cat | xargs dirname)
if [ -n "$FIRMWARE_PREFIX" ]
then
mkdir -p "$BASEDIR/target/$(dirname "$FIRMWARE_PREFIX")"
ln -s "$BASEDIR/target" "$BASEDIR/target/$FIRMWARE_PREFIX"
fi
# Set the new custom firmware path:
printf "%s" "$BASEDIR/target" > /sys/module/firmware_class/parameters/path
+1
View File
@@ -30,6 +30,7 @@ Docker is required!
cd devenv
docker compose run --rm builder # This will open bash inside a build environment
cp /repo/diffconfig .config # Copies the config on to the working folder
echo "# CONFIG_SIGNED_PACKAGES is not set" >> .config # Optional: Disable APK signature verification
make defconfig
make -j$(nproc)
```