1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Add a directory by kernel instead of a common root, add qnap-301w and rpi4 kernel 6.1 suppport

This commit is contained in:
Ycarus (Yannick Chabanois) 2023-04-22 08:07:24 +02:00
parent e910436a7a
commit 46837ec4c0
9459 changed files with 362648 additions and 116345 deletions

View file

@ -0,0 +1,55 @@
. /lib/functions.sh
# Prepare UBI devices for OpenWrt installation
# - rootfs (mtd22)
# - remove "ubi_rootfs" volume (rootfs on stock)
# - remove "fw_hash" volume (firmware hash)
# - user_property (mtd24)
# - remove "user_property_ubi" volume (user configuration)
# - remove "extra_property" volume (gzipped syslog)
buffalo_upgrade_prepare() {
local ubi_rootdev ubi_propdev
if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
! ubi_propdev="$(nand_attach_ubi user_property)"; then
echo "failed to attach UBI volume \"rootfs\" or \"user_property\", rebooting..."
reboot -f
fi
ubirmvol /dev/$ubi_rootdev -N ubi_rootfs &> /dev/null || true
ubirmvol /dev/$ubi_rootdev -N fw_hash &> /dev/null || true
ubirmvol /dev/$ubi_propdev -N user_property_ubi &> /dev/null || true
ubirmvol /dev/$ubi_propdev -N extra_property &> /dev/null || true
}
# Re-create small dummy ubi_rootfs volume and update
# fw_hash volume to pass the checking by U-Boot
# - rootfs (mtd22)
# - re-create "ubi_rootfs" volume
# - re-create and update "fw_hash" volume
# - rootfs_recover (mtd23)
# - update "fw_hash" volume
buffalo_upgrade_optvol() {
local ubi_rootdev ubi_rcvrdev
local hashvol_root hashvol_rcvr
if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
! ubi_rcvrdev="$(nand_attach_ubi rootfs_recover)"; then
echo "failed to attach UBI volume \"rootfs\" or \"rootfs_recover\", rebooting..."
reboot -f
fi
ubimkvol /dev/$ubi_rootdev -N ubi_rootfs -S 1
ubimkvol /dev/$ubi_rootdev -N fw_hash -S 1 -t static
if ! hashvol_root="$(nand_find_volume $ubi_rootdev fw_hash)" || \
! hashvol_rcvr="$(nand_find_volume $ubi_rcvrdev fw_hash)"; then
echo "\"fw_hash\" volume in \"rootfs\" or \"rootfs_recover\" not found, rebooting..."
reboot -f
fi
echo -n "00000000000000000000000000000000" > /tmp/dummyhash.txt
ubiupdatevol /dev/$hashvol_root /tmp/dummyhash.txt
ubiupdatevol /dev/$hashvol_rcvr /tmp/dummyhash.txt
}

View file

@ -0,0 +1,83 @@
#
# Copyright (C) 2016 lede-project.org
#
# this can be used as a generic mmc upgrade script
# just add a device entry in platform.sh,
# define "kernelname" and "rootfsname" and call mmc_do_upgrade
# after the kernel and rootfs flash a loopdev (as overlay) is
# setup on top of the rootfs partition
# for the proper function a padded rootfs image is needed, basically
# append "pad-to 64k" to the image definition
# this is based on the ipq806x zyxel.sh mmc upgrade
. /lib/functions.sh
mmc_do_upgrade() {
local tar_file="$1"
local rootfs=
local kernel=
[ -z "$kernel" ] && kernel=$(find_mmc_part ${kernelname})
[ -z "$rootfs" ] && rootfs=$(find_mmc_part ${rootfsname})
[ -z "$kernel" ] && echo "Upgrade failed: kernel partition not found! Rebooting..." && reboot -f
[ -z "$rootfs" ] && echo "Upgrade failed: rootfs partition not found! Rebooting..." && reboot -f
mmc_do_flash $tar_file $kernel $rootfs
return 0
}
mmc_do_flash() {
local tar_file=$1
local kernel=$2
local rootfs=$3
# keep sure its unbound
losetup --detach-all || {
echo Failed to detach all loop devices. Skip this try.
reboot -f
}
# use the first found directory in the tar archive
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
echo "flashing kernel to $kernel"
tar xf $tar_file ${board_dir}/kernel -O >$kernel
echo "flashing rootfs to ${rootfs}"
tar xf $tar_file ${board_dir}/root -O >"${rootfs}"
# a padded rootfs is needed for overlay fs creation
local offset=$(tar xf $tar_file ${board_dir}/root -O | wc -c)
[ $offset -lt 65536 ] && {
echo Wrong size for rootfs: $offset
sleep 10
reboot -f
}
# Mount loop for rootfs_data
local loopdev="$(losetup -f)"
losetup -o $offset $loopdev $rootfs || {
echo "Failed to mount looped rootfs_data."
sleep 10
reboot -f
}
echo "Format new rootfs_data at position ${offset}."
mkfs.ext4 -F -L rootfs_data $loopdev
mkdir /tmp/new_root
mount -t ext4 $loopdev /tmp/new_root && {
echo "Saving config to rootfs_data at position ${offset}."
cp -v "$UPGRADE_BACKUP" "/tmp/new_root/$BACKUP_FILE"
umount /tmp/new_root
}
# Cleanup
losetup -d $loopdev >/dev/null 2>&1
sync
umount -a
reboot -f
}

