Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From 434c75d73a065b93f708cf856fb88c5b5f0dd778 Mon Sep 17 00:00:00 2001
From: Frieder Schrempf <frieder.schrempf@kontron.de>
Date: Wed, 16 Aug 2023 11:11:50 +0200
Subject: [libubootenv][PATCH 1/3] Try to autoselect namespace based on DT
property
The bootloader might be able to tell us where the currently used
environment is located. Use the string from the
"/chosen/u-boot,env-config" devicetree property as namespace
selector if available.
Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---
src/fw_printenv.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/fw_printenv.c b/src/fw_printenv.c
index e475e43..6118324 100644
--- a/src/fw_printenv.c
+++ b/src/fw_printenv.c
@@ -87,6 +87,9 @@ int main (int argc, char **argv) {
bool noheader = false;
bool default_used = false;
struct uboot_version_info *version;
+ char dt_namespace[32];
+ size_t dt_ret;
+ FILE *fp;
/*
* As old tool, there is just a tool with symbolic link
@@ -144,8 +147,22 @@ int main (int argc, char **argv) {
fprintf(stderr, "Cannot initialize environment\n");
exit(1);
}
+
if (namespace)
ctx = libuboot_get_namespace(ctx, namespace);
+ else {
+ fp = fopen("/proc/device-tree/chosen/u-boot,env-config", "r");
+ if(fp) {
+ dt_ret = fread(dt_namespace, 1, sizeof(dt_namespace) - 1, fp);
+ if (dt_ret) {
+ dt_namespace[dt_ret] = 0;
+ ctx = libuboot_get_namespace(ctx, dt_namespace);
+ }
+
+ fclose(fp);
+ }
+ }
+
if (!ctx) {
fprintf(stderr, "Namespace %s not found\n", namespace);
exit (1);
--
2.41.0