Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright (C) 2014-2016 OpenWrt.org
|
||||
# Copyright (C) 2016 LEDE-Project.org
|
||||
#
|
||||
|
||||
preinit_mount_syscfg() {
|
||||
. /lib/functions.sh
|
||||
. /lib/upgrade/common.sh
|
||||
|
||||
case $(board_name) in
|
||||
linksys,wrt1200ac|\
|
||||
linksys,wrt1900ac-v1|\
|
||||
linksys,wrt1900ac-v2|\
|
||||
linksys,wrt1900acs|\
|
||||
linksys,wrt3200acm|\
|
||||
linksys,wrt32x)
|
||||
needs_recovery=0
|
||||
syscfg_part=$(grep syscfg /proc/mtd |cut -c4)
|
||||
ubiattach -m $syscfg_part || needs_recovery=1
|
||||
if [ $needs_recovery -eq 1 ]
|
||||
then
|
||||
echo "ubifs syscfg partition is damaged, reformatting"
|
||||
ubidetach -m $syscfg_part
|
||||
ubiformat -y -O 2048 -q /dev/mtd$syscfg_part
|
||||
ubiattach -m $syscfg_part
|
||||
ubimkvol /dev/ubi1 -n 0 -N syscfg -t dynamic --maxavsize
|
||||
fi
|
||||
mkdir /tmp/syscfg
|
||||
mount -t ubifs ubi1:syscfg /tmp/syscfg
|
||||
[ -f "/tmp/syscfg/$BACKUP_FILE" ] && {
|
||||
echo "- config restore -"
|
||||
cd /
|
||||
mv "/tmp/syscfg/$BACKUP_FILE" /tmp
|
||||
tar xzf "/tmp/$BACKUP_FILE"
|
||||
rm -f "/tmp/$BACKUP_FILE"
|
||||
sync
|
||||
}
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main preinit_mount_syscfg
|
||||
186
target/linux/mvebu/cortexa9/base-files/lib/upgrade/fortinet.sh
Normal file
186
target/linux/mvebu/cortexa9/base-files/lib/upgrade/fortinet.sh
Normal file
@@ -0,0 +1,186 @@
|
||||
. /lib/functions.sh
|
||||
|
||||
fortinet_bswap32() {
|
||||
local val="$(printf %08x $(($1)))"
|
||||
|
||||
# swap and print in hex
|
||||
echo "0x${val:6:2}${val:4:2}${val:2:2}${val:0:2}"
|
||||
}
|
||||
|
||||
fortinet_by2bl() {
|
||||
local blks="$(($1 / 0x200))"
|
||||
[ $(($1 % 0x200)) -gt 0 ] && blks=$((blks + 1))
|
||||
|
||||
printf "0x%08x" $blks
|
||||
}
|
||||
|
||||
fortinet_bl2by() {
|
||||
printf "0x%08x" $(($1 * 0x200))
|
||||
}
|
||||
|
||||
fortinet_build_partmap() {
|
||||
local new="$1" old="$2"
|
||||
local len="${old%%@*}" ofs="${old##*@}"
|
||||
|
||||
case "$new" in
|
||||
@*) ofs="$(fortinet_by2bl ${new##@})" ;; # "@<offset>"
|
||||
|
||||
*@*) len="$(fortinet_by2bl ${new%%@*})" # "<length>@<offset>"
|
||||
ofs="$(fortinet_by2bl ${new##*@})" ;;
|
||||
|
||||
"") ;; # "" (empty)
|
||||
|
||||
*) len="$(fortinet_by2bl ${new%%@*})" ;; # "<length>"
|
||||
esac
|
||||
|
||||
# print N blocks of length/offset in dec
|
||||
echo "${len}@${ofs}"
|
||||
}
|
||||
|
||||
# Update firmware information in "firmware-info" partition
|
||||
#
|
||||
# parameters:
|
||||
# $1: image index (0/1)
|
||||
# $2: new image name (up to 32 characters)
|
||||
# $3: length and/or offset for kernel (bytes)
|
||||
# $4: length and/or offset for rootfs (bytes)
|
||||
#
|
||||
# Note: $3 and $4 support multiple formats:
|
||||
#
|
||||
# - <length>@<offset>: set <length> and <rootfs>
|
||||
# - <length> : set <length> and keep the current offset
|
||||
# - @<offset> : set <offset> and keep the current length
|
||||
# - "" (empty) : keep the current length and offset
|
||||
fortinet_update_fwinfo() {
|
||||
local fwinfo_mtd="$(find_mtd_part firmware-info)"
|
||||
local index="$1"
|
||||
local name="$2"
|
||||
local offset
|
||||
local old_kr
|
||||
local old new tmp part pos
|
||||
local output
|
||||
|
||||
if [ -z "$fwinfo_mtd" ]; then
|
||||
echo "ERROR: MTD device \"firmware-info\" not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Image Name
|
||||
case "$index" in
|
||||
0) offset=0x10 ;;
|
||||
1) offset=0x30 ;;
|
||||
*) echo "ERROR: invalid image index specified!"; return 1 ;;
|
||||
esac
|
||||
|
||||
printf "Image Index: %d\n" $index
|
||||
|
||||
old="$(dd bs=16 count=2 skip=$((offset / 16)) if=$fwinfo_mtd 2>/dev/null)"
|
||||
printf "Image Name : \"%s\"\n" "$old"
|
||||
if [ -n "$name" ]; then
|
||||
echo -n "$name" | \
|
||||
dd bs=32 count=1 oflag=seek_bytes seek=$((offset)) \
|
||||
conv=sync,notrunc of=$fwinfo_mtd 2>/dev/null
|
||||
printf " --> \"%s\"\n\n" "$name"
|
||||
else
|
||||
printf "\n"
|
||||
fi
|
||||
|
||||
# length/offset values of kernel/rootfs
|
||||
case "$index" in
|
||||
0) offset=0x180 ;;
|
||||
1) offset=0x190 ;;
|
||||
esac
|
||||
|
||||
# <kernel offset:4><kernel length:4><rootfs offset:4><rootfs length:4>
|
||||
old_kr="$(hexdump -n 16 -v -s $((offset)) -e '1/4 "%08x"' $fwinfo_mtd)"
|
||||
|
||||
pos=0
|
||||
for part in kernel rootfs; do
|
||||
old="0x${old_kr:$((8 + pos)):8}@0x${old_kr:$((0 + pos)):8}"
|
||||
new="$(fortinet_build_partmap "$3" "$old")"
|
||||
shift
|
||||
|
||||
printf " %s:\n" $part
|
||||
printf " old: 0x%08x@0x%08x\n" \
|
||||
$(fortinet_bl2by ${old%%@*}) $(fortinet_bl2by ${old##*@})
|
||||
printf " new: 0x%08x@0x%08x\n\n" \
|
||||
$(fortinet_bl2by ${new%%@*}) $(fortinet_bl2by ${new##*@})
|
||||
|
||||
tmp="$(fortinet_bswap32 ${new%%@*})@$(fortinet_bswap32 ${new##*@})"
|
||||
new="$(echo $tmp | sed 's/0x\([0-9a-f]\{8\}\)@0x\([0-9a-f]\{8\}\)/\2\1/')"
|
||||
output="${output}${new}"
|
||||
|
||||
pos=$((pos + 16))
|
||||
done
|
||||
|
||||
data_2bin "$output" | \
|
||||
dd bs=16 count=1 seek=$((offset / 16)) conv=notrunc \
|
||||
of=$fwinfo_mtd 2>/dev/null
|
||||
}
|
||||
|
||||
fortinet_do_upgrade() {
|
||||
local board_dir="$(tar tf "$1" | grep -m 1 '^sysupgrade-.*/$')"
|
||||
local kern_mtd="$(find_mtd_part kernel)"
|
||||
local root_mtd="$(find_mtd_part rootfs)"
|
||||
local kern_len kern_ofs root_len root_ofs
|
||||
local imgname
|
||||
|
||||
board_dir="${board_dir%/}"
|
||||
|
||||
if [ -z "$kern_mtd" ] || [ -z "$root_mtd" ]; then
|
||||
echo "ERROR: MTD device \"kernel\" or \"rootfs\" not found"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
kern_ofs=$(cat /sys/class/mtd/${kern_mtd//\/dev\/mtdblock/mtd}/offset)
|
||||
root_ofs=$(cat /sys/class/mtd/${root_mtd//\/dev\/mtdblock/mtd}/offset)
|
||||
|
||||
if [ -z "$kern_ofs" ] || [ -z "$root_ofs" ]; then
|
||||
echo "ERROR: failed to get offset of kernel or rootfs"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
|
||||
kern_len=$( (tar xOf "$1" "$board_dir/kernel" | wc -c) 2> /dev/null)
|
||||
root_len=$( (tar xOf "$1" "$board_dir/root" | wc -c) 2> /dev/null)
|
||||
|
||||
if [ -z "$kern_len" ] || [ -z "$root_len" ]; then
|
||||
echo "ERROR: failed to get length of new kernel or rootfs"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
|
||||
# try to load and parse /tmp/sysupgrade.meta for image name
|
||||
if [ -r "/tmp/sysupgrade.meta" ]; then
|
||||
local key value
|
||||
|
||||
sed -e 's/, \{1,2\}\"/\n"/g' \
|
||||
-e 's/{ \{1,2\}/\n/g' \
|
||||
-e 's/ \{1,2\}}/\n/g' < /tmp/sysupgrade.meta \
|
||||
> /tmp/sysupgrade.meta.tmp
|
||||
while read key value; do
|
||||
key="${key//\"/}"
|
||||
value="${value//\"/}"
|
||||
|
||||
[ -z "$value" ] && continue
|
||||
case "$key" in
|
||||
dist:|\
|
||||
version:|\
|
||||
revision:) imgname="${imgname}$value " ;;
|
||||
esac
|
||||
done < /tmp/sysupgrade.meta.tmp
|
||||
else
|
||||
imgname="OpenWrt"
|
||||
fi
|
||||
|
||||
fortinet_update_fwinfo 0 "${imgname%% }" \
|
||||
"${kern_len}@${kern_ofs}" "${root_len}@${root_ofs}" || {
|
||||
umount -a
|
||||
reboot -f
|
||||
}
|
||||
|
||||
tar xOf "$1" "$board_dir/kernel" | \
|
||||
mtd write - "kernel"
|
||||
tar xOf "$1" "$board_dir/root" | \
|
||||
mtd ${UPGRADE_BACKUP:+-j "${UPGRADE_BACKUP}"} write - "rootfs"
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#
|
||||
# Copyright (C) 2014-2015 OpenWrt.org
|
||||
#
|
||||
|
||||
linksys_get_target_firmware() {
|
||||
|
||||
local cur_boot_part mtd_ubi0
|
||||
|
||||
cur_boot_part=$(/usr/sbin/fw_printenv -n boot_part)
|
||||
if [ -z "${cur_boot_part}" ] ; then
|
||||
mtd_ubi0=$(cat /sys/class/ubi/ubi0/mtd_num)
|
||||
case $(grep -E ^mtd${mtd_ubi0}: /proc/mtd | cut -d '"' -f 2) in
|
||||
kernel1|rootfs1)
|
||||
cur_boot_part=1
|
||||
;;
|
||||
kernel2|rootfs2)
|
||||
cur_boot_part=2
|
||||
;;
|
||||
esac
|
||||
>&2 printf "Current boot_part='%s' selected from ubi0/mtd_num='%s'" \
|
||||
"${cur_boot_part}" "${mtd_ubi0}"
|
||||
fi
|
||||
|
||||
case $cur_boot_part in
|
||||
1)
|
||||
fw_setenv -s - <<-EOF
|
||||
boot_part 2
|
||||
bootcmd "run altnandboot"
|
||||
EOF
|
||||
printf "kernel2"
|
||||
return
|
||||
;;
|
||||
2)
|
||||
fw_setenv -s - <<-EOF
|
||||
boot_part 1
|
||||
bootcmd "run nandboot"
|
||||
EOF
|
||||
printf "kernel1"
|
||||
return
|
||||
;;
|
||||
*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
platform_do_upgrade_linksys() {
|
||||
local magic_long="$(get_magic_long "$1")"
|
||||
|
||||
mkdir -p /var/lock
|
||||
local part_label="$(linksys_get_target_firmware)"
|
||||
touch /var/lock/fw_printenv.lock
|
||||
|
||||
if [ ! -n "$part_label" ]
|
||||
then
|
||||
v "cannot find target partition"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local target_mtd=$(find_mtd_part $part_label)
|
||||
|
||||
[ "$magic_long" = "73797375" ] && {
|
||||
CI_KERNPART="$part_label"
|
||||
if [ "$part_label" = "kernel1" ]
|
||||
then
|
||||
CI_UBIPART="rootfs1"
|
||||
else
|
||||
CI_UBIPART="rootfs2"
|
||||
fi
|
||||
|
||||
if nand_upgrade_tar "$1" ; then
|
||||
nand_do_upgrade_success
|
||||
else
|
||||
nand_do_upgrade_failed
|
||||
fi
|
||||
|
||||
}
|
||||
[ "$magic_long" = "27051956" -o "$magic_long" = "0000a0e1" ] && {
|
||||
get_image "$1" | mtd write - $part_label
|
||||
}
|
||||
}
|
||||
|
||||
platform_copy_config_linksys() {
|
||||
cp -f "$UPGRADE_BACKUP" "/tmp/syscfg/$BACKUP_FILE"
|
||||
sync
|
||||
}
|
||||
110
target/linux/mvebu/cortexa9/base-files/lib/upgrade/platform.sh
Executable file
110
target/linux/mvebu/cortexa9/base-files/lib/upgrade/platform.sh
Executable file
@@ -0,0 +1,110 @@
|
||||
#
|
||||
# Copyright (C) 2014-2016 OpenWrt.org
|
||||
# Copyright (C) 2016 LEDE-Project.org
|
||||
#
|
||||
|
||||
RAMFS_COPY_BIN='fw_printenv fw_setenv seq strings'
|
||||
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
|
||||
|
||||
REQUIRE_IMAGE_METADATA=1
|
||||
|
||||
platform_check_image() {
|
||||
case "$(board_name)" in
|
||||
cznic,turris-omnia|\
|
||||
kobol,helios4|\
|
||||
solidrun,clearfog-base-a1|\
|
||||
solidrun,clearfog-pro-a1)
|
||||
legacy_sdcard_check_image "$1"
|
||||
;;
|
||||
*)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
platform_do_upgrade() {
|
||||
case "$(board_name)" in
|
||||
buffalo,ls220de)
|
||||
# Kernel UBI volume name must be "boot"
|
||||
CI_KERNPART=boot
|
||||
CI_KERN_UBIPART=ubi_kernel
|
||||
CI_ROOT_UBIPART=ubi
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
buffalo,ls421de)
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
ctera,c200-v2)
|
||||
part=$(find_mtd_part "active_bank")
|
||||
|
||||
if [ -n "$part" ]; then
|
||||
CI_KERNPART="$(strings $part | grep bank)"
|
||||
nand_do_upgrade "$1"
|
||||
else
|
||||
echo "active_bank partition missed!"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
cznic,turris-omnia|\
|
||||
kobol,helios4|\
|
||||
solidrun,clearfog-base-a1|\
|
||||
solidrun,clearfog-pro-a1)
|
||||
legacy_sdcard_do_upgrade "$1"
|
||||
;;
|
||||
fortinet,fg-30e|\
|
||||
fortinet,fg-50e|\
|
||||
fortinet,fg-51e|\
|
||||
fortinet,fg-52e|\
|
||||
fortinet,fwf-50e-2r|\
|
||||
fortinet,fwf-51e)
|
||||
fortinet_do_upgrade "$1"
|
||||
;;
|
||||
iij,sa-w2)
|
||||
local envmtd=$(find_mtd_part "bootloader-env")
|
||||
local bootdev=$(grep "BOOTDEV=" "$envmtd")
|
||||
case "${bootdev#*=}" in
|
||||
flash) PART_NAME="firmware" ;;
|
||||
rescue) PART_NAME="rescue" ;;
|
||||
*)
|
||||
echo "invalid BOOTDEV is set (\"${bootdev#*=}\")"
|
||||
umount -a
|
||||
reboot -f
|
||||
;;
|
||||
esac
|
||||
default_do_upgrade "$1"
|
||||
;;
|
||||
iptime,nas1dual)
|
||||
PART_NAME=firmware
|
||||
default_do_upgrade "$1"
|
||||
;;
|
||||
linksys,wrt1200ac|\
|
||||
linksys,wrt1900ac-v1|\
|
||||
linksys,wrt1900ac-v2|\
|
||||
linksys,wrt1900acs|\
|
||||
linksys,wrt3200acm|\
|
||||
linksys,wrt32x)
|
||||
platform_do_upgrade_linksys "$1"
|
||||
;;
|
||||
*)
|
||||
default_do_upgrade "$1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
platform_copy_config() {
|
||||
case "$(board_name)" in
|
||||
cznic,turris-omnia|\
|
||||
kobol,helios4|\
|
||||
solidrun,clearfog-base-a1|\
|
||||
solidrun,clearfog-pro-a1)
|
||||
legacy_sdcard_copy_config
|
||||
;;
|
||||
linksys,wrt1200ac|\
|
||||
linksys,wrt1900ac-v1|\
|
||||
linksys,wrt1900ac-v2|\
|
||||
linksys,wrt1900acs|\
|
||||
linksys,wrt3200acm|\
|
||||
linksys,wrt32x)
|
||||
platform_copy_config_linksys
|
||||
;;
|
||||
esac
|
||||
}
|
||||
Reference in New Issue
Block a user