1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00
This commit is contained in:
suyuan 2021-11-03 18:56:07 +08:00
parent 716345e605
commit 3631646068
3 changed files with 111 additions and 120 deletions

View file

@ -1,106 +0,0 @@
# The U-Boot loader of the OpenMesh devices requires image sizes and
# checksums to be provided in the U-Boot environment.
# The OpenMesh devices come with 2 main partitions - while one is active
# sysupgrade will flash the other. The boot order is changed to boot the
# newly flashed partition. If the new partition can't be booted due to
# upgrade failures the previously used partition is loaded.
platform_do_upgrade_openmesh() {
local tar_file="$1"
local restore_backup
local primary_kernel_mtd
local setenv_script="/tmp/fw_env_upgrade"
local kernel_mtd="$(find_mtd_index $PART_NAME)"
local kernel_offset="$(cat /sys/class/mtd/mtd${kernel_mtd}/offset)"
local total_size="$(cat /sys/class/mtd/mtd${kernel_mtd}/size)"
# detect to which flash region the new image is written to.
#
# 1. check what is the mtd index for the first flash region on this
# device
# 2. check if the target partition ("inactive") has the mtd index of
# the first flash region
#
# - when it is: the new bootseq will be 1,2 and the first region is
# modified
# - when it isnt: bootseq will be 2,1 and the second region is
# modified
#
# The detection has to be done via the hardcoded mtd partition because
# the current boot might be done with the fallback region. Let us
# assume that the current bootseq is 1,2. The bootloader detected that
# the image in flash region 1 is corrupt and thus switches to flash
# region 2. The bootseq in the u-boot-env is now still the same and
# the sysupgrade code can now only rely on the actual mtd indexes and
# not the bootseq variable to detect the currently booted flash
# region/image.
#
# In the above example, an implementation which uses bootseq ("1,2") to
# detect the currently booted image would assume that region 1 is booted
# and then overwrite the variables for the wrong flash region (aka the
# one which isn't modified). This could result in a device which doesn't
# boot anymore to Linux until it was reflashed with ap51-flash.
local next_boot_part="1"
case "$(board_name)" in
openmesh,a42)
primary_kernel_mtd=8
;;
openmesh,a62)
primary_kernel_mtd=10
;;
*)
echo "failed to detect primary kernel mtd partition for board"
return 1
;;
esac
[ "$kernel_mtd" = "$primary_kernel_mtd" ] || next_boot_part="2"
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
board_dir=${board_dir%/}
local kernel_length=$(tar xf $tar_file ${board_dir}/kernel -O | wc -c)
local rootfs_length=$(tar xf $tar_file ${board_dir}/root -O | wc -c)
# rootfs without EOF marker
rootfs_length=$((rootfs_length-4))
local kernel_md5=$(tar xf $tar_file ${board_dir}/kernel -O | md5sum); kernel_md5="${kernel_md5%% *}"
# md5 checksum of rootfs with EOF marker
local rootfs_md5=$(tar xf $tar_file ${board_dir}/root -O | dd bs=1 count=$rootfs_length | md5sum); rootfs_md5="${rootfs_md5%% *}"
#
# add tar support to get_image() to use default_do_upgrade() instead?
#
# take care of restoring a saved config
[ -n "$UPGRADE_BACKUP" ] && restore_backup="${MTD_CONFIG_ARGS} -j ${UPGRADE_BACKUP}"
mtd -q erase inactive
tar xf $tar_file ${board_dir}/root -O | mtd -n -p $kernel_length $restore_backup write - $PART_NAME
tar xf $tar_file ${board_dir}/kernel -O | mtd -n write - $PART_NAME
# prepare new u-boot env
if [ "$next_boot_part" = "1" ]; then
echo "bootseq 1,2" > $setenv_script
else
echo "bootseq 2,1" > $setenv_script
fi
printf "kernel_size_%i 0x%08x\n" $next_boot_part $kernel_length >> $setenv_script
printf "vmlinux_start_addr 0x%08x\n" ${kernel_offset} >> $setenv_script
printf "vmlinux_size 0x%08x\n" ${kernel_length} >> $setenv_script
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
printf "rootfs_size_%i 0x%08x\n" $next_boot_part $((total_size-kernel_length)) >> $setenv_script
printf "rootfs_start_addr 0x%08x\n" $((kernel_offset+kernel_length)) >> $setenv_script
printf "rootfs_size 0x%08x\n" ${rootfs_length} >> $setenv_script
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
# store u-boot env changes
mkdir -p /var/lock
fw_setenv -s $setenv_script || {
echo "failed to update U-Boot environment"
return 1
}
}

View file

