X-Git-Url: https://git.archive.openwrt.org/?p=openwrt.git;a=blobdiff_plain;f=target%2Flinux%2Fbcm53xx%2Fbase-files%2Flib%2Fupgrade%2Fplatform.sh;h=d3440b77391ad49eec17b5e5e6c9355ee2604958;hp=e174cc7beb667cb9d70dd83105f023f61dbb1863;hb=d1cf0600961c3d72294cac1632065f1910663307;hpb=4664528216a4e237e475df9a5631f1c73fe2808b diff --git a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh index e174cc7beb..d3440b7739 100644 --- a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh @@ -54,28 +54,9 @@ platform_identify() { echo "unknown" } -# $(1): image that should contain trx -# $(2): trx offset in image -platform_check_image_trx() { - local magic=$(get_magic_long_at "$1" $2) - - [ "$magic" != "48445230" ] && { - return 1 - } - - # TODO: Check crc32 - - return 0 -} - platform_check_image() { [ "$#" -gt 1 ] && return 1 - [ "$(platform_flash_type)" = "nand" ] && { - echo "Firmware upgrade on NAND devices is not implemented." - return 1 - } - local file_type=$(platform_identify "$1") local magic local error=0 @@ -93,7 +74,7 @@ platform_check_image() { error=1 } - if ! platform_check_image_trx "$1" "$header_len"; then + if ! otrx check "$1" -o "$header_len"; then echo "No valid TRX firmware in the CHK image" error=1 fi @@ -108,12 +89,16 @@ platform_check_image() { error=1 } - if ! platform_check_image_trx "$1" 32; then + if ! otrx check "$1" -o 32; then echo "No valid TRX firmware in the CyberTAN image" error=1 fi ;; "trx") + if ! otrx check "$1"; then + echo "Invalid (corrupted?) TRX firmware" + error=1 + fi ;; *) echo "Invalid image type. Please use only .trx files" @@ -124,44 +109,80 @@ platform_check_image() { return $error } -# Extract TRX and use stadard upgrade method -platform_do_upgrade_chk() { +platform_extract_trx_from_chk() { local header_len=$((0x$(get_magic_long_at "$1" 4))) - local trx="/tmp/$1.trx" - dd if="$1" of="$trx" bs=$header_len skip=1 - shift - platform_do_upgrade_trx "$trx" "$@" + dd if="$1" of="$2" bs=$header_len skip=1 } -# Extract TRX and use stadard upgrade method -platform_do_upgrade_cybertan() { - local trx="/tmp/$1.trx" - - dd if="$1" of="$trx" bs=32 skip=1 - shift - platform_do_upgrade_trx "$trx" "$@" +platform_extract_trx_from_cybertan() { + dd if="$1" of="$2" bs=32 skip=1 } -platform_do_upgrade_trx() { - local flash_type=$(platform_flash_type) +platform_pre_upgrade() { + local file_type=$(platform_identify "$1") + local dir="/tmp/sysupgrade-bcm53xx" + local trx="$1" - case "$flash_type" in - "serial") - default_do_upgrade "$@" - ;; - "nand") - echo "Firmware upgrade on NAND devices is REALLY unsupported." - ;; + [ "$(platform_flash_type)" != "nand" ] && return + + # Extract trx + case "$file_type" in + "chk") trx="/tmp/$(basename $1).trx"; platform_extract_trx_from_chk "$1" "$trx";; + "cybertan") trx="/tmp/$(basename $1).trx"; platform_extract_trx_from_cybertan "$1" "$trx";; esac + + # Extract partitions from trx + rm -fR $dir + mkdir -p $dir + otrx extract "$trx" \ + -1 $dir/kernel \ + -2 $dir/root + + # Firmwares without UBI image should be flashed "normally" + local root_type=$(identify $dir/root) + [ "$root_type" != "ubi" ] && return + + # Prepare TRX file with just a kernel that will replace current one + local linux_length=$(grep "\"linux\"" /proc/mtd | sed "s/mtd[0-9]*:[ \t]*\([^ \t]*\).*/\1/") + [ -z "$linux_length" ] && { + echo "Unable to find \"linux\" partition size" + exit 1 + } + linux_length=$((0x$linux_length + 28)) + rm -f /tmp/null.bin + rm -f /tmp/kernel.trx + touch /tmp/null.bin + otrx create /tmp/kernel.trx \ + -f $dir/kernel -b $linux_length \ + -f /tmp/null.bin + + # Prepare UBI image (drop unwanted extra blocks) + local ubi_length=0 + while [ "$(dd if=$dir/root skip=$ubi_length bs=1 count=4 2>/dev/null)" = "UBI#" ]; do + ubi_length=$(($ubi_length + 131072)) + done + echo "ubi_length: $ubi_length" + dd if=$dir/root of=/tmp/root.ubi bs=131072 count=$((ubi_length / 131072)) 2>/dev/null + + # Flash + mtd write /tmp/kernel.trx firmware + nand_do_upgrade /tmp/root.ubi } platform_do_upgrade() { local file_type=$(platform_identify "$1") + local trx="$1" + + [ "$(platform_flash_type)" == "nand" ] && { + echo "Flashing firmware without UBI for rootfs. All erase counters will be lost." + } case "$file_type" in - "chk") platform_do_upgrade_chk "$ARGV";; - "cybertan") platform_do_upgrade_cybertan "$ARGV";; - *) platform_do_upgrade_trx "$ARGV";; + "chk") trx="/tmp/$(basename $1).trx"; platform_extract_trx_from_chk "$1" "$trx";; + "cybertan") trx="/tmp/$(basename $1).trx"; platform_extract_trx_from_cybertan "$1" "$trx";; esac + + shift + default_do_upgrade "$trx" "$@" }