Hi!

Am 23.10.2016 um 16:44 schrieb Felix Fietkau:
> On 2016-10-23 16:25, André Valentin wrote:
>> Add new way of flashing to mmc devices based on rootfs split with loop 
>> devices.
>>
>> Signed-off-by: André Valentin <avalen...@marcant.net>
>> ---
>>  .../ipq806x/base-files/lib/upgrade/platform.sh     | 12 +++
>>  .../linux/ipq806x/base-files/lib/upgrade/zyxel.sh  | 94 
>> ++++++++++++++++++++++
>>  2 files changed, 106 insertions(+)
>>  create mode 100644 target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
>>
>> diff --git a/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh 
>> b/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
>> new file mode 100644
>> index 0000000..d228dab
>> --- /dev/null
>> +++ b/target/linux/ipq806x/base-files/lib/upgrade/zyxel.sh
>> @@ -0,0 +1,94 @@
>> +#
>> +# Copyright (C) 2016 lede-project.org
>> +#
>> +
>> +zyxel_get_rootfs() {
>> +    local rootfsdev
>> +
>> +    if read cmdline < /proc/cmdline; then
>> +            case "$cmdline" in
>> +                    *block2mtd=*)
>> +                            rootfsdev="${cmdline##*block2mtd=}"
>> +                            rootfsdev="${rootfsdev%%,*}"
>> +                    ;;
> You can drop the block2mtd part here.

I'll remove it.
> 
>> +                    *root=*)
>> +                            rootfsdev="${cmdline##*root=}"
>> +                            rootfsdev="${rootfsdev%% *}"
>> +                    ;;
>> +            esac
>> +
>> +            echo "${rootfsdev}"
>> +    fi
>> +}
>> +
>> +zyxel_do_flash() {
>> +    local tar_file=$1
>> +    local board=$2
>> +    local kernel=$3
>> +    local rootfs=$4
>> +    local blocksize=65536
>> +
>> +    # keep sure its unbound
>> +    losetup --detach-all || {
>> +            echo Failed to detach all loop devices. Skip this try.
>> +            reboot -f
>> +    }
>> +
>> +    echo "flashing kernel to /dev/${kernel}"
>> +    tar xf $tar_file sysupgrade-$board/kernel -O >/dev/$kernel
>> +
>> +    echo "flashing rootfs to ${rootfs}"
>> +    tar xf $tar_file sysupgrade-$board/root -O >"${rootfs}"
>> +
>> +    local offset=$(tar xf $tar_file sysupgrade-$board/root -O | wc -c)
>> +    offset=$(( (($offset + $blocksize - 1) / $blocksize) * $blocksize ))
>> +
>> +    # Sanity
>> +    [ $offset -lt $blocksize ] && {
>> +            echo Wrong size for rootfs: $offset
>> +            sleep 10
>> +            reboot -f
>> +    }
>> +
>> +    # Mount loop for rootfs_data
>> +    losetup -o $offset /dev/loop0 "${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 /dev/loop0
>> +    mkdir /tmp/new_root
>> +    mount -t ext4 /dev/loop0 /tmp/new_root  && {
>> +            echo "Saving config to rootfs_data at position ${offset}."
>> +            cp -v /tmp/sysupgrade.tgz /tmp/new_root/
>> +            umount /tmp/new_root
>> +    }
>> +
>> +    # Cleanup
>> +    losetup -d /dev/loop0 >/dev/null 2>&1
> I think trying to guesstimate the offset for the ext4 part here, when
> fstools already handles some of that is a bit fragile. Things like the
> block size might be changed at some point, so I think it would be a good
> idea to extend fstools to be able deal with this stuff.

I think we need to store the blocksize in the sysupgrade/control. Because it 
could
change between 2 firmwares. What dou you think. In this case an fstools patch is
not needed.

Kind regards,

André


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to