Commit Graph

1417 Commits

Author SHA1 Message Date
Leonardo Mörlein b993b68b6c build: introduce $(MKHASH)
Before this commit, it was assumed that mkhash is in the PATH. While
this was fine for the normal build workflow, this led to some issues if

    make TOPDIR="$(pwd)" -C "$pkgdir" compile

was called manually. In most of the cases, I just saw warnings like this:

    make: Entering directory '/home/.../package/gluon-status-page'
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    bash: line 1: mkhash: command not found
    [...]

While these were only warnings and the package still compiled sucessfully,
I also observed that some package even fail to build because of this.

After applying this commit, the variable $(MKHASH) is introduced. This
variable points to $(STAGING_DIR_HOST)/bin/mkhash, which is always the
correct path.

Signed-off-by: Leonardo Mörlein <me@irrelefant.net>
2021-05-13 15:13:15 +02:00
Jo-Philipp Wich 75ea878d1b base-files: shinit: properly handle dashes in service names
Fixes: FS#3801
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-12 12:44:32 +02:00
Daniel Golle a2b9ec0231
base-files: upgrade: take down loop and LVM before upgrade
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>
2021-05-05 13:18:43 +01:00
Alexander Egorenkov 9318f61556 base-files: fix status display command
If service() is called w/o parameter then the status display for services
with multiple instances is incorrect. E.g. samba4 or wpad have 2 instances.

root@OpenWrt:~# /etc/init.d/samba4 status
running
root@OpenWrt:~# /etc/init.d/wpad status
running

Before change:
/etc/init.d/samba4                 enabled         stopped
/etc/init.d/wpad                   enabled         stopped

After change:
/etc/init.d/samba4                 enabled         running
/etc/init.d/wpad                   enabled         running

Signed-off-by: Alexander Egorenkov <egorenar-dev@posteo.net>
2021-04-03 18:56:02 +02:00
Daniel Golle bb107ad9c1
base-files: functions: introduce new helper functions
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>
2021-03-31 16:53:39 +01:00
Florian Eckert fdbdbe8eaa base-files: add logging for configuration import
Make sysupgrade backup import more verbose.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-03-21 22:45:20 +01:00
Adrian Schmutzler 85b1f4d8ca treewide: remove execute bit and shebang from board.d files
So far, board.d files were having execute bit set and contained a
shebang. However, they are just sourced in board_detect, with an
apparantly unnecessary check for execute permission beforehand.

Replace this check by one for existance and make the board.d files
"normal" files, as would be expected in /etc anyway.

Note:

This removes an apparantly unused '#!/bin/sh /etc/rc.common' in
target/linux/bcm47xx/base-files/etc/board.d/01_network

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2021-03-06 11:30:06 +01:00
Florian Eckert dec14ac436 base-files: add new application led trigger backend
For now we have only kernel LED trigger support. With this change it is now
possible to use application triggers.

If we configure a LED with a non kernel trigger, then we check on every
restart and boot of the LED service if we have this trigger as an application
in "/usr/libexec/led-trigger". If this file with the name is found, then we
execute this to init the LED.

Possible use cases are:

- Start/Stop/Restart an application led trigger service for this led
- Init a LED that is configured by a hotplug script (VPN tunnel established)

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-03-05 00:10:06 -10:00
Daniel Golle ebcb4f1d0a
treewide: fix spelling 'seperate' -> 'separate'
This popular spelling mistake was also introduced by myself lately.
Fix it everywhere.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-28 23:59:21 +00:00
Daniel Golle 84a339f015 base-files: add support for restoring config from tmpfs
Instead of only relying in /sysupgrade.tgz being present in rootfs to
restore configuration, also grab /tmp/sysupgrade.tar which may have
magically gotten there during preinit...

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-02-28 00:09:09 +00:00
Daniel Golle 287bd78e6f
base-files: remove unneeded '$' signs in nand.sh
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>
2021-02-24 11:42:02 +00:00
Daniel Golle 5c10f26c28 sysupgrade-nand: allow limiting rootfs_data by setting env variable
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>
2021-02-24 01:35:20 +00:00
Daniel Golle e6aac8d98f 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-24 01:35:20 +00:00
Rosen Penev 157cd0bd97 base-files: use hwclock --systz
The date -k patch is non standard and will be removed in the next
commit.

