aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib
Commit message (Collapse)AuthorAgeFilesLines
* package/base-files: add caldata_sysfsload_from_file()Thibaut VARÈNE2020-05-081-0/+15
| | | | | | | | This routine enables loading caldata binary via the kernel sysfs loader See https://www.kernel.org/doc/html/v4.19/driver-api/firmware/fallback-mechanisms.html Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
* package/base-files: caldata: allow setting target fileThibaut VARÈNE2020-05-081-8/+21
| | | | | | | This will enable platforms to extract caldata to an arbitrary file, or patch mac in an abitrary file. Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
* 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>
* base-files: preinit: also config switch when no port roles definedChuanhong Guo2020-04-121-6/+7
| | | | | | | | | current preinit code in base-files doesn't config switch when there are no port roles defined. But this kind of configuration exists on single port devices where switch vlan is simply disabled. configure reset and enable_vlan property when a switch node exist. Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
* base-files: source functions.sh in /lib/functions/system.shAdrian Schmutzler2020-04-121-0/+1
| | | | | | | | The file /lib/functions/system.sh depends on find_mtd_index() and find_mtd_part() located in /lib/function.sh, so let's source that file. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: do not source system.sh in functions.shAdrian Schmutzler2020-04-121-1/+0
| | | | | | | | | | | | | | | | | | The default_postinst() function in /lib/functions.sh sources /lib/functions/system.sh before cycling through uci-defaults files. This creates a pseudo-cyclic dependency as system.sh also uses functions that are located in functions.sh. Despite that, there is actually only one uci-defaults file in the entire repo that needs system.sh, and this one contains an explicit source for system.sh anyway. Consequently, this patch removes the sourcing of system.sh in functions.sh. There are no relevant uses in packages, routing and luci repositories. This may require adjustments for downstream, though. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* 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: convert leading spaces to tabs in functions.shAdrian Schmutzler2020-03-131-2/+2
| | | | | | Use tabs for indent consistently. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* 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: diag: restore default trigger for 'boot' LEDPiotr Dymacz2020-02-241-4/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For devices without a dedicated 'diag' LED, we use sometimes one of other LEDs for indicating at least 'boot', 'failsafe' and 'upgrade' stages. In some cases, at the same time these LEDs have defined default triggers in DTS using 'linux,default-trigger' property. Current 'diag' setup removes the trigger and turns off 'boot' LED after bootup. One of the examples of such device is TP-Link TL-WR841N v14 (ramips) which uses 'wlan' LED with defined 'linux,default-trigger' for 'diag': aliases { led-boot = &led_wlan; led-failsafe = &led_wlan; led-upgrade = &led_wlan; }; [...] led_wlan: wlan { label = "tl-wr841n-v14:green:wlan"; gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; linux,default-trigger = "phy0tpt"; }; This patch extends 'diag.sh' and 'leds.sh' scripts to make sure default trigger defined in DTS is restored for 'diag' LED which isn't used for indicating 'running' stage. Acked-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
* base-files: remove some bashismsSven Roederer2020-01-261-1/+1
| | | | | | | | | | "[[" is a bash extension for test. As the ash-implementation is not fully compatible we drop its usage. Also change to "=" for simple test, which is sufficient. (see d6ac8ca76c04ed) Signed-off-by: Sven Roederer <devel-sven@geroedel.de> [split patch, removed shebang] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files/functions.sh: use grep -q instead of []Rosen Penev2020-01-181-4/+4
| | | | | | | | | | | | It's cleaner and faster as it does not need to do extra work. Also removed $() to avoid executing the output. The shell can handle it. https://github.com/koalaman/shellcheck/wiki/SC2143 Signed-off-by: Rosen Penev <rosenp@gmail.com> [correct || to && for one conversion] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files/system.sh: remove $ in $(())Rosen Penev2020-01-171-1/+1
| | | | | | | | Not needed. https://github.com/koalaman/shellcheck/wiki/Sc2004 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files/functions.sh: use && instead of -aRosen Penev2020-01-171-2/+2
| | | | | | | | -a is not well defined. https://github.com/koalaman/shellcheck/wiki/SC2166 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files/functions.sh: remove useless catRosen Penev2020-01-171-2/+2
| | | | | | | | The cut command can take a file as an input. https://github.com/koalaman/shellcheck/wiki/SC2002 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files/functions.sh: don't use $var in $(())Rosen Penev2020-01-171-3/+3
| | | | | | | | It's not needed. It can also lead to subtle bugs. https://github.com/koalaman/shellcheck/wiki/Sc2004 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* dropbear: move failsafe code out of base-filesKyle Copperfield2020-01-151-6/+0
| | | | | | | | | | | | The sender domain has a DMARC Reject/Quarantine policy which disallows sending mailing list messages using the original "From" header. To mitigate this problem, the original message has been wrapped automatically by the mailing list software. Failsafe code of dropbear should be in the dropbear package not the base-files package. Signed-off-by: Kyle Copperfield <kmcopper@danwin1210.me>
* base-files: send informational UDP message each second waitingPaul Fertser2019-12-191-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The preinit network initialisation and failsafe informational message are inherently racy as the interface takes some time to become functional after "ip link set $pi_ifname up" command. Consider this timing: [ 12.002713] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready [ 12.008819] IPv6: ADDRCONF(NETDEV_UP): eth1.1: link is not ready [ 12.118877] random: procd: uninitialized urandom read (4 bytes read) [ 13.068614] eth1: link up (1000Mbps/Full duplex) [ 13.073309] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready [ 13.080445] IPv6: ADDRCONF(NETDEV_CHANGE): eth1.1: link becomes ready Since the UDP message was sent prior to link becoming ready, it was never seen on the wire. The default failsafe timeout is set to 2 seconds, so with this patch there are two attempts to send the message, one spent in vain, and the other visible in tcpdump on an attached host. Of course, in cases when the interface is brought up faster it leads to two messages, however it should be harmless. This patch (almost) doesn't affect normal boot time while still allowing to enter failsafe reliably with a single button press, matching the official "generic failsafe" documentation. Signed-off-by: Paul Fertser <fercerpav@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: rename hostname with EUI of mac addressRosy Song2019-11-071-0/+7
| | | | | | | | | | | | | | | If a label MAC address is provided for device, system will rename the hostname with OpenWrt_{eui mac address}. This helps to distinguish between different devices. Since it's no good idea to nest json_* functions, this code does not use get_mac_label directly, but only get_mac_label_dt as external resource. Signed-off-by: Rosy Song <rosysong@rosinson.com> [merged with commit introducing macaddr_geteui, rebased on updated label MAC address storage, extended commit message] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: don't store label MAC address in uci system configAdrian Schmutzler2019-11-071-3/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | If set, label MAC address is available from one of two sources, device tree or board.json. So far, the function get_mac_label was meant for retrieving the address, while an option in uci system config was specified only for case 2 (board.json). The uci config option has several drawbacks: - it is only used for a fraction of devices (those not in DT) - label MAC address is a device property, while config implies user interaction - label_macaddr option will only be set if /etc/config/system does not exist (i.e. only for new installations) Thus, this patch changes the behavior of get_mac_label: Instead of writing the value in board.json to uci system config and reading from this location afterwards, get_mac_label now extracts data from board.json directly. The uci config option won't be used anymore. In addition, two utility functions for extraction only from DT or from board.json are introduced. Since this is only changing the access to the label MAC address, it won't interfere with the addresses stored in the code base so far. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: uci-defaults: do config flush in one shotRoman Yeryomin2019-10-221-2/+1
| | | | | | | | | | | Moving a file between tmpfs and other fs is neither faster nor safer, thus no point in doing it in two steps. Use new jshn option to write output directly to file. Originally discussed here: http://lists.openwrt.org/pipermail/openwrt-devel/2017-December/010127.html Signed-off-by: Roman Yeryomin <roman@advem.lv>
* treewide: use a single ath10k MAC patching function with checksumAdrian Schmutzler2019-10-151-7/+1
| | | | | | | | | | | | | | | | While all ath10k eeproms have a checksum field, so far two functions for patching ath10k MAC address have been present (and been used). This merges code to provide a single function ath10k_patch_mac in caldata.sh, having its name in accordance with ath9k functions. By doing so, correct MAC patching for current and future ath10k devices should be ensured. This patch adds checksum adjustments for several targets on ath79 and lantiq. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* treewide: move MAC address patch functions to common libraryAdrian Schmutzler2019-10-141-0/+59
| | | | | | | | | This unifies MAC address patch functions and moves them to a common script. While those were implemented differently for different targets, they all seem to do the same. The number of different variants is significantly reduced by this patch. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* treewide: move calibration data extraction function to libraryAdrian Schmutzler2019-10-131-0/+75
| | | | | | | | | | | | | | | | | This moves the almost identical calibration data extraction functions present multiple times in several targets to a single library file /lib/functions/caldata.sh. Functions are renamed with more generic names to merge different variants that only differ in their names. Most of the targets used find_mtd_chardev, while some used find_mtd_part inside the extraction code. To merge them, the more abundant version with find_mtd_chardev is used in the common code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> [rebase on latest master; add mpc85xx] Signed-off-by: David Bauer <mail@david-bauer.net>
* base-files: move xor() from caldata extraction to functions.shAdrian Schmutzler2019-10-131-0/+16
| | | | | | | | The xor() function is defined in each of the caldata extraction scripts for several targets. Move it to functions.sh to reduce duplicate code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* 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>
* base-files: provide option to specify label MAC address in board.dAdrian Schmutzler2019-09-192-0/+9
| | | | | | | | | | | | | | For many devices, MAC addresses cannot be retrieved via the device tree alias. To still provide the label MAC address for those, this implements a second mechanism that will put the address into uci config. Note that this stores the actual MAC address, whereas in DTS we reference the bearing device. This is based on the work of Rosy Song <rosysong@rosinson.com> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: add function to retrieve label MAC addressAdrian Schmutzler2019-09-191-0/+10
| | | | | | | | | | | | | | | | To refer to the MAC address on a device's label, one can specify the alias label-mac-device in the DTS which should point to the bearer of the corresponding MAC address. With the function get_mac_label, the user can retrieve then retrieve this address and use it as a value that uniquely identifies his device. This is severely helpful for several downstream functionalities, e.g. define MAC addresses of custom netifs or change the SSID to be easily recognizable. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* 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>
* base-files: use get_mac_binary() in mtd_get_mac_binary_ubi()Adrian Schmutzler2019-09-051-6/+1
| | | | | | | | | | | | The actual retrieval of the MAC address in mtd_get_mac_binary_ubi() is the same as in get_mac_binary(). Thus, use the latter function in the former to reduce duplicate code. This will also allow to benefit from the enhanced path check there and bring mtd_get_mac_binary_ubi() more in line with the similar mtd_get_mac_binary(). Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: fix mtd_get_mac_text not accepting hex offsetsDavid Bauer2019-09-051-1/+1
| | | | | | | | | | | The mtd_get_mac_text helper method did not support hexadecimal offset values, resulting them to break after 75bfc393ba6c ("treewide: convert MAC address location offsets to hexadecimal") This commit fixes this by evaluating the hexadecimal input, converting them to decimal. Signed-off-by: David Bauer <mail@david-bauer.net>
* 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: Fix path check in get_mac_binaryAdrian Schmutzler2019-07-091-1/+1
| | | | | | | | | Logic was inverted when changing from string check to file check. Fix it. Fixes: 8592602d0a88 ("base-files: Really check path in get_mac_binary") Reported-by: Matthias Schiffer <mschiffer@universe-factory.net> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* 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: Really check path in get_mac_binaryAdrian Schmutzler2019-07-071-1/+1
| | | | | | | | Currently, path argument is only checked for being not empty. This changes behavior to actually check whether path exists. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: add network_get_uptime() to /lib/functions/network.shFlorian Eckert2019-06-291-0/+5
| | | | | | Add missing ubus api call for uptime value. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
* base-files: apply new sysctl.conf at postinstYousong Zhou2019-06-211-13/+20
| | | | | | | | | | | | | | | | This is mainly for kmod-br-netfilter. To turn off bridge-netfilter-call-xxx immediately after installation While at it - Define filelist="/usr/lib/opkg/info/${pkgname}.list" - Reuse "[ -z "$root" ]" - Grep with "-m1" Fixes FS#2300 Reported-by: Marco Sartorius <tidbits@ormoorgmen.info> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: fix uci led oneshot/timer triggerRobinson Wu2019-06-201-0/+1
| | | | | | | | | | | | | This patch adds a missing type property. This fixes the creation of oneshot and timer led triggers like: | ucidef_set_led_timer "system" "system" "zhuotk:green:system" "1000" "1000" from /etc/init.d/01_leds. Fixes: b06a286a4861 ("base-files: cleanup led functions in uci-defaults.sh") Signed-off-by: Robinson Wu <wurobinson@qq.com> Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
* base-files: move urandom seed bits into separate packagePetr Štetiar2019-06-111-24/+0
| | | | | | | So it's possible to install or remove it as needed. Tested-by: Lucian Cristian <lucian.cristian@gmail.com> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* base-files: add support for the new ar8xxx MIB counters settingsPetr Štetiar2019-05-201-0/+13
| | | | | | | | | | | | | Commit "generic: ar8216: add mib_poll_interval switch attribute" has added mib_poll_interval global config option and commit "generic: ar8216: group MIB counters and use two basic ones only by default" has added mib_type config option. So this patch adds ucidef_set_ar8xxx_switch_mib helper function which would allow configuration of the above mentioned new switch config options. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* 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>