Commit Graph

1628 Commits

Author SHA1 Message Date
Hannu Nyman
3c76bed6a9 base-files: increase default system log size to 128 kB
Increase the default system log buffer size option
in /etc/config/system from 64 kB to 128 kB.

64 kB is barely enough for the boot items of a modern router
with a few add-on packages, but any subsequent logging will
quickly cause the early boot items to get overwritten in the
round-robin log buffer. Double the buffer size to 128 kB.

(Note: built-in default in ubox logd itself is still 16 kB)

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
Link: https://github.com/openwrt/openwrt/pull/16723
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2024-10-19 14:14:00 +02:00
Hannu Nyman
5004f3780d base-files: Increase failsafe trigger wait time from 2 to 4 sec
Increase the failsafe waiting timeout period from 2 seconds
to 4 seconds.

Since commit 29207748b in 2015 we have had a rapid LED blinking
indication for the failsafe triggering period. But the really short
timeout of 2 seconds requires snappy reaction time from the user to
notice the LED blinking and to push button inside the short window.

Relax the timeout to 4 seconds, which more easily allows to notice
the change in LED blinking and push a button.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
Link: https://github.com/openwrt/openwrt/pull/11852
Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-10-17 18:15:05 +02:00
Boris Krasnovskiy
a9402a83e6 mvebu: fix sysupgrade failure
Linksys devices do no pass $cmd at all.

Fixes: #16148
Fixes: 715634e6d1 ("base-files: upgrade: nand: use "cmd" argument for extracting command")
Signed-off-by: Boris Krasnovskiy <borkra@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16690
Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-10-13 14:18:21 +02:00
Daniel Golle
dae6a871de base-files: don't wipe LED state when adding a single LED
Only replace LED state of a single LED instead of removing the entire
/var/run/led.state file.

Fixes: 511e8f84d0 ("base-files: configure LED when added")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-10-07 01:41:32 +01:00
Daniel Golle
511e8f84d0 base-files: configure LED when added
Currently LED configuration is only carried out once during boot.
Apply LED configuration also with a hotplug call when a new LED gets
added later.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-10-03 23:05:24 +01:00
John Audia
664b8ffb0a base-files: /etc/sysctl.conf: clarity in comment
Make it clear to users that they should not place a custom file
in /etc/sysctl.d/ for their values and expect it to survive a
reimage.

This change is needed since these directories (/etc/foo.d/) are
generally where such files are placed on other distros.