@ -59,7 +59,7 @@ platform_do_upgrade() {
case "$(board_name)" in
8dev,jalapeno |\
aruba,ap-303 |\
pangu,l1000 |\
pangu,l1000 |\
aruba,ap-303h |\
aruba,ap-365 |\
avm,fritzbox-7530 |\
@ -74,7 +74,8 @@ platform_do_upgrade() {
luma,wrtq-329acn |\
zbt,z4019 |\
mobipromo,cm520-79f |\
p2w,r619ac-64m |\
netgear,wac510 |\
p2w,r619ac-64m |\
p2w,r619ac-128m |\
qxwlan,e2600ac-c2)
nand_do_upgrade "$1"
@ -115,6 +116,17 @@ platform_do_upgrade() {
CI_KERNPART="part.safe"
nand_do_upgrade "$1"
;;
mikrotik,hap-ac2|\
mikrotik,sxtsq-5-ac)
[ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
default_do_upgrade "$1"
;;
netgear,rbr50 |\
netgear,rbs50 |\
netgear,srr60 |\
netgear,srs60)
platform_do_upgrade_netgear_orbi_upgrade "$1"
;;
openmesh,a42 |\
openmesh,a62 |\
plasmacloud,pa1200 |\
@ -129,4 +141,4 @@ platform_do_upgrade() {
default_do_upgrade "$1"
;;
esac
}
}

107
root/target/linux/ipq40xx/image/generic.mk Executable file → Normal file
View file