Tested behavior to be identical with a simple C program:

 #define _GNU_SOURCE
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/time.h>
 #include <sys/syscall.h>

int main()
{
        struct timezone tt;
	struct timezone tz;

        int a = syscall(SYS_gettimeofday, NULL, &tt);
        int b = gettimeofday(NULL, &tz);
        printf("%d - %d, %d\n", a, tt.tz_minuteswest, tt.tz_dsttime);
        printf("%d - %d, %d\n", b, tz.tz_minuteswest, tz.tz_dsttime);
}

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-02-14 15:15:32 +01:00
Brian Norris 95b30f84d2 base-files: mount pstore if present
Pstore (persistent store) can be used to stash debug information (kernel
console, panics, ftrace) across reboots or crashes. If the filesystem is
present, mount it.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2021-01-29 22:26:36 +01:00
Adrian Schmutzler 396a35dd51 base-files: remove execute bit and shebang from functions.sh
/lib/functions.sh was executable for no obvious reason and its
execute property was even checked in package-ipkg.mk just to
source it afterwards.

Remove the execute bit and shebang as this is clearly a library.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Philip Prindeville <philipp@redfish-solutions.com>
2021-01-29 14:30:32 +01:00
Adrian Schmutzler 331892f85f treewide: drop shebang from non-executable lib files
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>
2021-01-29 14:29:41 +01:00
Paul Spooren 2d72be766d base-files: bump Copyright to 2021
This commit is only added to keep the PKG_RELEASE correct after fixing
the $(COMMITCOUNT) logic in the previous commit.

This way the PKG_RELEASE stays the same while the compiled packages
content isn't changed.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2021-01-26 17:30:09 -10:00
Paul Spooren aa589c77b4 base-files: use $(COMMITCOUNT) in PKG_RELEASE
The newly added `$(COMMITCOUNT)` varialbe allows automatic versioning
based on the number of Git commits of a package. Replace *tedious to
bump* and *merge conflict causing* `PKG_RELEASE` and replace it with
`$(COMMITCOUNT)`.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2021-01-22 19:03:53 -10:00
Adrian Schmutzler 81655e1450 base-files: read all 3 bytes in get_magic_vfat() at once
While the speed improvement might be negligible, there is still no
reason to read individual bytes.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2021-01-07 19:51:50 +01:00
Daniel Golle 9c845a5ad1 base-files: wifi: add support for 802.11ad
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2021-01-05 02:16:24 +00:00
Kagurazaka Kotori 927b9df938 x86/efi: add FAT32 esp mounting support
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>
2021-01-03 13:48:50 -10:00
Oldřich Jedlička 49d678f0d2 base-files: allow reusing of boolean value extraction logic
The `functions.sh` script has `config_get_bool()` function, which is
usable when using UCI config direct access API, but there is no
equivalent for the callback API. Introduce `get_bool()` function to
allow reusing it from init scripts.

Example:

