Commit Graph

93 Commits (a6b7c3e672764858fd294998406ae791f5964b4a)

Author SHA1 Message Date
李国 a6b7c3e672 x86: generate EFI platform bootable images
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>
4 years ago
Klaus Kudielka 3a4f587c46 base-files: upgrade: add case to export_bootdevice
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>
5 years ago
Rafał Miłecki a858db3136 treewide: sysupgrade: use $UPGRADE_BACKUP to check for backup
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>
5 years ago
Rafał Miłecki 641f6b6c26 treewide: use new procd sysupgrade $UPGRADE_BACKUP variable
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>
5 years ago
Rafał Miłecki bf39047872 treewide: don't hardcode "sysupgrade.tgz" file name
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>
5 years ago
Rafał Miłecki b534ba9611 base-files: pass "save_config" option to the "sysupgrade" method
This explicitly lets stage2 know if config should be preserved.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
5 years ago
Rafał Miłecki f7edd94a65 base-files: move stage2 upgrade to separated file
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>
5 years ago
Rafał Miłecki ea4e1dac71 base-files: drop support for NAND upgrade in platform_pre_upgrade()
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>
5 years ago
Rafał Miłecki f58ca6ee57 base-files: drop unused jffs2_copy_config()
Its last usage was dropped back in 2013 in the commit b95bdc8ab5
("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>
5 years ago
Klaus Kudielka ad62247800 base-files: improve lib/upgrade/common.sh
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>
5 years ago
David Bauer 28cd2caa35 base-files: sysupgrade: support additional mtd options
Add support for passing additional parameters to mtd called during
sysupgrade. It will be required to toggle the "recovery moe" flag
supported by recent tp-link boards.

Signed-off-by: David Bauer <mail@david-bauer.net>
[split code from board support patch; add commit message]
Signed-off-by: Mathias Kresin <dev@kresin.me>
5 years ago
Michael Heimpold d6ac8ca76c base-files: fix several bashisms
For equality test a simple = is sufficient, the == is
usually disregarded as bashism.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
6 years ago
Mathias Kresin 56b8ac1e86 treewide: consolidate upgrade state set
Set the (sys)upgrade state when sourcing the stage2 script instead of
setting the state for each target individual.

This change fixes the, due to a missing state set, not working upgrade
led on ath79 and apm821xx.

Signed-off-by: Mathias Kresin <dev@kresin.me>
6 years ago
Rafał Miłecki 5b2e20807d base-files: exit if mtd write command fails during sysupgrade
It avoids confusing situations like:
> Could not get image magic
> Image check failed.
> Upgrade completed
> Rebooting system...

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
6 years ago
Matthias Schiffer 3b6f865b01
base-files: sysupgrade: fix handing get_image unpack commands
On bcm53xx and brcm47xx, commands are passed to default_do_upgrade that
expect the image to be passed on stdin, rather than as an argument.

Fixes: 30f61a34b4 ("base-files: always use staged sysupgrade")
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
6 years ago
Daniel Golle 267873ac9b
base-files: don't evaluate block-device uevent
Current code and also before commit da52dd0c83 was vulnerable to shell
injection using volume lables in the GPT partition table of block
devices. Given that partition names can be freely defined in GPT tables
we really shouldn't evaluate a string which is potentially crafted with
evil intentions. Hence rather use `export -n` to absorb the uevent's
variables into the environment.

Fixes commit da52dd0c83 (base-files: quote values when evaluating uevent)
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
[mschiffer@universe-factory.net: suggested export -n usage]
6 years ago
Daniel Golle da52dd0c83 base-files: quote values when evaluating uevent
When sourcing /sys/class/block/*/uevent values have to be quoted as
they may contain spaces (e.g. in PARTNAME).
Fix this by pre-processing with sed before sourcing.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
6 years ago
Christian Lamparter 4e3f6dae04 base-files: upgrade: make get_partitions() endian agnostic
This patch fixes two issues with the current get_partitions()
function.

First: "Invalid partition table on $disk" will pop up on
legitimate images on big endian system.

This is because the little-endian representation of "55 AA" is
assumed in the context of little-endian architectures. On these
comparing it to the 16-bit word 0xAA55 does work as intented.
Whereas on big-endian systems, this would have to be 0x55AA.

This patch fixes the issue by replacing the integer conversion
and value match check with just a string comparision.

Second: The extraction of the type, start LBA and LBA num from
the partition table has the same endianness issue. This has been
fixed by using the new hex_le32_to_cpu() function. This function
will translate the stored little-endian data to the correct
byte-order if necessary.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
7 years ago
Matthias Schiffer 438dcbfe74
base-files: automatically handle paths and symlinks for RAMFS_COPY_BIN
Depending on busybox applet selection, paths of basic utiilties may differ,
and may not work as symlinks to busybox. Simply using whatever binary is
found in PATH and detecting symlinks automatically is more robust and
easier to maintain.

The list of binaries is also slightly cleaned up and duplicates are
removed.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years ago
Matthias Schiffer 7a29e44f90
base-files: upgrade: correctly handle nand_do_upgrade argument passed from preupgrade
Fixes: 30f61a34b4 "base-files: always use staged sysupgrade"
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years ago
Matthias Schiffer b2adb9a7b5
base-files: sysupgrade cleanup
Some functions only used by stage2 are moved there from common.sh.

One piece that could still use more cleanup is platform_pre_upgrade: many
targets reference files from there are aren't available in the ramfs, so
we need to evaluate it before the switch; conversely, flash writes happen
in that function on some targets. Targets that do the latter should be
fixed eventually to use platform_do_upgrade for that purpose.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years ago
Matthias Schiffer 30f61a34b4
base-files: always use staged sysupgrade
Support for the -d and -p options is dropped; it may be added again at some
point by adding these flags to the ubus sysupgrade call.

A downside of this is that we get a lot less information about the progress
of the upgrade: as soon as the actual upgrade starts, all shell sessions
are killed to allow unmounting the root filesystem.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years ago
Felix Fietkau 7304510392 base-files: save /bin/mknod for sysupgrade
It is used on NAND devices in case hotplug is too slow

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years ago
Yousong Zhou 6f61d8511e base-files: export x86 platform upgrade functions to common.sh
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
7 years ago
André Valentin 783875f18b package/basefiles: add mkfs.ext4 and losetup binaries to ramfs list
mkfs.ext4 und losetup are needed for sysupgrade support on mmc devices
with automatic rootfs split (loopback device usage).

Signed-off-by: André Valentin <avalentin@marcant.net>
8 years ago
Mathias Kresin 3004298e62 sysupgrade: unmount filesystems before reboot
sysupgrade immediately reboots after flashing an image and doesn't
allow to unmount filesystems. At least in case the image used for
sysupgrade is stored on a FAT formatted usb flash drive, the following
warning is printed during the next mount of the flash drive:

FAT-fs (sda1): Volume was not properly unmounted. Some data may be
corrupt. Please run fsck.

Although a data corruption during read operations is unlikely, there is
no need to scare the users.

Signed-off-by: Mathias Kresin <dev@kresin.me>
8 years ago
Conn O'Griofa e1406cd31a base-files: sysupgrade: fix pseudobridge upgrades
Treat 'relayd' as an essential service to avoid connection interruptions during sysupgrade on devices configured as a pseudobridge.

Signed-off-by: Conn O'Griofa <connogriofa@gmail.com>
8 years ago
Jo-Philipp Wich 1012701014 x86: generalize partition discovery for sysupgrade
Generalize the partition discovery in sysupgrade in order to fix sysupgrade
and config backup/recovery on MMC block devices which use a different naming
scheme compared to mtdblock or sd* devices.

The change also adds the find applet to the ramdisk utilities so that upgrade
code can rely on it.

The commit is based on the initial submission by Russell Senior at
http://patchwork.ozlabs.org/patch/625440/ .

Signed-off-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
8 years ago
Jo-Philipp Wich 4aeeead303 x86: preserve partition table on sysupgrade
With this patch sysupgrade will write directly to the partitions
instead of to the main disk.  The UUID is copied from the image
to the MBR as well.  This prevents the mbr from being completely
overwritten and losing the partition table.  The -p option has
been added to maintain the original behavior and overwite the
entire disk with the new image.  Tests have been added to ensure
that the image partitions match up with the active partitions.

Signed-off-by: Rob Mosher <nyt-openwrt@countercultured.net>

SVN-Revision: 48682
8 years ago
Felix Fietkau b7ab6c66cc base-files: fix sysupgrade 'wget' handling for uclient-fetch
change 48451 tried to add support for uclient-fetch by moving
/usr/bin/wget to /bin/wget, but this change kept the symbolic
link to /bin/busybox as install_bin creates links to param 1

the desired fix is to link to uclient-fetch to wget:
  install_bin /bin/uclient-fetch /bin/wget

Signed-off-by: John Clark <inindev@gmail.com>

SVN-Revision: 48483
8 years ago
Felix Fietkau f57419d26e base-files: fix sysupgrade 'wget' handling
with r48379 and r48386 the path of wget changed.
respect that and adjust the dirname.

this fixes #21680

Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>

SVN-Revision: 48451
8 years ago
John Crispin 4ef319fad2 base-files: sysupgrade: quote source image name
get_image() eval a filename without quoting it, resulting in errors with
filenames containing characters that need to be escaped.
    $ sysupgrade -T -f ./cfg\(12\).tar.gz img.bin; echo $?
    Image check 'platform_check_image' failed.
    Invalid config file. Please use only .tar.gz files
    1
    $ mv cfg\(12\).tar.gz cfg_12.tar.gz
    $ mv img\(1\).bin img.bin
    sysupgrade -T -f ./cfg_12.tar.gz img.bin; echo $?
    0

Enclose the content of $from in double quotes.

Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>

SVN-Revision: 46919
9 years ago
John Crispin f57076956e base-files: default_do_upgrade: accept & forward image extraction command
get_image allows passing 2nd argument that is used in a pipe for
extracting firmware from a non-native format. By accepting such command
in default_do_upgrade we allow platforms to use this helper for vendor
specific images.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 45900
9 years ago
Luka Perkov 0a4bcd5be6 base-files: remove ubi tool
ubi tool was removed from fstools in r41128.

Signed-off-by: Luka Perkov <luka@openwrt.org>

SVN-Revision: 45813
9 years ago
Jonas Gorski 02c6798a0d base-files: supress errors from ldd
ldd might be called for shell scrips during sysupgrade, causing it to
complain that they are not a dynamic executables.

This is a harmless error, so supress it to avoid confusing about them
being serious ones.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>

SVN-Revision: 43315
10 years ago
Jonas Gorski 2e95b1fda7 base-files: properly fix copying ld*.so with eglibc
r36107 ("base-files: sysupgrade fail with eglibc") tried to fix
sysupgrade by changing the ld-soname to what is expected, but only
fixed MIPS while breaking ARM.

The underlying issue is that the ld.so name varies widely across
different architectures for eglibc:

eglibc-2.19-r25243$ grep -r "ld-soname :=" . | awk '{ print $3 }' | sort -u
ld64.so.1
ld64.so.2
ld-linux-aarch64_be.so.1
ld-linux-aarch64.so.1
ld-linux-armhf.so.3
ld-linux-mipsn8.so.1
ld-linux.so.2
ld-linux.so.3
ld-linux-x32.so.2
ld-linux-x86-64.so.2
ld.so.1

Instead of adding each different soname to check for and copy it,
replace the awk script with a sed script to extract it properly and
drop the hardcoded so-name.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>

SVN-Revision: 43295
10 years ago
Felix Fietkau 0ef474a118 base-files: fix ldd definition if /usr/bin/ldd exists
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 42976
10 years ago
John Crispin be26421f45 sysupgrade: Enable killing of all processes under upgraded
If the sysupgrade scripts is called under upgraded, it will not kill all
other processes as it should to avoid interference by locked filesystem.
This patch checks the parent and if it is upgraded, it kills all.

Signed-off-by: André Valentin <avalentin@marcant.net>

SVN-Revision: 41563
10 years ago
John Crispin 66ae4803e2 base-files: fix ramfs / nand upgrade
/lib/{imx6,lantiq,...}.sh are needed in the ramfs for sysupgrade to work.

Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 41440
10 years ago
John Crispin 09273f5c0a base-files: regenerate the /lib64 symlink when switching to a ramdisk
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 41284
10 years ago
John Crispin 4b1c48bc93 base-files: add upgraded to the list of daemons not killed
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 41268
10 years ago
John Crispin bedd6f44a5 base-files: properly remove stderr from zcat/bzcat
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 41135
10 years ago
John Crispin e73538ba56 base-files: include more ubi* tools in sysupgrade ramdisk
Also add some more busybox symlinks which are useful for sysupgrade
on UBI-enabled devices.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>

SVN-Revision: 41125
10 years ago
John Crispin 0de0310a9c base-files: Allow installation of symlinks using RAMFS_COPY_BIN env var.
http://patchwork.openwrt.org/patch/5086/

Signed-off-by: karl.vogel@gmail.com

SVN-Revision: 40943
10 years ago
John Crispin 665d39f698 base-files: the ubi tol should be installed when jumping to ram_fs
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 40420
10 years ago
John Crispin 1d5ac95850 base-files: make use of new fstools
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 40416
10 years ago
Felix Fietkau 4a9ea80ef0 /lib/functions.sh: move rarely used mtd and macaddr related functions to /lib/functions/system.sh
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 40411
10 years ago
John Crispin 08b4924401 ubi-utils: mini version of mtd-utils that only includes ubi tools
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 40367
10 years ago
John Crispin 0dc9d8d6ff fstools: add the new fstools package
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 39895
10 years ago
John Crispin 834204bda6 base-files: fix mount-utils incompatibility
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>

SVN-Revision: 39169
11 years ago