@ -35,7 +35,7 @@ define Device/DniImage
IMAGES += factory.img
IMAGE/factory.img := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | append-rootfs | pad-rootfs | netgear-dni
IMAGE/sysupgrade.bin := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
append-rootfs | pad-rootfs | append-metadata | check-size
append-rootfs | pad-rootfs | check-size | append-metadata
endef
define Build/append-rootfshdr
@ -62,6 +62,16 @@ define Build/mkmylofw_32m
@mv $@.new $@
endef
define Build/wac5xx-netgear-tar
mkdir $@.tmp
mv $@ $@.tmp/wac5xx-ubifs-root.img
md5sum $@.tmp/wac5xx-ubifs-root.img > $@.tmp/wac5xx-ubifs-root.md5sum
echo "WAC505 WAC510" > $@.tmp/metadata.txt
echo "WAC505_V9.9.9.9" > $@.tmp/version
tar -C $@.tmp/ -cf $@ .
rm -rf $@.tmp
endef
define Build/qsdk-ipq-factory-nand-askey
$(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh $@.its\
askey_kernel $(IMAGE_KERNEL) \
@ -96,7 +106,7 @@ define Device/8dev_habanero-dvk
IMAGE_SIZE := 30976k
SOC := qcom-ipq4019
DEVICE_PACKAGES := ipq-wifi-8dev_habanero-dvk
IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | append-metadata | check-size
IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | check-size | append-metadata
endef
TARGET_DEVICES += 8dev_habanero-dvk
@ -136,8 +146,7 @@ define Device/alfa-network_ap120c-ac
DEVICE_VENDOR := ALFA Network
DEVICE_MODEL := AP120C-AC
SOC := qcom-ipq4018
DEVICE_PACKAGES := kmod-usb-acm \
kmod-tpm-i2c-atmel
DEVICE_PACKAGES := kmod-usb-acm kmod-tpm-i2c-atmel
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGE_SIZE := 65536k
@ -213,7 +222,7 @@ define Device/avm_fritzbox-4040
UBOOT_PARTITION_SIZE := 524288
IMAGES += eva.bin
IMAGE/eva.bin := append-uboot | pad-to $$$$(UBOOT_PARTITION_SIZE) | append-kernel | append-rootfs | pad-rootfs
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
DEVICE_PACKAGES := fritz-tffs fritz-caldata
endef
TARGET_DEVICES += avm_fritzbox-4040
@ -371,6 +380,7 @@ define Device/edgecore_ecw5211
SOC := qcom-ipq4018
BLOCKSIZE := 128k
PAGESIZE := 2048
DEVICE_DTS_CONFIG := config@ap.dk01.1-c2
DEVICE_PACKAGES := kmod-tpm-i2c-atmel kmod-usb-acm
endef
TARGET_DEVICES += edgecore_ecw5211
@ -424,6 +434,7 @@ define Device/engenius_emd1
IMAGES += factory.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGE/factory.bin := qsdk-ipq-factory-nor | check-size
DEVICE_PACKAGES := ipq-wifi-engenius_emd1
endef
TARGET_DEVICES += engenius_emd1
@ -438,6 +449,7 @@ define Device/engenius_emr3500
IMAGES += factory.bin
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
IMAGE/factory.bin := qsdk-ipq-factory-nor | check-size
DEVICE_PACKAGES := ipq-wifi-engenius_emr3500
endef
TARGET_DEVICES += engenius_emr3500
@ -498,7 +510,7 @@ endef
TARGET_DEVICES += glinet_gl-ap1300
define Device/glinet_gl-b1300
$(call Device/FitImage)
$(call Device/FitzImage)
DEVICE_VENDOR := GL.iNet
DEVICE_MODEL := GL-B1300
BOARD_NAME := gl-b1300
@ -522,7 +534,7 @@ endef
TARGET_DEVICES += zbt_z4019
define Device/glinet_gl-s1300
$(call Device/FitImage)
$(call Device/FitzImage)
DEVICE_VENDOR := GL.iNet
DEVICE_MODEL := GL-S1300
SOC := qcom-ipq4029
@ -661,6 +673,79 @@ define Device/netgear_ex6150v2
endef
TARGET_DEVICES += netgear_ex6150v2
define Device/netgear_orbi
$(call Device/DniImage)
SOC := qcom-ipq4019
DEVICE_VENDOR := NETGEAR
IMAGE/factory.img := append-kernel | pad-offset 128k 64 | \
append-uImage-fakehdr filesystem | pad-to $$$$(KERNEL_SIZE) | \
append-rootfs | pad-rootfs | netgear-dni
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-to 64k | \
sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ath10k-firmware-qca9984-ct e2fsprogs kmod-fs-ext4 losetup
endef
define Device/netgear_rbx50
$(call Device/netgear_orbi)
NETGEAR_HW_ID := 29765352+0+4000+512+2x2+2x2+4x4
KERNEL_SIZE := 3932160
ROOTFS_SIZE := 32243712
IMAGE_SIZE := 36175872
endef
define Device/netgear_rbr50
$(call Device/netgear_rbx50)
DEVICE_MODEL := RBR50
DEVICE_VARIANT := v1
NETGEAR_BOARD_ID := RBR50
endef
TARGET_DEVICES += netgear_rbr50
define Device/netgear_rbs50
$(call Device/netgear_rbx50)
DEVICE_MODEL := RBS50
DEVICE_VARIANT := v1
NETGEAR_BOARD_ID := RBS50
endef
TARGET_DEVICES += netgear_rbs50
define Device/netgear_srx60
$(call Device/netgear_orbi)
NETGEAR_HW_ID := 29765352+0+4096+512+2x2+2x2+4x4
KERNEL_SIZE := 3932160
ROOTFS_SIZE := 32243712
IMAGE_SIZE := 36175872
endef
define Device/netgear_srr60
$(call Device/netgear_srx60)
DEVICE_MODEL := SRR60
NETGEAR_BOARD_ID := SRR60
endef
TARGET_DEVICES += netgear_srr60
define Device/netgear_srs60
$(call Device/netgear_srx60)
DEVICE_MODEL := SRS60
NETGEAR_BOARD_ID := SRS60
endef
TARGET_DEVICES += netgear_srs60
define Device/netgear_wac510
$(call Device/FitImage)
$(call Device/UbiFit)
DEVICE_VENDOR := Netgear
DEVICE_MODEL := WAC510
SOC := qcom-ipq4018
DEVICE_DTS_CONFIG := config@5
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGES += nand-factory.tar
IMAGE/nand-factory.tar := append-ubi | wac5xx-netgear-tar
DEVICE_PACKAGES := uboot-envtools
endef
TARGET_DEVICES += netgear_wac510
define Device/openmesh_a42
$(call Device/FitImageLzma)
DEVICE_VENDOR := OpenMesh
@ -704,7 +789,7 @@ define Device/plasmacloud_pa1200
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=PA1200
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ipq-wifi-plasmacloud-pa1200
DEVICE_PACKAGES := ipq-wifi-plasmacloud_pa1200
endef
TARGET_DEVICES += plasmacloud_pa1200
@ -720,7 +805,7 @@ define Device/plasmacloud_pa2200
IMAGES += factory.bin
IMAGE/factory.bin := append-rootfs | pad-rootfs | openmesh-image ce_type=PA2200
IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | sysupgrade-tar rootfs=$$$$@ | append-metadata
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-plasmacloud-pa2200
DEVICE_PACKAGES := ath10k-firmware-qca9888-ct ipq-wifi-plasmacloud_pa2200
endef
TARGET_DEVICES += plasmacloud_pa2200
@ -825,7 +910,7 @@ define Device/zyxel_wre6606
DEVICE_DTS_CONFIG := config@4
SOC := qcom-ipq4018
IMAGE_SIZE := 13184k
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers
endef
TARGET_DEVICES += zyxel_wre6606
TARGET_DEVICES += zyxel_wre6606