2014-06-11 12:59:49 +00:00
|
|
|
# Copyright (C) 2014 OpenWrt.org
|
|
|
|
#
|
|
|
|
|
|
|
|
. /lib/functions.sh
|
|
|
|
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
# 'kernel' partition or UBI volume on NAND contains the kernel
|
2016-11-20 02:33:03 +00:00
|
|
|
CI_KERNPART="${CI_KERNPART:-kernel}"
|
2014-07-14 14:53:15 +00:00
|
|
|
|
2014-06-24 18:13:56 +00:00
|
|
|
# 'ubi' partition on NAND contains UBI
|
2016-11-20 02:33:03 +00:00
|
|
|
CI_UBIPART="${CI_UBIPART:-ubi}"
|
2014-06-11 12:59:49 +00:00
|
|
|
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
# 'rootfs' UBI volume on NAND contains the rootfs
|
2019-01-01 00:15:34 +00:00
|
|
|
CI_ROOTPART="${CI_ROOTPART:-rootfs}"
|
|
|
|
|
2014-10-12 15:50:15 +00:00
|
|
|
ubi_mknod() {
|
|
|
|
local dir="$1"
|
|
|
|
local dev="/dev/$(basename $dir)"
|
|
|
|
|
|
|
|
[ -e "$dev" ] && return 0
|
|
|
|
|
|
|
|
local devid="$(cat $dir/dev)"
|
|
|
|
local major="${devid%%:*}"
|
|
|
|
local minor="${devid##*:}"
|
|
|
|
mknod "$dev" c $major $minor
|
|
|
|
}
|
|
|
|
|
2014-06-11 12:59:49 +00:00
|
|
|
nand_find_volume() {
|
|
|
|
local ubidevdir ubivoldir
|
|
|
|
ubidevdir="/sys/devices/virtual/ubi/$1"
|
|
|
|
[ ! -d "$ubidevdir" ] && return 1
|
|
|
|
for ubivoldir in $ubidevdir/${1}_*; do
|
|
|
|
[ ! -d "$ubivoldir" ] && continue
|
|
|
|
if [ "$( cat $ubivoldir/name )" = "$2" ]; then
|
|
|
|
basename $ubivoldir
|
2014-10-12 15:50:15 +00:00
|
|
|
ubi_mknod "$ubivoldir"
|
2014-06-11 12:59:49 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
nand_find_ubi() {
|
|
|
|
local ubidevdir ubidev mtdnum
|
|
|
|
mtdnum="$( find_mtd_index $1 )"
|
|
|
|
[ ! "$mtdnum" ] && return 1
|
|
|
|
for ubidevdir in /sys/devices/virtual/ubi/ubi*; do
|
|
|
|
[ ! -d "$ubidevdir" ] && continue
|
|
|
|
cmtdnum="$( cat $ubidevdir/mtd_num )"
|
|
|
|
[ ! "$mtdnum" ] && continue
|
|
|
|
if [ "$mtdnum" = "$cmtdnum" ]; then
|
|
|
|
ubidev=$( basename $ubidevdir )
|
2014-10-12 15:50:15 +00:00
|
|
|
ubi_mknod "$ubidevdir"
|
2014-06-11 12:59:49 +00:00
|
|
|
echo $ubidev
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-07-13 20:51:17 +00:00
|
|
|
nand_get_magic_long() {
|
2022-05-03 10:09:33 +00:00
|
|
|
(${3}cat "$1" | dd bs=4 "skip=${2:-0}" count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
get_magic_long_tar() {
|
2022-05-04 02:54:58 +00:00
|
|
|
(tar xO${3}f "$1" "$2" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
identify_magic() {
|
|
|
|
local magic=$1
|
2014-06-11 12:59:49 +00:00
|
|
|
case "$magic" in
|
|
|
|
"55424923")
|
|
|
|
echo "ubi"
|
|
|
|
;;
|
|
|
|
"31181006")
|
|
|
|
echo "ubifs"
|
|
|
|
;;
|
|
|
|
"68737173")
|
|
|
|
echo "squashfs"
|
|
|
|
;;
|
|
|
|
"d00dfeed")
|
|
|
|
echo "fit"
|
|
|
|
;;
|
|
|
|
"4349"*)
|
|
|
|
echo "combined"
|
|
|
|
;;
|
2022-05-03 10:09:33 +00:00
|
|
|
"1f8b"*)
|
|
|
|
echo "gzip"
|
|
|
|
;;
|
2014-06-11 12:59:49 +00:00
|
|
|
*)
|
|
|
|
echo "unknown $magic"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
identify() {
|
2022-05-03 10:09:33 +00:00
|
|
|
identify_magic $(nand_get_magic_long "$@")
|
2014-06-16 18:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
identify_tar() {
|
2022-05-03 10:09:33 +00:00
|
|
|
identify_magic $(get_magic_long_tar "$@")
|
|
|
|
}
|
|
|
|
|
|
|
|
identify_if_gzip() {
|
|
|
|
if [ "$(identify "$1")" = gzip ]; then echo -n z; fi
|
2014-06-16 18:55:14 +00:00
|
|
|
}
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_restore_config() {
|
2022-04-15 10:18:22 +00:00
|
|
|
local ubidev=$( nand_find_ubi "$CI_UBIPART" )
|
2014-06-16 18:55:14 +00:00
|
|
|
local ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
2022-04-15 13:11:52 +00:00
|
|
|
if [ ! "$ubivol" ]; then
|
2022-04-15 10:18:22 +00:00
|
|
|
ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
|
2022-04-15 13:11:52 +00:00
|
|
|
if [ ! "$ubivol" ]; then
|
|
|
|
echo "cannot find ubifs data volume"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
2014-06-16 18:55:14 +00:00
|
|
|
mkdir /tmp/new_root
|
|
|
|
if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
|
2022-04-15 13:11:52 +00:00
|
|
|
echo "cannot mount ubifs volume $ubivol"
|
2014-06-16 18:55:14 +00:00
|
|
|
rmdir /tmp/new_root
|
|
|
|
return 1
|
|
|
|
fi
|
2022-04-15 13:11:52 +00:00
|
|
|
if mv "$1" "/tmp/new_root/$BACKUP_FILE"; then
|
|
|
|
if umount /tmp/new_root; then
|
|
|
|
echo "configuration saved"
|
|
|
|
rmdir /tmp/new_root
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
umount /tmp/new_root
|
|
|
|
fi
|
|
|
|
echo "could not save configuration to ubifs volume $ubivol"
|
2014-06-16 18:55:14 +00:00
|
|
|
rmdir /tmp/new_root
|
2022-04-15 13:11:52 +00:00
|
|
|
return 1
|
2014-06-16 18:55:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 03:52:12 +00:00
|
|
|
nand_remove_ubiblock() {
|
2022-05-03 06:47:43 +00:00
|
|
|
local ubivol="$1"
|
|
|
|
|
|
|
|
local ubiblk="ubiblock${ubivol:3}"
|
|
|
|
if [ -e "/dev/$ubiblk" ]; then
|
|
|
|
umount "/dev/$ubiblk" && echo "unmounted /dev/$ubiblk" || :
|
|
|
|
if ! ubiblock -r "/dev/$ubivol"; then
|
2022-04-15 03:52:12 +00:00
|
|
|
echo "cannot remove $ubiblk"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-03 06:47:43 +00:00
|
|
|
nand_detach_ubi() {
|
|
|
|
local ubipart="$1"
|
|
|
|
|
|
|
|
local mtdnum="$( find_mtd_index "$ubipart" )"
|
|
|
|
if [ ! "$mtdnum" ]; then
|
|
|
|
echo "cannot find ubi mtd partition $ubipart"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ubidev="$( nand_find_ubi "$ubipart" )"
|
|
|
|
if [ "$ubidev" ]; then
|
|
|
|
for ubivol in $(find /dev -name "${ubidev}_*" -maxdepth 1 | sort); do
|
|
|
|
ubivol="${ubivol:5}"
|
|
|
|
nand_remove_ubiblock "$ubivol" || :
|
|
|
|
umount "/dev/$ubivol" && echo "unmounted /dev/$ubivol" || :
|
|
|
|
done
|
|
|
|
if ! ubidetach -m "$mtdnum"; then
|
|
|
|
echo "cannot detach ubi mtd partition $ubipart"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_upgrade_prepare_ubi() {
|
|
|
|
local rootfs_length="$1"
|
2014-06-19 14:13:41 +00:00
|
|
|
local rootfs_type="$2"
|
2022-05-04 02:54:58 +00:00
|
|
|
local rootfs_data_max="$(fw_printenv -n rootfs_data_max 2> /dev/null)"
|
2021-02-24 11:40:50 +00:00
|
|
|
[ -n "$rootfs_data_max" ] && rootfs_data_max=$((rootfs_data_max))
|
2021-02-17 15:17:49 +00:00
|
|
|
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
local kernel_length="$3"
|
2014-06-19 14:13:41 +00:00
|
|
|
local has_env="${4:-0}"
|
2014-06-16 18:55:14 +00:00
|
|
|
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
[ -n "$rootfs_length" -o -n "$kernel_length" ] || return 1
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
2014-06-11 12:59:49 +00:00
|
|
|
if [ ! "$mtdnum" ]; then
|
|
|
|
echo "cannot find ubi mtd partition $CI_UBIPART"
|
|
|
|
return 1
|
|
|
|
fi
|
2014-06-16 18:55:14 +00:00
|
|
|
|
2014-06-11 12:59:49 +00:00
|
|
|
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
|
|
|
if [ ! "$ubidev" ]; then
|
|
|
|
ubiattach -m "$mtdnum"
|
|
|
|
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
2014-06-16 18:55:14 +00:00
|
|
|
|
2022-04-15 03:44:26 +00:00
|
|
|
if [ ! "$ubidev" ]; then
|
|
|
|
ubiformat /dev/mtd$mtdnum -y
|
|
|
|
ubiattach -m "$mtdnum"
|
|
|
|
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
|
|
|
|
|
|
|
if [ ! "$ubidev" ]; then
|
|
|
|
echo "cannot attach ubi mtd partition $CI_UBIPART"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$has_env" -gt 0 ]; then
|
|
|
|
ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
|
|
|
|
ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
|
|
|
|
fi
|
|
|
|
fi
|
2014-06-11 12:59:49 +00:00
|
|
|
fi
|
2014-06-16 18:55:14 +00:00
|
|
|
|
2022-04-15 10:18:22 +00:00
|
|
|
local kern_ubivol="$( nand_find_volume $ubidev "$CI_KERNPART" )"
|
|
|
|
local root_ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
|
2014-06-11 12:59:49 +00:00
|
|
|
local data_ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
2022-04-15 03:52:12 +00:00
|
|
|
[ "$root_ubivol" = "$kern_ubivol" ] && root_ubivol=
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-04-15 03:52:12 +00:00
|
|
|
# remove ubiblocks
|
|
|
|
[ "$kern_ubivol" ] && { nand_remove_ubiblock $kern_ubivol || return 1; }
|
|
|
|
[ "$root_ubivol" ] && { nand_remove_ubiblock $root_ubivol || return 1; }
|
|
|
|
[ "$data_ubivol" ] && { nand_remove_ubiblock $data_ubivol || return 1; }
|
2014-06-11 12:59:49 +00:00
|
|
|
|
|
|
|
# kill volumes
|
2022-04-15 10:18:22 +00:00
|
|
|
[ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N "$CI_KERNPART" || :
|
|
|
|
[ "$root_ubivol" ] && ubirmvol /dev/$ubidev -N "$CI_ROOTPART" || :
|
2022-04-13 13:51:34 +00:00
|
|
|
[ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || :
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-04-15 03:53:27 +00:00
|
|
|
# create kernel vol
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
if [ -n "$kernel_length" ]; then
|
2022-04-15 10:18:22 +00:00
|
|
|
if ! ubimkvol /dev/$ubidev -N "$CI_KERNPART" -s $kernel_length; then
|
2014-06-11 12:59:49 +00:00
|
|
|
echo "cannot create kernel volume"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-04-15 03:53:27 +00:00
|
|
|
# create rootfs vol
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
if [ -n "$rootfs_length" ]; then
|
2021-02-17 15:17:49 +00:00
|
|
|
local rootfs_size_param
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
if [ "$rootfs_type" = "ubifs" ]; then
|
2021-02-17 15:17:49 +00:00
|
|
|
rootfs_size_param="-m"
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
else
|
2021-02-17 15:17:49 +00:00
|
|
|
rootfs_size_param="-s $rootfs_length"
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
fi
|
2022-04-15 10:18:22 +00:00
|
|
|
if ! ubimkvol /dev/$ubidev -N "$CI_ROOTPART" $rootfs_size_param; then
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
echo "cannot create rootfs volume"
|
|
|
|
return 1;
|
|
|
|
fi
|
2014-06-11 12:59:49 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-15 03:53:27 +00:00
|
|
|
# create rootfs_data vol for non-ubifs rootfs
|
2014-06-16 18:55:14 +00:00
|
|
|
if [ "$rootfs_type" != "ubifs" ]; then
|
2021-02-17 15:17:49 +00:00
|
|
|
local rootfs_data_size_param="-m"
|
2022-02-17 15:10:00 +00:00
|
|
|
if [ -n "$rootfs_data_max" ]; then
|
2021-02-17 15:17:49 +00:00
|
|
|
rootfs_data_size_param="-s $rootfs_data_max"
|
|
|
|
fi
|
|
|
|
if ! ubimkvol /dev/$ubidev -N rootfs_data $rootfs_data_size_param; then
|
2022-02-17 15:10:00 +00:00
|
|
|
if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then
|
|
|
|
echo "cannot initialize rootfs_data volume"
|
|
|
|
return 1
|
|
|
|
fi
|
2014-06-11 12:59:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-04-15 13:15:02 +00:00
|
|
|
|
2014-06-11 12:59:49 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
# Write the UBI image to MTD ubi partition
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_upgrade_ubinized() {
|
|
|
|
local ubi_file="$1"
|
2022-05-03 10:09:33 +00:00
|
|
|
local gz="$2"
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-05-03 06:47:43 +00:00
|
|
|
nand_detach_ubi "$CI_UBIPART" || return 1
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-05-03 06:47:43 +00:00
|
|
|
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
2022-05-03 10:09:33 +00:00
|
|
|
${gz}cat "$ubi_file" | ubiformat "/dev/mtd$mtdnum" -y -f - && ubiattach -m "$mtdnum"
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
# Write the UBIFS image to UBI rootfs volume
|
2014-06-19 14:13:41 +00:00
|
|
|
nand_upgrade_ubifs() {
|
2022-05-03 10:09:33 +00:00
|
|
|
local ubifs_file="$1"
|
|
|
|
local gz="$2"
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-05-03 10:09:33 +00:00
|
|
|
local ubifs_length=$( (${gz}cat "$ubifs_file" | wc -c) 2> /dev/null)
|
|
|
|
|
|
|
|
nand_upgrade_prepare_ubi "$ubifs_length" "ubifs" "" "" || return 1
|
2017-05-03 06:27:40 +00:00
|
|
|
|
2014-06-19 14:13:41 +00:00
|
|
|
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
2022-04-15 10:18:22 +00:00
|
|
|
local root_ubivol="$(nand_find_volume $ubidev "$CI_ROOTPART")"
|
2022-05-03 10:09:33 +00:00
|
|
|
${gz}cat "$ubifs_file" | ubiupdatevol /dev/$root_ubivol -s "$ubifs_length" -
|
2014-06-19 14:13:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
# Write the FIT image to UBI kernel volume
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
nand_upgrade_fit() {
|
|
|
|
local fit_file="$1"
|
2022-05-03 10:09:33 +00:00
|
|
|
local gz="$2"
|
|
|
|
|
|
|
|
local fit_length=$( (${gz}cat "$fit_file" | wc -c) 2> /dev/null)
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
nand_upgrade_prepare_ubi "" "" "$fit_length" "1" || return 1
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
|
|
|
|
local fit_ubidev="$(nand_find_ubi "$CI_UBIPART")"
|
|
|
|
local fit_ubivol="$(nand_find_volume $fit_ubidev "$CI_KERNPART")"
|
2022-05-03 10:09:33 +00:00
|
|
|
${gz}cat "$fit_file" | ubiupdatevol /dev/$fit_ubivol -s "$fit_length" -
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
# Write images in the TAR file to MTD partitions and/or UBI volumes as required
|
2014-06-19 14:13:41 +00:00
|
|
|
nand_upgrade_tar() {
|
2014-06-16 18:55:14 +00:00
|
|
|
local tar_file="$1"
|
2022-05-03 10:09:33 +00:00
|
|
|
local gz="$2"
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
# WARNING: This fails if tar contains more than one 'sysupgrade-*' directory.
|
2022-05-03 10:09:33 +00:00
|
|
|
local board_dir="$(tar t${gz}f "$tar_file" | grep -m 1 '^sysupgrade-.*/$')"
|
2022-04-15 09:31:24 +00:00
|
|
|
board_dir="${board_dir%/}"
|
2014-06-17 15:40:02 +00:00
|
|
|
|
2022-04-15 09:31:24 +00:00
|
|
|
local kernel_mtd kernel_length
|
|
|
|
if [ "$CI_KERNPART" != "none" ]; then
|
|
|
|
kernel_mtd="$(find_mtd_index "$CI_KERNPART")"
|
2022-05-04 02:54:58 +00:00
|
|
|
kernel_length=$( (tar xO${gz}f "$tar_file" "$board_dir/kernel" | wc -c) 2> /dev/null)
|
2022-04-15 09:31:24 +00:00
|
|
|
[ "$kernel_length" = 0 ] && kernel_length=
|
|
|
|
fi
|
2022-05-04 02:54:58 +00:00
|
|
|
local rootfs_length=$( (tar xO${gz}f "$tar_file" "$board_dir/root" | wc -c) 2> /dev/null)
|
2022-04-15 09:31:24 +00:00
|
|
|
[ "$rootfs_length" = 0 ] && rootfs_length=
|
image: add support for building FIT image with filesystem
Allow for single (external-data) FIT image to hold kernel, dtb and
squashfs. In that way, the bootloader verifies the system integrity
including the rootfs, because what's the point of checking that the
hash of the kernel is correct if it won't boot in case of squashfs
being corrupted? Better allow bootloader to check everything needed
to make it at least up to failsafe mode. As a positive side effect
this change also makes the sysupgrade process on nand potentially
much easier as it is now.
In short: mkimage has a parameter '-E' which allows generating FIT
images with 'external' data rather than embedding the data into the
device-tree blob itself. In this way, the FIT structure itself remains
small and can be parsed easily (rather than having to page around
megabytes of image content). This patch makes use of that and adds
support for adding sub-images of type 'filesystem' which are used to
store the squashfs. Now U-Boot can verify the whole OS and the new
partition parsers added in the Linux kernel can detect the filesystem
sub-images, create partitions for them, and select the active rootfs
volume based on the configuration in FIT (passing configuration via
device tree could be implemented easily at a later stage).
This new FIT partition parser works for NOR flash (on top of mtdblock),
NAND flash (on top of ubiblock) as well as classic block devices
(ie. eMMC, SDcard, SATA, NVME, ...).
It could even be used to mount such FIT images via `losetup -P` on a
user PC if this patch gets included in Linux upstream one day ;)
Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-15 14:37:17 +00:00
|
|
|
local rootfs_type
|
2022-05-03 10:09:33 +00:00
|
|
|
[ "$rootfs_length" ] && rootfs_type="$(identify_tar "$tar_file" "$board_dir/root" "$gz")"
|
2017-04-07 06:39:59 +00:00
|
|
|
|
2022-04-15 09:31:24 +00:00
|
|
|
local ubi_kernel_length
|
|
|
|
if [ "$kernel_length" ]; then
|
|
|
|
if [ "$kernel_mtd" ]; then
|
2022-05-02 08:33:01 +00:00
|
|
|
# On some devices, the raw kernel and ubi partitions overlap.
|
|
|
|
# These devices brick if the kernel partition is erased.
|
|
|
|
# Hence only invalidate kernel for now.
|
2022-05-04 02:54:58 +00:00
|
|
|
dd if=/dev/zero bs=4096 count=1 2> /dev/null | \
|
2022-05-02 08:33:01 +00:00
|
|
|
mtd write - "$CI_KERNPART"
|
2022-04-15 09:31:24 +00:00
|
|
|
else
|
|
|
|
ubi_kernel_length="$kernel_length"
|
|
|
|
fi
|
|
|
|
fi
|
2014-06-16 18:55:14 +00:00
|
|
|
local has_env=0
|
2022-05-03 06:31:48 +00:00
|
|
|
nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$ubi_kernel_length" "$has_env" || return 1
|
2014-06-16 18:55:14 +00:00
|
|
|
|
|
|
|
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
2022-04-15 09:31:24 +00:00
|
|
|
if [ "$rootfs_length" ]; then
|
|
|
|
local root_ubivol="$( nand_find_volume $ubidev "$CI_ROOTPART" )"
|
2022-05-04 02:54:58 +00:00
|
|
|
tar xO${gz}f "$tar_file" "$board_dir/root" | \
|
2022-05-03 10:09:33 +00:00
|
|
|
ubiupdatevol /dev/$root_ubivol -s "$rootfs_length" -
|
2022-04-15 09:31:24 +00:00
|
|
|
fi
|
|
|
|
if [ "$kernel_length" ]; then
|
|
|
|
if [ "$kernel_mtd" ]; then
|
2022-05-04 02:54:58 +00:00
|
|
|
tar xO${gz}f "$tar_file" "$board_dir/kernel" | \
|
2022-05-02 08:33:01 +00:00
|
|
|
mtd write - "$CI_KERNPART"
|
2022-04-15 09:31:24 +00:00
|
|
|
else
|
|
|
|
local kern_ubivol="$( nand_find_volume $ubidev "$CI_KERNPART" )"
|
2022-05-04 02:54:58 +00:00
|
|
|
tar xO${gz}f "$tar_file" "$board_dir/kernel" | \
|
2022-05-03 10:09:33 +00:00
|
|
|
ubiupdatevol /dev/$kern_ubivol -s "$kernel_length" -
|
2022-04-15 09:31:24 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-04-15 03:59:49 +00:00
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
return 0
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 02:54:58 +00:00
|
|
|
nand_verify_if_gzip_file() {
|
|
|
|
local file="$1"
|
|
|
|
local gz="$2"
|
|
|
|
|
|
|
|
if [ "$gz" = z ]; then
|
|
|
|
echo "verifying compressed sysupgrade file integrity"
|
|
|
|
if ! gzip -t "$file"; then
|
|
|
|
echo "corrupted compressed sysupgrade file"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
nand_verify_tar_file() {
|
|
|
|
local file="$1"
|
|
|
|
local gz="$2"
|
|
|
|
|
|
|
|
echo "verifying sysupgrade tar file integrity"
|
|
|
|
if ! tar xO${gz}f "$file" > /dev/null; then
|
|
|
|
echo "corrupted sysupgrade tar file"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
nand_do_flash_file() {
|
2022-05-03 10:09:33 +00:00
|
|
|
local file="$1"
|
|
|
|
|
|
|
|
local gz="$(identify_if_gzip "$file")"
|
|
|
|
local file_type="$(identify "$file" "" "$gz")"
|
|
|
|
|
2022-04-15 09:42:51 +00:00
|
|
|
[ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART=rootfs
|
2014-06-19 14:13:41 +00:00
|
|
|
|
2014-11-24 19:14:29 +00:00
|
|
|
case "$file_type" in
|
2022-05-04 02:54:58 +00:00
|
|
|
"fit")
|
|
|
|
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
|
|
|
nand_upgrade_fit "$file" "$gz"
|
|
|
|
;;
|
|
|
|
"ubi")
|
|
|
|
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
|
|
|
nand_upgrade_ubinized "$file" "$gz"
|
|
|
|
;;
|
|
|
|
"ubifs")
|
|
|
|
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
|
|
|
nand_upgrade_ubifs "$file" "$gz"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
nand_verify_tar_file "$file" "$gz" || return 1
|
|
|
|
nand_upgrade_tar "$file" "$gz"
|
|
|
|
;;
|
2014-11-24 19:14:29 +00:00
|
|
|
esac
|
2014-06-19 14:13:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
nand_do_restore_config() {
|
|
|
|
local conf_tar="/tmp/sysupgrade.tgz"
|
|
|
|
[ ! -f "$conf_tar" ] || nand_restore_config "$conf_tar"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Recognize type of passed file and start the upgrade process
|
|
|
|
nand_do_upgrade() {
|
2022-05-03 10:09:33 +00:00
|
|
|
local file="$1"
|
|
|
|
|
2022-05-03 06:31:48 +00:00
|
|
|
sync
|
2022-05-03 10:09:33 +00:00
|
|
|
if nand_do_flash_file "$file" && nand_do_restore_config && sync; then
|
2022-05-03 06:31:48 +00:00
|
|
|
echo "sysupgrade successful"
|
|
|
|
umount -a
|
|
|
|
reboot -f
|
|
|
|
fi
|
|
|
|
|
|
|
|
sync
|
|
|
|
echo "sysupgrade failed"
|
|
|
|
# Should we reboot or bring up some failsafe mode instead?
|
|
|
|
umount -a
|
|
|
|
reboot -f
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if passed file is a valid one for NAND sysupgrade.
|
|
|
|
# Currently it accepts 4 types of files:
|
|
|
|
# 1) UBI: a ubinized image containing required UBI volumes.
|
|
|
|
# 2) UBIFS: a UBIFS rootfs volume image.
|
|
|
|
# 3) FIT: a FIT image containing kernel and rootfs.
|
|
|
|
# 4) TAR: an archive that includes directory "sysupgrade-${BOARD_NAME}" containing
|
|
|
|
# a non-empty "CONTROL" file and required partition and/or volume images.
|
2014-11-24 19:14:17 +00:00
|
|
|
#
|
|
|
|
# You usually want to call this function in platform_check_image.
|
|
|
|
#
|
2014-11-28 19:13:24 +00:00
|
|
|
# $(1): board name, used in case of passing TAR file
|
2014-11-24 19:14:17 +00:00
|
|
|
# $(2): file to be checked
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_do_platform_check() {
|
|
|
|
local board_name="$1"
|
2022-05-03 10:09:33 +00:00
|
|
|
local file="$2"
|
|
|
|
|
|
|
|
local gz="$(identify_if_gzip "$file")"
|
|
|
|
local file_type="$(identify "$file" "" "$gz")"
|
2022-05-04 02:54:58 +00:00
|
|
|
local control_length=$( (tar xO${gz}f "$file" "sysupgrade-$board_name/CONTROL" | wc -c) 2> /dev/null)
|
2014-06-19 14:13:41 +00:00
|
|
|
|
2022-05-04 02:54:58 +00:00
|
|
|
if [ "$control_length" != 0 ]; then
|
|
|
|
nand_verify_tar_file "$file" "$gz" || return 1
|
|
|
|
else
|
|
|
|
nand_verify_if_gzip_file "$file" "$gz" || return 1
|
|
|
|
if [ "$file_type" != "fit" -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ]; then
|
|
|
|
echo "invalid sysupgrade file"
|
|
|
|
return 1
|
|
|
|
fi
|
2022-05-03 10:09:33 +00:00
|
|
|
fi
|
2014-06-16 18:55:14 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|