Signed-off-by: John Audia <therealgraysky@proton.me>
Link: https://github.com/openwrt/openwrt/pull/16543
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2024-10-03 17:29:02 +02:00
John Crispin
859bb4dd3f base-files: set root password if present inside board.json
Add code to set plain password or put the hash into /etc/shadow.

Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
John Crispin
5071e842b9 base-files: add timezone to UCI during config_generate
Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
John Crispin
7a120ee72e base-files: execute uboot-env script before calling config_generate
This allows /etc/board.d/* scripts to use values from the uboot environment.

Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
John Crispin
e7c7a3c154 base-files: uci-defaults: allow setting the number of MACs a radio can use
Introduce new uci-default functions:
	- ucidef_set_wireless_mac_count [count]

Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
John Crispin
fa53a733ab base-files: uci-defaults: allow setting default timezone
Introduce new uci-default functions:
	- ucidef_set_timezone TZ

Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
John Crispin
a8271b0f82 base-files: uci-defaults: allow setting default credentials and ssh keys
Introduce new uci-default functions:
     - ucidef_set_root_password_hash [hash]
     - ucidef_set_root_password_plain [plaintext]
     - ucidef_set_ssh_authorized_key [ssh key]

Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
Daniel Golle
b9eadcf318 base-files: uci-defaults: allow setting wireless defaults
Introduce new uci-default functions:
 - ucidef_set_wireless band ssid [encryption] [key]
 - ucidef_set_country cc

They are supposed to be used in /etc/board.d/* scripts to define
board-specific defaults for wireless.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: John Crispin <john@phrozen.org>
2024-10-02 15:41:33 +02:00
Rodrigo Balerdi
c4022e6199 base-files: emmc: invalidate kernel image while rootfs is being written
Some setups have alternate boot actions in case the main OS fails to
boot. These can include a secondary copy of the OS, a recovery OS, a
fallback to TFTP boot, etc.

This commit invalidates the kernel image while rootfs is being written
which, if a sysupgrade is interrupted, will trigger an alternate boot
action in devices that support it. This results in safer sysupgrades.

Signed-off-by: Rodrigo Balerdi <lanchon@gmail.com>
2024-09-27 18:24:44 +01:00
Matthias Schiffer
9bbaa6f2c0
base-files: fix merge of passwd/shadow/group lines with trailing colons
Empty trailing fields get lost when the lines are split and merged again
at colons, resulting in unparsable entries. Only use the split fields for
matching against the other file, but emit the original line unchanged
to fix the issue.

Fixes: de7ca7dafa ("base-files: merge /etc/passwd et al at sysupgrade config restore")
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2024-08-29 21:07:15 +02:00
Mark Mentovai
1310e4f1ae failsafe: fix console failsafe shell
When running a failsafe shell on a console, job control was unavailable,
and ^C did not function correctly.

This change invokes console failsafe shells via `setsid`, making them
session leaders and allowing them to claim controlling terminals, which
makes job control function properly. To support this, the busybox
`setsid` utility is enabled. This has a minimal 149-byte size impact on
a test x86_64 squashfs rootfs image.

^C was ignored in subprocesses of failsafe shells: it was not possible
to ^C out of a program that would not exit on its own, such as many
typical `ping` invocations. As job control was unavailable, it was not
possible to suspend these subprocesses either, causing a hung program to
tie up a console indefinitely, unless another means to signal the
program was available. This was caused by SIGINT being placed at
disposition SIG_IGN by the shell running preinit, which it did because
the console shell was executed asynchronously with &. That disposition
was inherited by the console shell and its subprocesses, generally
causing ^C to have no effect.

As there is no way in busybox `ash` to reset the disposition of a signal
already ignored at shell entry, and no apparent way to avoid SIGINT
being placed at SIG_IGN when & is used in preinit, an alternative
construct is needed. Now, `start-stop-daemon` is used to start (-S) the
console failsafe shell in the background (-b). This approach does not
alter SIGINT, allowing the console shell to be started with that
signal's handling intact, and normal ^C processing to occur.

busybox `ash` has some behaviors conditional on SHLVL, and while the
console shells ought to run at SHLVL=1, they were not by virtue of being
started by the shell-based preinit system. Additionally, a variety of
detritus was present in the console shell's environment, carried over
from preinit. These conditions are corrected by running the console
shell via `env -i` to clear the environment and establish a minimum and
correct set of environment variables for operation, in the same manner
as `login`. HOME is not explicitly set, because it's addressed in
/etc/profile. For non-failsafe console shells when
system.@system[0].ttylogin = 0, `login -f root` achieves a similar
effect. (`login` already started non-failsafe console shells when
ttylogin = 1 and behaved correctly. This brings the ttylogin = 0 case to
parity.) Note that even `login -f` is somewhat undesirable for failsafe
shells because it requires a viable /etc/passwd, hence the `env -i`
construct in that case.

The TERM environment variable from the preinit environment, with value
"linux", would rarely be correct for serial consoles. Now, the preinit
TERM value is preserved (or set to "linux" if unset) only when the
console is /dev/console or /dev/tty[0-9]*. Otherwise, it will be set to
a safe default appropriate for serial consoles, "vt102", as used for
serial consoles by busybox init. This "linux"/"vt102" TERM setting is
also duplicated for non-failsafe console shells.

This also indicates failsafe mode by showing "- failsafe -" on all
consoles (not just the last-defined one). It sets a hostname of
"OpenWrt-failsafe" in failsafe mode which is rendered in the shell's
prompt as a reminder of the mode during interactive failsafe use.
Previously, no hostname was set, which resulted in the kernel-default
hostname, "(none)", appearing in failsafe shell prompts.

Signed-off-by: Mark Mentovai <mark@mentovai.com>
Link: https://github.com/openwrt/openwrt/pull/16113
Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-08-19 18:55:00 +02:00
Daniel Golle
74bf11570f base-files: get rid of forgotten traces of fitblk_get_bootdev
The function fitblk_get_bootdev doesn't exist any more, using it in
export_bootdevice anyway never made much sense and only worked for
classic block devices.
Just drop /dev/fit* handling there, it isn't needed anywhere.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-08-12 19:16:58 +01:00
Rafał Miłecki
a67b20e3d5 base-files: upgrade: nand: allow custom fw extraction in nand_do_upgrade()
By default nand_do_upgrade() can only deal with raw and gzipped firmware
files. Vendors often use custom firmware containers. Allow passing
custom extraction command to allow using nand_do_upgrade() with vendor
firmwares.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-07-26 13:41:25 +02:00
Philip Prindeville
0037100e12 base-files: ipcalc.sh handle start and range being empty strings
If we're being paranoid and quote all the arguments to ipcalc.sh,
it's possible to pass in empty start and range arguments.  This
should be handled the same as their being absent.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Link: https://github.com/openwrt/openwrt/pull/15946
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2024-07-21 17:31:59 +02:00
Rafał Miłecki
715634e6d1 base-files: upgrade: nand: use "cmd" argument for extracting command
NAND code uses either "cat" or "zcat" for getting firmware image
content. Code was full of duplicated ${gz}cat calls. Use "cmd" variable
that is determined by a caller and passed to lower level functions. This
avoids code duplication and allows adding support for more formats.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-07-19 08:48:51 +02:00
Rafał Miłecki
4565699ebe base-files: upgrade: nand: document nand_do_upgrade()
Describe what firmware files are supported.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-07-19 08:48:51 +02:00
Daniel Golle
de2df0f2c5 base-files: remove fitblk_get_bootdev() from /lib/upgrade/common.sh
The function was moved to /lib/upgrade/fit.sh which is part of the fitblk
package. Remove it from /lib/upgrade/common.sh to safe space on boards
not using unified uImage.FIT images.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-07-18 11:48:53 +01:00
Christian Marangi
cf2b689d03
Revert "apk: limit CONFIG_IPK_FILES_CHECKSUMS config to OPKG"
This reverts commit 25bbefcdd9.

Only the Config-build.in change needed to be merged and this contains
leftover from previous revision of the feature.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-06-20 05:52:05 +02:00
Rafał Miłecki
156f5e8f48 base-files: migrate old UCI network sections defining bridges
Old "interface" sections for bridges were mixing layer 2 and layer 3.
That syntax got deprecated and UCI section "device" is used for bridge
configuration now.

Backward compatibility may be dropped from netifd soon now so migrate
old configs using uci-defaults script.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-06-19 12:47:58 +02:00
Rafał Miłecki
c8e68dce61 base-files: migrate old UCI network bridge ports syntax
netifd supports more accurate "ports" option (instead of "ifname") for
years now. Relevant changes were even backported to OpenWrt 21.02. Add
uci-defaults script that translates config files using deprecated
syntax.

Identical commit f716c30241 ended up reverted back in 2021 by
80be798d4a due to breaking downgrades. With 19.07 support ended it
should no longer be an issue.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-06-19 09:11:44 +02:00
Leon M. Busch-George
bff0e1cfd8
base-files: fix ipcalc bound calculation for /31 prefix
A small regress from the translation to shell.
Fixes #12921, originally fixed in #12925 (Github).

Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
Link: https://github.com/openwrt/openwrt/pull/15430
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-06-17 13:45:37 +02:00
Paul Spooren
213bd273ed base-files: Reapply fixed "Ignore exit code of uci.sh inclusion"
This reverts commit 80d1c353b7 with the
fix which won't break running systems. A logic error on how shell
handles && and || more the init process.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-06-12 11:12:13 +02:00
Christian Marangi
25bbefcdd9
apk: limit CONFIG_IPK_FILES_CHECKSUMS config to OPKG
Limit CONFIG_IPK_FILES_CHECKSUMS config to OPKG as APK have different
way to validate package integrity (apk audit)

Link: https://github.com/openwrt/openwrt/pull/15543
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-06-11 23:58:19 +02:00
Christian Marangi
8ca2e2852e
base-files: skip fix-group-user uci-default for APK installation
For APK installation we don't have /usr/lib/opkg/info and user fixup are
handled dirrectly. Skip the script in such case.

Also remove this uci-defaults if we have CONFIG_USE_APK enabled.

Link: https://github.com/openwrt/openwrt/pull/15543
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-06-11 23:58:18 +02:00
Christian Marangi
93d49529a1
apk: provide csum for static conffiles
For non-overlay configuration we need checksum for config file that
weren't modified by the user. For OPKG in sysupgrade we check the status
file for the Conffiles: entry of every package. this entry contains
checksum for every static file that the package contains.

Provide the same info for APK by creating a conffiles_static file and
parse this file on sysupgrade for non-overlay configurations.

This is also used by the sysupgrade -u option to exclude non-changed
files from the final backup.

Link: https://github.com/openwrt/openwrt/pull/15543
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-06-11 23:58:17 +02:00
Robert Marko
80d1c353b7 Revert "base-files: Ignore exit code of uci.sh inclusion"
This reverts commit 17d8c5825e.
This commit is breaking init somehow, even the hostname is not set,
so until its fixed, revert it.

Signed-off-by: Robert Marko <robimarko@gmail.com>
2024-06-08 12:57:18 +02:00
Paul Spooren
17d8c5825e base-files: Ignore exit code of uci.sh inclusion
When running unit tests this causes trouble since `/lib/config/uci.sh`
isn't available in those cases. Instead exit with a clean status fo the
unit test framework don't wrongly interpret things as an error.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-06-07 21:49:09 +02:00
Daniel Golle
9a11bc3682 build: generate private key for APK early
Other than OPKG which only uses signed package list, APK uses
individually signed packages in addition to signed package lists. Hence,
in order to be able to generate package, the private key needs to be
generated before compiling packages. Express that dependency and
generate the private key before building any packages instead of doing
so as part of the base-files package build.

Fixes: d788ab376f ("build: add APK package build capabilities")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-05-22 19:28:20 +02:00
Paul Spooren
a96354bcfb
base-files: correctly split install-key function for APK
The function incorrectly tried to APK keys even if there were none.
Correctly separate it into its own `ifdef` section.

Signed-off-by: Paul Spooren <mail@aparcar.org>
Link: https://github.com/openwrt/openwrt/pull/15519
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2024-05-17 23:34:23 +03:00
Paul Spooren
bcc641504d base-files: add compatibility for APK and OPKG
Both package managers work slightly different, i.e. stores files at
different places. Modify the `functions.sh` file to cover those.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-05-17 23:21:26 +03:00
Paul Spooren
3010ab87bc base-files: add update_alternatives function
The APK package manager does not support handling of package
alternatives itself, so implement it via a simple shell script.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-05-17 23:21:26 +03:00
Paul Spooren
d788ab376f build: add APK package build capabilities
A new option called `USE_APK` is added which generated APK packages
(.apk) instead of OPKG packages (.ipk).

Some features like fstools `snapshot` command are not yet ported

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-05-17 23:21:26 +03:00
Thomas Winkler
140b48a9e9 base-files: fix uid/gid auto-enumeration to avoid 16-bit limit
uid/gid range should be limited to 16bit unsigned integer range to
avoid "wraparound" issues with permissions where jffs2
is employed for storage and chown 65536 (first auto-created user)
becomes equivalent to chown 0

Fixes: #13927

Signed-off-by: Thomas Winkler <tewinkler86@gmail.com>
2024-05-10 22:39:57 +02:00
Paweł Owoc
652a6677d5 base-files: Add new functions for ath11k caldata
Add new functions for ath11k caldata:
- ath11k_patch_mac (from 0 to 5)
- ath11k_remove_regdomain
- ath11k_set_macflag (some pre-caldata have the nvMacFlag flag unset which is needed to change the MAC address)

Additionaly for ath10k caldata:
- ath10k_remove_regdomain

Signed-off-by: Paweł Owoc <frut3k7@gmail.com>
2024-04-23 22:35:57 +02:00
Paul Donald
27edf28b11
base-files: reduce IPv6 ULA prefix generation to a single call
Reduce calls and pipes and read from urandom once directly with hexdump
for the necessary 5 bytes of random data to build the 48 bit ULA Prefix.

Fewer calls and forks; finish quicker; less memory used.

Tested on: 23.05.3

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-04-18 12:55:31 +02:00
Rodrigo Balerdi
8cf4ac5195 base-files: minor fix to mmc_get_mac_ascii function
This is mostly a cosmetic cleanup. The absence of
the return statement was not causing any problems.

Signed-off-by: Rodrigo Balerdi <lanchon@gmail.com>
2024-04-07 20:06:11 +01:00
Paul Spooren
e8725a932e treewide: use APK compatible version schema
Different from OPKG, APK uses a deterministic version schema which chips
the version into chunks and compares them individually. This enforces a
certain schema which was previously entirely flexible.

 - Releases are added at the very and end prefixed with an `r` like
`1.2.3-r3`.
- Hashes are prefixed with a `~` like `1.2.3~abc123`.
- Dates become semantic versions, like `2024.04.01`
- Extra tags are possible like `_git`, `_alpha` and more.

For full details see the APK test list:
https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/test/version.data

Signed-off-by: Paul Spooren <mail@aparcar.org>
2024-03-22 22:14:22 +01:00
Rafał Miłecki
4efbfcd996 base-files: sysupgrade: handle errors when generating backup
1. Return error if any step of generating tar file fails
2. Use pipefail to avoid calling "gzip" if tar failed

Fixes: e36cc53092 ("base-files: sysupgrade: use tar helper to include installed_packages.txt")
Reported-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: Jo-Philipp Wich <jo@mein.io>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-03-05 11:54:55 +01:00
Álvaro Fernández Rojas
4b3c1251a4 base-files: sysupgrade: allow overriding config restore
Some platforms like Raspberry Pi require patching some backup files like
cmdline.txt in order to set the correct root PARTUUID.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
2024-03-04 16:27:39 +01:00
Jo-Philipp Wich
6f6406a132 base-files: sysupgrade: fix streaming backup archives to stdout
Due to previous refactoring in sysupgrade, writing backup archives to
stdout became impossible since the hardcoded gzip output redirection
did not account for the `-` special case filename.

Fix this issue by substituting `-` with `/proc/self/fd/1` in the tar
archive output path variable.

Also remove a redundant `rm -f` of the target file path that occurs
before the file could've possibly been written.

Fixes: #14773
Fixes: https://github.com/openwrt/luci/issues/6961
Fixes: e36cc53092 ("base-files: sysupgrade: use tar helper to include installed_packages.txt")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-03-04 14:58:10 +01:00
Rafał Miłecki
0ad062a21b base-files: sysupgrade: add uci-defaults script disabling services #2
Disabled services should be kept disabled after sysupgrade. This can be
easily handled using a proper uci-defaults script.

Extend sysupgrade to check for disabled services, generate uci-defaults
script disabling them and include it in backup.

Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Jo-Philipp Wich <jo@mein.io>
Cc: Jonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2024-02-29 16:12:06 +01:00
Rafał Miłecki
e36cc53092 base-files: sysupgrade: use tar helper to include installed_packages.txt
Replace mount + overlay with manually built tar archive that gets
prepended to the actual config files backup. This allows more
flexibility with including extra backup files. They can be included at
any paths and don't require writing to flash or mounting an overlay
which has its own limitations (mount points).

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2024-02-29 16:12:06 +01:00
Jo-Philipp Wich
08495b7f24 base-files: sysupgrade: add tar.sh with helpers for building archives
This allows building uncompressed tar archives from shell scripts (and
compressing them later if needed)

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
[rmilecki: adapt to sysupgrade needs]
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-02-29 16:11:47 +01:00
Daniel Golle
0c18c5679a base-files: export whole disk of fitblk backing partition
After commit ad62247800 ("base-files: improve lib/upgrade/common.sh")
behavior of export_bootdevice has been made consistent in such way that
always the whole disk device is exported (as that was the case already
when matching via UUID) rather than the partition device.
Do the same for the device holding the fitblk backing partition.

Fixes: 5992f976b3 ("base-files: recognize bootdevice on devices using fitblk")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-02-26 04:01:10 +00:00
Daniel Golle
5992f976b3 base-files: recognize bootdevice on devices using fitblk
Boards using the fitblk driver need special treatment when it comes to
detecting the actual block device used to store the image used to boot
from. Transparently handle this in 'export_bootdevice' and provide new
'fitblk_get_bootdev' function to replace implementations in
/lib/upgrade/platform.sh.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-02-26 01:29:22 +00:00