aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib/upgrade
Commit message (Collapse)AuthorAgeFilesLines
* base-files: redirect kill ouptut for ash, telnetd and dropbearFlorian Eckert2021-06-201-3/+3
| | | | | | | | | | | If one of the programmes is not running, then we see the following output in the logs. `killall: telnetd: no process killed` To ensure that the log is clean, redirect the output to /dev/null Signed-off-by: Florian Eckert <fe@dev.tdt.de>
* base-files: remove unused vn and _vn functionFlorian Eckert2021-06-201-8/+0
| | | | | | | The remaining vn calls have been ported to v. Therefore, these functions are no longer needed and will be removed. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
* base-files: change logging for upgrade on stage2Florian Eckert2021-06-201-4/+2
| | | | | | | Remove vn call in favour of v call. This commit serves as preparation for removing the vn function call. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
* base-files: add syslog logging for v functionFlorian Eckert2021-06-202-1/+2
| | | | | | | | The logging output should not only be displayed in the calling shell session but also in the syslog. A sysupgrade and a configuration import, export can thus be traced in the syslog. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
* base-files: upgrade: use zcat command provided by busyboxChuck Fan2021-06-201-1/+1
| | | | | | | | | | | Calling `switch_to_ramfs()` will not copy the gzip executable (/bin/gzip) to ramfs, but `/bin/zcat` will call `/bin/gzip` when package gzip is installed, instead of the busybox-supplied zcat. This will cause `zcat` to fail to find `gzip`, then cause the sysupgrade to fail. Adding the `busybox` prefix here will solve the problem. Signed-off-by: Chuck Fan <fanck0605@qq.com>
* busybox: disable bzip2Sergey Ponomarev2021-06-202-2/+1
| | | | | | | | | | bzip2 adds about 8kb of size. For tiny builds it's often disabled. It's not directly used by stock OpenWrt programs. Kernel images compressed with bzip2 are also not fully supported. Signed-off-by: Sergey Ponomarev <stokito@gmail.com> [fix \ indention] Signed-off-by: Paul Spooren <mail@aparcar.org>
* base-files: upgrade: use procd to kill managed daemonsMichael Pratt2021-06-121-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | These processes are managed by procd and set to start again when killed via the procd instance parameter "respawn" being set during init. Example: procd_set_param respawn 3600 1 0 When they are killed manually during sysupgrade, they are started again in 5 seconds or less, depending on how the "respawn" parameter is set. Use procd through ubus to disable the instances that respawn them, however, allow dnsmasq, netifd, and logd to restart for remote logging. Properly closing all these processes increases free memory by about 3 MB, which should help low memory devices upgrade without crashing. For very low memory devices (set to 32 MB for now) also kill dnsmasq, netifd, and logd for an additional 3 MB of free memory. Also, bump sleep values to allow at least 10 seconds for network interfaces and daemons to come up after they are killed and restarted before caches are dropped. Signed-off-by: Michael Pratt <mcpratt@pm.me>
* base-files: change logging for upgrade on fwtoolFlorian Eckert2021-05-171-3/+3
| | | | | | | | | Remove vn call in favour of v call. This commit serves as preparation for removing the v function call. Signed-off-by: Florian Eckert <fe@dev.tdt.de> [alter slightly to prevent double space after colon] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: upgrade: take down loop and LVM before upgradeDaniel Golle2021-05-051-0/+10
| | | | | | | | | | | | | | Users of devices with large block storage may choose to have an LVM partition on the same device which is used for booting OpenWrt. The presents a problem during sysupgrade as the root device is then still busy and changing partitions will not work as desired, leading to data corruption in case the newly flashed image is larger than the currently installed one. Having loop devices setup causes similar havoc. Make sure all volume groups are offline and all loop devices have been released before sysupgrade. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: functions: introduce new helper functionsDaniel Golle2021-03-311-63/+58
| | | | | | | | | | | Introduce cmdline_get_var() to /lib/function.sh and make use of it in export_rootdev() in /lib/upgrade/common.sh, making the code more simple and removing one level of indentation. Introduce get_partition_by_name() to /lib/upgrade/common.sh which is useful on non-EFI GPT platforms like mt7622. Remove some dead-code while at it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: remove unneeded '$' signs in nand.shDaniel Golle2021-02-241-2/+2
| | | | | | | When using Shell arithmetric evaluation via $((..)) the variables in the expression do not need to be prefixed by the '$' sign. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* sysupgrade-nand: allow limiting rootfs_data by setting env variableDaniel Golle2021-02-241-4/+16
| | | | | | | | | | | | | | | | | Check if firmware environment variable 'rootfs_data_max' exists and is set to a numerical value greater than 0. If so, limit rootfs_data volume to that size instead of using the maximum available size. This is useful on devices with lots of flash where users may want to have eg. a volume for persistent logs and statistics or for external applications/containers. Persistence on rootfs overlay is limited by the size of memory available during the sysugprade process as that data needs to be copied to RAM while the volume is being recreated during sysupgrade. Hence it is unsuitable for keeping larger amounts of data accross upgrade which makes additional volume(s) for application data desirable. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* image: add support for building FIT image with filesystemDaniel Golle2021-02-241-37/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* treewide: drop shebang from non-executable lib filesAdrian Schmutzler2021-01-292-3/+0
| | | | | | | | | | | | This drops the shebang from another bunch of files in various /lib folders, as these are sourced and the shebang is useless. Fix execute bit in one case, too. This should cover almost all trivial cases now, i.e. where /lib is actually used for library files. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: read all 3 bytes in get_magic_vfat() at onceAdrian Schmutzler2021-01-071-1/+1
| | | | | | | While the speed improvement might be negligible, there is still no reason to read individual bytes. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* x86/efi: add FAT32 esp mounting supportKagurazaka Kotori2021-01-031-1/+6
| | | | | | | | | Adds a new function get_magic_fat32() in base-files to read FAT32 magic. Now FAT32 EFI system partition can be handled in the same way as FAT12/FAT16. Signed-off-by: Kagurazaka Kotori <kagurazakakotori@gmail.com> [replace '-o' with '] || [' to satisfy shellsheck] Signed-off-by: Paul Spooren <mail@aparcar.org>
* base-files: flush kernel memory cache during sysupgradeHannu Nyman2020-12-222-0/+2
| | | | | | | | | | | Flush kernel memory caches during sysupgrade in order to mitigate the impact from memory consumption spikes in low-RAM devices. This may help to prevent sysupgrade causing a reboot before the actual flashing starts. Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
* base-files: upgrade: stage2: use v for log linesYousong Zhou2020-11-111-7/+7
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: upgrade: fwtool.sh: rewording logsYousong Zhou2020-11-111-2/+2
| | | | | | | | | | The intent is to make it sound more like info level message, not some error like "404 not found". x86 target at the moment makes image with only signature but no metadata (ref commit f8141216 "x86: append metadata to combined images"). Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Reviewed-By: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: upgrade: fwtool.sh: use v for log linesYousong Zhou2020-11-111-13/+13
| | | | | | | | | This will have at least the following effects - Log lines will have common prefix - They will be output to stderr instead of stdout Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: upgrade: add get_image_dd()Yousong Zhou2020-11-111-0/+11
| | | | | | | | | | This is mainly to handle stderr message "Broken pipe", "F+P records in/out" by common pattern "xcat | dd .." Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3140 Reported-by: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Reviewed-By: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: upgrade: use stdin redirection to replace cat commandYousong Zhou2020-11-111-1/+1
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: upgrade: add vn and variantsYousong Zhou2020-11-111-1/+13
| | | | | | | | | | | | To be used with in the following pattern vn "Remaining: " for p in $xx; do _vn "$p" done _v Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: upgrade: log with date prefixYousong Zhou2020-11-112-2/+2
| | | | | | And log to stderr Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: remove block2mtd checks from sysupgradeFelix Fietkau2020-10-171-4/+0
| | | | | | This hasn't been used in a long time Signed-off-by: Felix Fietkau <nbd@nbd.name>
* treewide: replace `which` with `command -v`Paul Spooren2020-08-121-1/+1
| | | | | | | | | | | | | | | | | Fix shellcheck SC2230 > which is non-standard. Use builtin 'command -v' instead. Using `command -v` is POSIX compliant while `which` is not. Also to mention, `command -v` is a shell builtin whereas `which` is a separate busybox applet. Once applied to everything concerning OpenWrt we can disable the busybox feature `which` and save 3.8kB. Acked-by: Stijn Tintel <stijn@linux-ipv6.be> Signed-off-by: Paul Spooren <mail@aparcar.org> [also replace cases in zram-swap] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: fwtool: make compat_version backward compatibleAdrian Schmutzler2020-07-311-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, the compatibility mechanism only works if both device and image are already updated to the new routines. This patch extends the sysupgrade metadata and fwtool_check_image() to account for "older" images as well: The basic mechanism for older devices to check for image compatibility is the supported_devices entry. This can be exploited by putting a custom message into this variable of the metadata, so older FW will produce a mismatch and print the message as it thinks it's the list of supported devices. So, we have two cases: device 1.0, image 1.0: The metadata will just contain supported_devices as before. device 1.0, image 1.1: The metadata will contain: "new_supported_devices":["device_string1", "device_string2", ...], "supported_devices":["Image version 1.1 incompatible to device: ..."] If the device is "legacy", i.e. does not have the updated fwtool.sh, it will just fail with image check and print the content of supported_devices. If DEVICE_COMPAT_MESSAGE is set, this will be printed on old devices as well through the same mechanism. Otherwise a generic "Please check documentation ..." is appended. Upgrade can still be performed with -F like when SUPPORTED_DEVICES has been removed to prevent bricking. If the device has updated fwtool.sh (but is 1.0), it will just use the new_supported_devices instead, and work as intended (flashing with -n will work, flashing without will print the appropriate warning). This mechanism should provide a fair tradeoff between simplicity and functionality. Since we touched a lot of fields in metadata, this also bumps metadata_version to 1.1. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: fwtool: implement compatibility check for imagesAdrian Schmutzler2020-07-311-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We regularly encounter the situation that devices are subject to changes that will make them incompatible to previous versions. Removing SUPPORTED_DEVICES will not really be helpful in most of these cases, as this only helps after a rename. To solve this situation, this patchset introduces a compatibility version for devices. In this patch, the actual checks are implemented into fwtool_check_image(): If an incompatible change is introduced, one can increase either the minor version (1.0->1.1) or the major version (1.0->2.0). Minor version increment: This will still allow sysupgrade, but require to reset config (-n or SAVE_CONFIG=0). If sysupgrade is called without -n, a corresponding message will be printed. If sysupgrade is called with -n, it will just pass, with supported devices being checked as usual. (Which will allow us to add back SUPPORTED_DEVICES for many cases.) Major version increment: This is meant for potential (rare) cases where sysupgrade is not possible at all, because it would break the device. In this case, a warning will be printed, and -n won't help. If image check fails because of one of the versions parts not matching, the content of DEVICE_COMPAT_MESSAGE is printed in addition to the generic message (if set). For both cases, upgrade can still be forced with -F as usual. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: replace backticks in lib/upgrade/nand.shAdrian Schmutzler2020-07-151-4/+4
| | | | | | This replaces deprecated backticks by more versatile $(...) syntax. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: switch_to_ramfs: add nand-utilsÁlvaro Fernández Rojas2020-05-181-1/+1
| | | | Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
* base-files: upgrade: fix indentJavier Marcet2020-05-081-2/+2
| | | | | | | | Use same indent as for the rest of the file. Signed-off-by: Javier Marcet <javier@marcet.info> [add commit description] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: ensure VERBOSE is setAlexander Couzens2020-04-211-1/+1
| | | | | | | If not set, it shows the following error sh: out of range Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* treewide: convert sed -r to posix -EKevin Darbyshire-Bryant2020-04-041-1/+1
| | | | Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
* x86: generate EFI platform bootable images李国2020-03-311-8/+54
| | | | | | | | | | | | | | | | | Add EFI platform bootable images for x86 platforms. These images can also boot from legacy BIOS platform. EFI System Partition need to be fat12/fat16/fat32 (not need to load filesystem drivers), so the first partition of EFI images are not ext4 filesystem any more. GPT partition table has an alternate partition table, we did not generate it. This may cause problems when use these images as qemu disk (kernel can not find rootfs), we pad enough sectors will be ok. Signed-off-by: 李国 <uxgood.org@gmail.com> [part_magic_* refactoring, removed genisoimage checks] Signed-off-by: Petr Štetiar <ynezz@true.cz>
* base-files: Add /etc/shinit for non-login shell initJeffery To2020-03-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because /etc/profile (and ~/.profile) are read by login shells only, aliases and functions defined there are not available to non-login shells, e.g. when using screen or tmux. If the ENV environment variable exists (exported by /etc/profile or ~/.profile) and references an existing file, then all interactive shells (login or non-login) will read that file as well. This sets the ENV environment variable in /etc/profile, pointing to /etc/shinit. This also adds /etc/shinit, which: * Contains alias and function definitions originally in /etc/profile * Sources /etc/mkshrc if the user is using mksh (also originally in /etc/profile), as /etc/mkshrc is meant for all interactive shells * Sources ~/.mkshrc if the user is using mksh, to compensate for the fact that mksh will not read ~/.mkshrc if ENV is set * Sources ~/.shinit if the user is not using mksh This also removes the shebang from /etc/profile, as the file is sourced, not executed. Signed-off-by: Jeffery To <jeffery.to@gmail.com>
* base-files: add /usr/share/libubox/jshn.sh to sysupgrade stage2Russell Senior2019-11-131-1/+1
| | | | | | | | Discovered recent changes had broken sysupgrade for ar71xx mikrotik rb-493g, traced the problem to missing /usr/share/libubox/jshn.sh after switching to tmpfs. Signed-off-by: Russell Senior <russell@personaltelco.net>
* base-files: upgrade: add case to export_bootdeviceKlaus Kudielka2019-10-091-1/+13
| | | | | | | | | | | The factory uboot of the Turris Omnia boots with "root=b301", and we instruct new users to sysupgrade from there (e.g. method 1, step 7). Currently, this will fail with "Unable to determine upgrade device". Add a new case to export_bootdevice, which parses the hex argument. Fixes commit 2e5a0b81 ("mvebu: sysupgrade: sdcard: keep user added ...") Signed-off-by: Klaus Kudielka <klaus.kudielka@gmail.com>
* treewide: sysupgrade: use $UPGRADE_BACKUP to check for backupRafał Miłecki2019-09-112-2/+2
| | | | | | | Now that $UPGRADE_BACKUP is set conditionally there is no need to check the $UPGRADE_OPT_SAVE_CONFIG anymore. All conditions can be simplified. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* treewide: use new procd sysupgrade $UPGRADE_BACKUP variableRafał Miłecki2019-09-052-2/+1
| | | | | | | | | | It's a variable set by procd that should replace hardcoded /tmp/sysupgrade.tgz. This change requires the most recent procd with the commit 0f3c136 ("sysupgrade: set UPGRADE_BACKUP env variable"). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* treewide: don't hardcode "sysupgrade.tgz" file nameRafał Miłecki2019-09-052-1/+3
| | | | | | | | 1) Add BACKUP_FILE and use it when copying an archive to be restored after sysupgrade (on the next preinit). 2) Use CONF_TAR for copying backup prepared by the /sbin/sysupgrade Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* treewide: sysupgrade: pass "save_partitions" option to the "sysupgrade" methodRafał Miłecki2019-08-221-5/+0
| | | | | | | This explicitly lets stage2 know if partitions should be preserved. No more "touch /tmp/sysupgrade.always.overwrite.bootdisk.partmap" hack. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: pass "save_config" option to the "sysupgrade" methodRafał Miłecki2019-08-223-4/+2
| | | | | | This explicitly lets stage2 know if config should be preserved. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: drop support for the platform_nand_pre_upgrade()Rafał Miłecki2019-07-221-4/+0
| | | | | | | No target uses it anymore. All code from that callback was moved into the platform_do_upgrade(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: don't set ARGV and ARGCRafał Miłecki2019-07-171-3/+0
| | | | | | Those are not used by any image check function anymore. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: move stage2 upgrade to separated fileRafał Miłecki2019-07-113-23/+26
| | | | | | | | | do_upgrade_stage2() isn't really any common code. It isn't used anywhere except for /sbin/sysupgrade that passes it to the stage2. Moving its code to separated file also simplifies COMMAND variable. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: drop support for NAND upgrade in platform_pre_upgrade()Rafał Miłecki2019-07-083-16/+2
| | | | | | | With bcm53xx switched to the new procedure there is no more need for keeping that backward compatibility code. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: drop unused jffs2_copy_config()Rafał Miłecki2019-07-081-10/+0
| | | | | | | | Its last usage was dropped back in 2013 in the commit b95bdc8ab56e ("kernel/base-files: clean up old code related to refreshing mtd partitions, it is no longer used anywhere"). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: improve lib/upgrade/common.shKlaus Kudielka2019-05-111-13/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recently, upgrade device autodetection has been added to the mvebu target. This exposes some shortcomings of the generic export_bootdevice function, e.g. on the Turris Omnia: export_bootdevice silently reports the root partition to be the boot device. This makes the sysupgrade process fail at several places. Fix this by clearly distinguishing between /proc/cmdline arguments which specify the boot disk, and those which specify the root partition. Only in the latter case, strip off the partition, and do it consistently. root=PARTUUID=<pseudo PARTUUID for MBR> (any partition) and root=/dev/* (any partition) are accepted. The root of the problem is that the *existing* export_bootdevice in /lib/upgrade/common.sh behaves differently, if the kernel is booted with root=/dev/..., or if it is booted with root=PARTUUID=... In the former case, it reports back major/minor of the root partition, in the latter case it reports back major/minor of the complete boot disk. Targets, which boot with root=/dev/... *and* use export_bootdevice / export_partdevice, have added workarounds to this behaviour, by specifying *negative* increments to the export_partdevice function. Consequently, those targets have to be adapted to use positive increments, otherwise they are broken by the change to export_bootdevice. Fixes: 4e8345ff68 ("mvebu: base-files: autodetect upgrade device") Signed-off-by: Klaus Kudielka <klaus.kudielka@gmail.com> Tested-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
* base-files: fix ucert verificationFelix Fietkau2019-02-121-1/+2
| | | | | | | | ucert needs to check the firmware part with metadata, but without the signature. Use the new fwtool mode to extract that without altering the firmware image inside the check Signed-off-by: Felix Fietkau <nbd@nbd.name>
* base-files: do not strip fwtool signature data during checkFelix Fietkau2019-02-091-1/+1
| | | | | | | Same reason as in commit 9808bd279927bcd2d3a78d19a55229b93bbbcf05 - sysupgrade --test must not alter the image in any way Signed-off-by: Felix Fietkau <nbd@nbd.name>