View file

@ -0,0 +1,114 @@
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_printenv fw_setenv head'
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
xiaomi_initramfs_prepare() {
# Wipe UBI if running initramfs
[ "$(rootfs_type)" = "tmpfs" ] || return 0
local rootfs_mtdnum="$( find_mtd_index rootfs )"
if [ ! "$rootfs_mtdnum" ]; then
echo "unable to find mtd partition rootfs"
return 1
fi
local kern_mtdnum="$( find_mtd_index ubi_kernel )"
if [ ! "$kern_mtdnum" ]; then
echo "unable to find mtd partition ubi_kernel"
return 1
fi
ubidetach -m "$rootfs_mtdnum"
ubiformat /dev/mtd$rootfs_mtdnum -y
ubidetach -m "$kern_mtdnum"
ubiformat /dev/mtd$kern_mtdnum -y
}
platform_check_image() {
return 0;
}
platform_pre_upgrade() {
case "$(board_name)" in
redmi,ax6|\
xiaomi,ax3600|\
xiaomi,ax9000)
xiaomi_initramfs_prepare
;;
esac
}
platform_do_upgrade() {
case "$(board_name)" in
buffalo,wxr-5950ax12)
CI_KERN_UBIPART="rootfs"
CI_ROOT_UBIPART="user_property"
buffalo_upgrade_prepare
nand_do_flash_file "$1" || nand_do_upgrade_failed
nand_do_restore_config || nand_do_upgrade_failed
buffalo_upgrade_optvol
;;
dynalink,dl-wrx36)
nand_do_upgrade "$1"
;;
edgecore,eap102)
active="$(fw_printenv -n active)"
if [ "$active" -eq "1" ]; then
CI_UBIPART="rootfs2"
else
CI_UBIPART="rootfs1"
fi
# force altbootcmd which handles partition change in u-boot
fw_setenv bootcount 3
fw_setenv upgrade_available 1
nand_do_upgrade "$1"
;;
edimax,cax1800)
nand_do_upgrade "$1"
;;
qnap,301w)
kernelname="0:HLOS"
rootfsname="rootfs"
mmc_do_upgrade "$1"
;;
zyxel,nbg7815)
local config_mtdnum="$(find_mtd_index 0:bootconfig)"
[ -z "$config_mtdnum" ] && reboot
part_num="$(hexdump -e '1/1 "%01x|"' -n 1 -s 168 -C /dev/mtd$config_mtdnum | cut -f 1 -d "|" | head -n1)"
if [ "$part_num" -eq "0" ]; then
kernelname="0:HLOS"
rootfsname="rootfs"
mmc_do_upgrade "$1"
else
kernelname="0:HLOS_1"
rootfsname="rootfs_1"
mmc_do_upgrade "$1"
fi
;;
redmi,ax6|\
xiaomi,ax3600|\
xiaomi,ax9000)
# Make sure that UART is enabled
fw_setenv boot_wait on
fw_setenv uart_en 1
# Enforce single partition.
fw_setenv flag_boot_rootfs 0
fw_setenv flag_last_success 0
fw_setenv flag_boot_success 1
fw_setenv flag_try_sys1_failed 8
fw_setenv flag_try_sys2_failed 8
# Kernel and rootfs are placed in 2 different UBI
CI_KERN_UBIPART="ubi_kernel"
CI_ROOT_UBIPART="rootfs"
nand_do_upgrade "$1"
;;
*)
default_do_upgrade "$1"
;;
esac
}