summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-11-24 11:24:30 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-11-30 09:41:20 +0100
commitf382be77f8c02cbaa94dc2664c3ab0d46775cab9 (patch)
tree76127cdc37396acf6801b43e957b6093a6dd1dba /common/oftree.c
parent1ac440d8149184f3de289e8596bfa516b8a65d66 (diff)
downloadbarebox-f382be77f8c02cbaa94dc2664c3ab0d46775cab9.tar.gz
barebox-f382be77f8c02cbaa94dc2664c3ab0d46775cab9.tar.xz
boot: introduce option to pass barebox-enabled watchdog to systemd
Like Linux, barebox supports co-existence of multiple watchdog devices. On boot, barebox enables only the default watchdog, which is defined as the watchdog with highest non-zero priority. The kernel handles all watchdogs the same and defers to userspace, which watchdogs to service. It can be useful to have barebox tell the system, which watchdog it activated, so it can service the same. Having this feature behind a global variable adds 354 bytes to a LZO compressed THUMB2 barebox. Users can opt out by toggling the Kconfig option, which defaults to off. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/oftree.c')
-rw-r--r--common/oftree.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 36906e86fc..075b9d6b8b 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -14,6 +14,8 @@
#include <bootsource.h>
#include <i2c/i2c.h>
#include <reset_source.h>
+#include <watchdog.h>
+#include <globalvar.h>
#define MAX_LEVEL 32 /* how deeply nested we will go */
@@ -139,6 +141,26 @@ static int of_fixup_bootargs_bootsource(struct device_node *root,
return ret;
}
+static void watchdog_build_bootargs(struct watchdog *watchdog, struct device_node *root)
+{
+ int alias_id;
+ char *buf;
+
+ if (!watchdog)
+ return;
+
+ alias_id = watchdog_get_alias_id_from(watchdog, root);
+ if (alias_id < 0)
+ return;
+
+ buf = basprintf("systemd.watchdog-device=/dev/watchdog%d", alias_id);
+ if (!buf)
+ return;
+
+ globalvar_add_simple("linux.bootargs.dyn.watchdog", buf);
+ free(buf);
+}
+
static int of_fixup_bootargs(struct device_node *root, void *unused)
{
struct device_node *node;
@@ -147,6 +169,9 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
int instance = reset_source_get_instance();
struct device_d *dev;
+ if (IS_ENABLED(CONFIG_SYSTEMD_OF_WATCHDOG))
+ watchdog_build_bootargs(boot_get_enabled_watchdog(), root);
+
str = linux_bootargs_get();
if (!str)
return 0;