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() {
|
2014-06-16 18:55:14 +00:00
|
|
|
dd if="$1" skip=$2 bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
get_magic_long_tar() {
|
|
|
|
( tar xf $1 $2 -O | 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"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown $magic"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
identify() {
|
2014-07-13 20:51:17 +00:00
|
|
|
identify_magic $(nand_get_magic_long "$1" "${2:-0}")
|
2014-06-16 18:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
identify_tar() {
|
|
|
|
identify_magic $(get_magic_long_tar "$1" "$2")
|
|
|
|
}
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_restore_config() {
|
|
|
|
sync
|
|
|
|
local ubidev=$( nand_find_ubi $CI_UBIPART )
|
|
|
|
local ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
|
|
|
[ ! "$ubivol" ] &&
|
2019-01-01 00:15:34 +00:00
|
|
|
ubivol="$( nand_find_volume $ubidev $CI_ROOTPART )"
|
2014-06-16 18:55:14 +00:00
|
|
|
mkdir /tmp/new_root
|
|
|
|
if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
|
|
|
|
echo "mounting ubifs $ubivol failed"
|
|
|
|
rmdir /tmp/new_root
|
|
|
|
return 1
|
|
|
|
fi
|
2019-09-04 14:57:39 +00:00
|
|
|
mv "$1" "/tmp/new_root/$BACKUP_FILE"
|
2014-06-16 18:55:14 +00:00
|
|
|
umount /tmp/new_root
|
|
|
|
sync
|
|
|
|
rmdir /tmp/new_root
|
|
|
|
}
|
|
|
|
|
|
|
|
nand_upgrade_prepare_ubi() {
|
|
|
|
local rootfs_length="$1"
|
2014-06-19 14:13:41 +00:00
|
|
|
local rootfs_type="$2"
|
2021-02-17 15:17:49 +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"
|
|
|
|
sync
|
|
|
|
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"
|
|
|
|
sync
|
|
|
|
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
|
|
|
|
2017-05-30 20:03:39 +00:00
|
|
|
local kern_ubivol="$( nand_find_volume $ubidev $CI_KERNPART )"
|
2019-01-01 00:15:34 +00:00
|
|
|
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 )"
|
|
|
|
|
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 ubiblk ubiblkvol
|
2022-04-13 13:51:34 +00:00
|
|
|
for ubiblk in /dev/ubiblock${ubidev:3}_* ; do
|
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
|
|
|
[ -e "$ubiblk" ] || continue
|
2022-04-13 13:51:34 +00:00
|
|
|
case "$ubiblk" in
|
|
|
|
/dev/ubiblock*_*p*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
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 "removing ubiblock${ubiblk:13}"
|
|
|
|
ubiblkvol=ubi${ubiblk:13}
|
|
|
|
if ! ubiblock -r /dev/$ubiblkvol; then
|
|
|
|
echo "cannot remove $ubiblk"
|
|
|
|
return 1
|
2014-06-11 12:59:49 +00:00
|
|
|
fi
|
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
|
|
|
done
|
2014-06-11 12:59:49 +00:00
|
|
|
|
|
|
|
# kill volumes
|
2022-04-13 13:51:34 +00:00
|
|
|
[ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N $CI_KERNPART || :
|
|
|
|
[ "$root_ubivol" -a "$root_ubivol" != "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N $CI_ROOTPART || :
|
|
|
|
[ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || :
|
2014-06-11 12:59:49 +00:00
|
|
|
|
|
|
|
# update kernel
|
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
|
2017-05-30 20:03:39 +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
|
|
|
|
|
|
|
|
# update rootfs
|
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
|
|
|
|
if ! ubimkvol /dev/$ubidev -N $CI_ROOTPART $rootfs_size_param; then
|
|
|
|
echo "cannot create rootfs volume"
|
|
|
|
return 1;
|
|
|
|
fi
|
2014-06-11 12:59:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create rootfs_data 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
|
|
|
|
sync
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_do_upgrade_success() {
|
|
|
|
local conf_tar="/tmp/sysupgrade.tgz"
|
2017-05-03 06:27:40 +00:00
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
sync
|
|
|
|
[ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
|
2014-07-10 19:16:31 +00:00
|
|
|
echo "sysupgrade successful"
|
2016-08-02 20:29:31 +00:00
|
|
|
umount -a
|
2014-06-16 18:55:14 +00:00
|
|
|
reboot -f
|
|
|
|
}
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-11-24 19:14:17 +00:00
|
|
|
# Flash the UBI image to MTD partition
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_upgrade_ubinized() {
|
|
|
|
local ubi_file="$1"
|
|
|
|
local mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-06-19 14:13:41 +00:00
|
|
|
[ ! "$mtdnum" ] && {
|
|
|
|
CI_UBIPART="rootfs"
|
|
|
|
mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
|
|
|
}
|
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
if [ ! "$mtdnum" ]; then
|
|
|
|
echo "cannot find mtd device $CI_UBIPART"
|
2016-08-02 20:29:31 +00:00
|
|
|
umount -a
|
2014-06-17 15:40:02 +00:00
|
|
|
reboot -f
|
2014-06-16 18:55:14 +00:00
|
|
|
fi
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
local mtddev="/dev/mtd${mtdnum}"
|
|
|
|
ubidetach -p "${mtddev}" || true
|
|
|
|
sync
|
|
|
|
ubiformat "${mtddev}" -y -f "${ubi_file}"
|
|
|
|
ubiattach -p "${mtddev}"
|
|
|
|
nand_do_upgrade_success
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 19:14:17 +00:00
|
|
|
# Write the UBIFS image to UBI volume
|
2014-06-19 14:13:41 +00:00
|
|
|
nand_upgrade_ubifs() {
|
2020-05-10 14:20:55 +00:00
|
|
|
local rootfs_length=$( (cat $1 | wc -c) 2> /dev/null)
|
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
|
|
|
nand_upgrade_prepare_ubi "$rootfs_length" "ubifs" "" ""
|
2017-05-03 06:27:40 +00:00
|
|
|
|
2014-06-19 14:13:41 +00:00
|
|
|
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
2019-01-01 00:15:34 +00:00
|
|
|
local root_ubivol="$(nand_find_volume $ubidev $CI_ROOTPART)"
|
2014-06-19 14:13:41 +00:00
|
|
|
ubiupdatevol /dev/$root_ubivol -s $rootfs_length $1
|
|
|
|
|
|
|
|
nand_do_upgrade_success
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
local fit_length="$(wc -c < "$fit_file")"
|
|
|
|
|
|
|
|
nand_upgrade_prepare_ubi "" "" "$fit_length" "1"
|
|
|
|
|
|
|
|
local fit_ubidev="$(nand_find_ubi "$CI_UBIPART")"
|
|
|
|
local fit_ubivol="$(nand_find_volume $fit_ubidev "$CI_KERNPART")"
|
|
|
|
ubiupdatevol /dev/$fit_ubivol -s $fit_length $fit_file
|
|
|
|
|
|
|
|
nand_do_upgrade_success
|
|
|
|
}
|
|
|
|
|
2014-06-19 14:13:41 +00:00
|
|
|
nand_upgrade_tar() {
|
2014-06-16 18:55:14 +00:00
|
|
|
local tar_file="$1"
|
2014-07-14 14:53:15 +00:00
|
|
|
local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
|
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
|
|
|
local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
|
2017-04-07 06:39:59 +00:00
|
|
|
board_dir=${board_dir%/}
|
2014-06-17 15:40:02 +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
|
|
|
kernel_length=$( (tar xf "$tar_file" ${board_dir}/kernel -O | wc -c) 2> /dev/null)
|
|
|
|
local has_rootfs=0
|
|
|
|
local rootfs_length
|
|
|
|
local rootfs_type
|
2017-04-07 06:39:59 +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
|
|
|
tar tf "$tar_file" ${board_dir}/root 1>/dev/null 2>/dev/null && has_rootfs=1
|
|
|
|
[ "$has_rootfs" = "1" ] && {
|
|
|
|
rootfs_length=$( (tar xf "$tar_file" ${board_dir}/root -O | wc -c) 2> /dev/null)
|
|
|
|
rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
|
|
|
|
}
|
2014-06-17 15:40:02 +00:00
|
|
|
|
2014-06-16 18:55:14 +00:00
|
|
|
local has_kernel=1
|
|
|
|
local has_env=0
|
2014-06-11 12:59:49 +00:00
|
|
|
|
2014-11-24 19:14:29 +00:00
|
|
|
[ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
|
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
|
|
|
tar xf "$tar_file" ${board_dir}/kernel -O | mtd write - $CI_KERNPART
|
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
|
|
|
[ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=
|
2021-09-20 17:13:43 +00:00
|
|
|
[ "$CI_KERNPART" = "none" ] && has_kernel=
|
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
|
|
|
nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "${has_kernel:+$kernel_length}" "$has_env"
|
2014-06-16 18:55:14 +00:00
|
|
|
|
|
|
|
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
|
|
|
[ "$has_kernel" = "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 kern_ubivol="$( nand_find_volume $ubidev $CI_KERNPART )"
|
|
|
|
tar xf "$tar_file" ${board_dir}/kernel -O | \
|
2014-06-24 18:13:56 +00:00
|
|
|
ubiupdatevol /dev/$kern_ubivol -s $kernel_length -
|
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
|
|
|
[ "$has_rootfs" = "1" ] && {
|
|
|
|
local root_ubivol="$( nand_find_volume $ubidev $CI_ROOTPART )"
|
|
|
|
tar xf "$tar_file" ${board_dir}/root -O | \
|
|
|
|
ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
|
|
|
|
}
|
2014-06-16 18:55:14 +00:00
|
|
|
nand_do_upgrade_success
|
2014-06-11 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 19:14:17 +00:00
|
|
|
# Recognize type of passed file and start the upgrade process
|
2017-04-21 22:54:50 +00:00
|
|
|
nand_do_upgrade() {
|
2014-06-19 14:13:41 +00:00
|
|
|
local file_type=$(identify $1)
|
|
|
|
|
|
|
|
[ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
|
|
|
|
|
2014-11-24 19:14:29 +00:00
|
|
|
case "$file_type" in
|
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
|
|
|
"fit") nand_upgrade_fit $1;;
|
2014-11-24 19:14:29 +00:00
|
|
|
"ubi") nand_upgrade_ubinized $1;;
|
|
|
|
"ubifs") nand_upgrade_ubifs $1;;
|
|
|
|
*) nand_upgrade_tar $1;;
|
|
|
|
esac
|
2014-06-19 14:13:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 19:14:17 +00:00
|
|
|
# Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
|
|
|
|
# 3 types of files:
|
|
|
|
# 1) UBI - should contain an ubinized image, header is checked for the proper
|
|
|
|
# MAGIC
|
|
|
|
# 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
|
|
|
|
# header is checked for the proper MAGIC
|
2014-11-28 19:13:24 +00:00
|
|
|
# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
|
2014-11-24 19:14:17 +00:00
|
|
|
# "CONTROL" file (at this point its content isn't verified)
|
|
|
|
#
|
|
|
|
# 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"
|
|
|
|
local tar_file="$2"
|
2020-05-10 14:20:55 +00:00
|
|
|
local control_length=$( (tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null)
|
2014-06-19 14:13:41 +00:00
|
|
|
local file_type="$(identify $2)"
|
|
|
|
|
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
|
|
|
[ "$control_length" = 0 -a "$file_type" != "ubi" -a "$file_type" != "ubifs" -a "$file_type" != "fit" ] && {
|
2014-06-16 18:55:14 +00:00
|
|
|
echo "Invalid sysupgrade file."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|