```sh
option_cb() {
    local option="$1"
    local value="$(get_bool "$2")"
    ...
}
```

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
2021-01-01 10:23:56 -10:00
Adrian Schmutzler 93b6122212 base-files: sysupgrade: add function for conffiles retrieval
The find command to retrieve files from /etc/sysupgrade.conf and
/lib/upgrade/keep.d/* is used twice in almost the same way.

Move it into a function to consolidate, enhance readability and make
future adjustments easier.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Acked-by: Paul Spooren <mail@aparcar.org>
Reviewed-by: Philip Prindeville <philipp@redfish-solutions.com>
2020-12-30 00:00:13 +01:00
Piotr Dymacz 8c28da9724 base-files: drop banner.failsafe if failsafe is disabled
Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
2020-12-22 21:27:25 +01:00
Hannu Nyman 3d12b47985 base-files: flush kernel memory cache during sysupgrade
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>
2020-12-22 18:59:10 +01:00
Robert Marko 20d847d133 base-files: upgrade: fix initramfs detection
Commit "initramfs: switch to tmpfs to fix ujail" switched initramfs to
now use tmpfs, it causes $(rootfs_type) to now return tmpfs when
running initramfs image instead of being empty.

This broke initramfs detection which prevents config files from
being saved as it does not work from initramfs.

So, lets test for $(rootfs_type) returning "tmpfs" instead.

Fixes: 7fd3c68 ("initramfs: switch to tmpfs to fix ujail)

Signed-off-by: Robert Marko <robimarko@gmail.com>
2020-12-20 17:14:56 +00:00
John Thomson d82c191283 package/base-files: caldata: use dd iflag fullblock
This dd flag ensures that the requested size
is retrieved from pipes or special filesystems (if available).

Without this flag, on multi-core systems,
Piped or special filesystem data can be truncated
when a size greater than PIPE_BUF is requested.

Fixes: FS#3494
Fixes: 7557e7f ("package/base-files: caldata: work around dd's
limitation")
Cc: Thibaut VARÈNE <hacks@slashdirt.org>

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
2020-12-11 13:48:24 +01:00
Stan Grishin b4f1f9c9e4 base-files: informative service command in /etc/shinit. service command shows services enabled/disabled and running status, when the service command is invoked with no/invalid arguments, like this:
Usage: service <service> [command]
The following services are available:
/etc/init.d/acme                   enabled         stopped
/etc/init.d/boot                   enabled         stopped
/etc/init.d/cron                   enabled         running
/etc/init.d/dnsmasq                enabled         running
...

Signed-off-by: Stan Grishin <stangri@melmac.net>
2020-12-03 23:28:43 -10:00
John Crispin 9290539ca9 base-files: allow setting device and bridge macs
Add code for setting mac addresses inside board.json and rendering
them out to uci. On switches we want to have a unique MAC on each port.
With 48 port switches that would require 48 device sections in
/etc/config/network. Doing so via board.json is easier.

Signed-off-by: John Crispin <john@phrozen.org>
2020-12-02 07:51:36 +01:00
Huangbin Zhan 451c1eb8c2 base-files: fix alias more to properly detect /usr/bin/more
Package more is installed to /usr/bin rather than /bin.

Signed-off-by: Huangbin Zhan <zhanhb88@gmail.com>
2020-11-28 15:12:36 -10:00
Imran Khan 9c2eceef90 base-files: merge /etc/passwd on rw-rootfs
Support installations without root-overlayfs (and hence without /rom)
when migrating user accounts.

Signed-off-by: Imran Khan <gururug@gmail.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
[simplified patch, bumped PKG_RELEASE, cleaned message]
2020-11-27 09:59:14 +00:00
Rosen Penev b9246bbdc9 base-files: functions.sh: replace [^...] with [!...] in case
Strictly speaking, ash does not support it.

From https://wiki.ubuntu.com/DashAsBinSh#A.5B.5E.5D

Not to be confused by sed's and other program's regular expression
syntax. Uses of [^...] in case (parameter/word expansion in general) need
to be replaced with [!...].

Found with shellcheck: https://github.com/koalaman/shellcheck/wiki/SC2169

Signed-off-by: Rosen Penev <rosenp@gmail.com>
[minor commit title/message adjustments]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-11-25 17:22:39 +01:00
John Crispin 8134c542e2 base-files: generated named bridge-vlan sections
Signed-off-by: John Crispin <john@phrozen.org>
2020-11-19 15:38:37 +01:00
Matthias Schiffer 3f1109bf2a
base-files: fix backwards compatiblity of rc.common EXTRA_COMMANDS
Avoid needlessly breaking old initscripts that set EXTRA_COMMANDS. This
will aid in debugging (as it simplifies reverting to an older version of
a package) and unbreaks third-party feeds (and packages that maintain
their OpenWrt initscripts as part of the software's repo instead of the
OpenWrt feed like fastd).

Without this, initscripts that set EXTRA_COMMANDS become completely
unusable, as all default commands like start/stop cease working.

Fixes: 1a69f50dc6 ("base-files: fix rc.common help alignment")
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2020-11-17 17:57:42 +01:00
Yousong Zhou 600bcaf9c9 base-files: bump PKG_RELEASE
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2020-11-11 21:29:55 +08:00
Yousong Zhou 00fb51f97e base-files: upgrade: stage2: use v for log lines
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2020-11-11 21:29:55 +08:00
Yousong Zhou 128bb4e8d3 base-files: upgrade: fwtool.sh: rewording logs
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>
2020-11-11 21:29:55 +08:00
Yousong Zhou 856b288d27 base-files: upgrade: fwtool.sh: use v for log lines
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>
2020-11-11 21:29:55 +08:00
Yousong Zhou 50b870ee3c base-files: upgrade: add get_image_dd()
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>
2020-11-11 21:29:55 +08:00
Yousong Zhou bd21e4a936 base-files: upgrade: use stdin redirection to replace cat command
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2020-11-11 21:29:55 +08:00
Yousong Zhou 7863c33cea base-files: upgrade: add vn and variants
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>
2020-11-11 21:29:55 +08:00
Yousong Zhou 826bb13742 base-files: upgrade: log with date prefix
And log to stderr

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2020-11-11 21:29:55 +08:00
John Crispin be09c5a3cd base-files: add board.d support for bridge device
Latest netifd allows us to setup network bridges with implicit vlan
tagging. For this to work, we need to setup several additional uci
sections. This feature is particularly usefull for DSA tupe devices.
Add board.d and uci-defaults support for generating the sections.

Signed-off-by: John Crispin <john@phrozen.org>
2020-11-04 07:36:49 +01:00
Florian Eckert 1a69f50dc6 base-files: fix rc.common help alignment
This commit introduces a new function `extra_command` to better format
the help text without having to calculate the indentation in every startup
script that wants to add a new command. So far it looks weird and is not
formatted correctly on some startup scripts.

After using the new `extra_command` wrapper the alignement looks correctly.

And if the indentation is not sufficient in the future, this can be
changed in the function extra_command at a central location.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-11-02 21:32:38 +01:00
Daniel Golle de7ca7dafa base-files: merge /etc/passwd et al at sysupgrade config restore
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2020-10-22 14:25:55 +01:00
Daniel Golle d355b578b7 target: include selinux-variants if CONFIG_SELINUX is set
Rather than unconditionally adding busybox and procd to the set of
default packages, add busybox-selinux and procd-selinux in case
CONFIG_SELINUX is set.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2020-10-21 11:56:26 +01:00
Felix Fietkau 4a0688ed71 base-files: remove block2mtd checks from sysupgrade
This hasn't been used in a long time

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2020-10-17 16:43:17 +02:00
Adrian Schmutzler 9b4eab023c base-files: allow exceptions when removing devicename from LEDs
Without the model-based devicename for LEDs, there are still cases
where a third component is required, typically when it refers to
internal "devices" like phys etc. An example are the following two
found on ramips:

  - rt2800soc-phy0::radio
  - rt2800pci-phy0::radio

So far, the rt2800*-phy: prefixes would be removed by the devicename
removal ("migration") script, and the configuration for these LEDs
would be broken.

To address this, this patch allows to add arguments to a call of
remove_devicename_leds, which will be compared against the first
part of the LED names/labels, and then be ignored by the routine,
and thus not removed:

  remove_devicename_leds "rt2800soc-phy0" "rt2800pci-phy0"

This mechanism is supposed to be used when a "devicename" applies
to several devices. If only a single device is affected, it might
be more effective to use a case statement and exclude the device
from migration by that entirely.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-10-02 14:51:57 +02:00
Adrian Schmutzler 365a639f91 base-files: add function to remove devicename from LED labels
Currently, we request LED labels in OpenWrt to follow the scheme

  modelname:color:function

However, specifying the modelname at the beginning is actually
entirely useless for the devices we support in OpenWrt. In patches
subsequent to this one, we will thus remove the modelname from
the label definitions on various targets.

To migrate the existing definitions from older installations,
a migration script needs to be deployed that does

  modelname:color:function -> color:function

e.g.

  dir-789:green:status -> green:status

This patch introduces two functions that do exactly that:
For each entry in /etc/config/system, the routine will check whether
two (or more) colons are present, and then remove everything up to
(and including) the first colon.

For now, this will be applied unconditionally, i.e. if the function
is called for a device, all labels will be cut like this.

However, for a future case of mixed three-part and two-part labels,
it should not be too hard to provide a function argument with
exceptions to the removal.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-10-02 13:50:50 +02:00