diff mbox series

[1/7] Always link libubootenv

Message ID 20231009153152.416365-2-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Introduce SWUpdate environment | expand

Commit Message

Stefano Babic Oct. 9, 2023, 3:31 p.m. UTC
Library can be used to store an arbitrary set of variables and not only
the U-Boot's environment. This will be used to save application
variables and SWUpdate's state.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 Makefile.flags     |  5 +----
 bootloader/uboot.c | 25 +++++++------------------
 2 files changed, 8 insertions(+), 22 deletions(-)

Comments

Storm, Christian Nov. 28, 2023, 2:22 p.m. UTC | #1
Hi Stefano,

> On Oct 9, 2023, at 17:31, Stefano Babic <stefano.babic@swupdate.org> wrote:
> 
> Library can be used to store an arbitrary set of variables and not only
> the U-Boot's environment. This will be used to save application
> variables and SWUpdate's state.
> 
> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>

With this we have a problem with the BSDs: There's no MTD which is pretty
specific to Linux and libubootenv is quite tied to MTD in the sources.
I locally worked around this by wildly commenting stuff but that's not
a proper solution :)

Kind regards
  Christian
Stefano Babic Nov. 28, 2023, 6:08 p.m. UTC | #2
Hi Christian,

On 28.11.23 15:22, 'Storm, Christian' via swupdate wrote:
> Hi Stefano,
> 
>> On Oct 9, 2023, at 17:31, Stefano Babic <stefano.babic@swupdate.org> wrote:
>>
>> Library can be used to store an arbitrary set of variables and not only
>> the U-Boot's environment. This will be used to save application
>> variables and SWUpdate's state.
>>
>> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
> 
> With this we have a problem with the BSDs: There's no MTD which is pretty
> specific to Linux and libubootenv is quite tied to MTD in the sources.
> I locally worked around this by wildly commenting stuff but that's not
> a proper solution :)

I know this, it was on my TODO list. I have moved MTD's related function 
to a separate file. I send a RFC patch to improve this, let me know what 
you mind.

With the patch I am able to build on FreeBSD 13.2.

Best regards,
Stefano

> 
> Kind regards
>    Christian
>
Storm, Christian Nov. 28, 2023, 9:29 p.m. UTC | #3
Hi Stefano,

>>> Library can be used to store an arbitrary set of variables and not only
>>> the U-Boot's environment. This will be used to save application
>>> variables and SWUpdate's state.
>>> 
>>> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
>> With this we have a problem with the BSDs: There's no MTD which is pretty
>> specific to Linux and libubootenv is quite tied to MTD in the sources.
>> I locally worked around this by wildly commenting stuff but that's not
>> a proper solution :)
> 
> I know this, it was on my TODO list. I have moved MTD's related function to a separate file. I send a RFC patch to improve this, let me know what you mind.
> 
> With the patch I am able to build on FreeBSD 13.2.


Perfect, thanks for this! A quick compile test works. I'm going to test it further...


P.S.: I had to grab the patch from patchwork as it's malformed. Is it OK in
your Inbox? Then it's another thing to blame our corporate mail server for..


Kind regards,
  Christian
Stefano Babic Nov. 28, 2023, 9:35 p.m. UTC | #4
Hi Christian,

On 28.11.23 22:29, 'Storm, Christian' via swupdate wrote:
> Hi Stefano,
> 
>>>> Library can be used to store an arbitrary set of variables and not only
>>>> the U-Boot's environment. This will be used to save application
>>>> variables and SWUpdate's state.
>>>>
>>>> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
>>> With this we have a problem with the BSDs: There's no MTD which is pretty
>>> specific to Linux and libubootenv is quite tied to MTD in the sources.
>>> I locally worked around this by wildly commenting stuff but that's not
>>> a proper solution :)
>>
>> I know this, it was on my TODO list. I have moved MTD's related function to a separate file. I send a RFC patch to improve this, let me know what you mind.
>>
>> With the patch I am able to build on FreeBSD 13.2.
> 
> 
> Perfect, thanks for this! A quick compile test works. I'm going to test it further...
> 
> 
> P.S.: I had to grab the patch from patchwork as it's malformed. Is it OK in
> your Inbox? 

Yes, I tested again with:

$ git checkout -b tmp master
Switched to a new branch 'tmp'

$ pwclient git-am 1869413
Applying patch #1869413 using "git am"
Description: [libubootenv,RFC] Move MTD related function to separate file
Applying: Move MTD related function to separate file
.git/rebase-apply/patch:1179: new blank line at EOF.
+
warning: 1 line adds whitespace errors.


> Then it's another thing to blame our corporate mail server for..

+1

Stefano
diff mbox series

Patch

diff --git a/Makefile.flags b/Makefile.flags
index 2d27a8f8..fa9936a1 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -106,7 +106,7 @@  export SYSROOT=$(CONFIG_SYSROOT)
 endif
 
 # Links always pthread
-LDLIBS += pthread
+LDLIBS += pthread ubootenv
 # lua
 ifneq ($(CONFIG_LUA),)
 LDFLAGS_swupdate += -Wl,-E
@@ -219,9 +219,6 @@  endif
 
 
 ifeq ($(CONFIG_BOOTLOADER_STATIC_LINKED),y)
-ifeq ($(CONFIG_UBOOT),y)
-LDLIBS += ubootenv
-endif
 ifeq ($(CONFIG_BOOTLOADER_EBG),y)
 LDLIBS += ebgenv
 endif
diff --git a/bootloader/uboot.c b/bootloader/uboot.c
index 7f0e04a6..4be034df 100644
--- a/bootloader/uboot.c
+++ b/bootloader/uboot.c
@@ -126,9 +126,15 @@  static bootloader uboot = {
 	.apply_list = &do_apply_list
 };
 
+/*
+ * libubootenv is not only used as interface to U-Boot.
+ * It is also used to save SWUpdate's persistent variables that
+ * survives after a restart of the device but should not be
+ * considered by the bootloader. That requires libubootenv
+ * is always linked.
+ */
 static bootloader* probe(void)
 {
-#if defined(BOOTLOADER_STATIC_LINKED)
 	libuboot.open = libuboot_open;
 	libuboot.close = libuboot_close;
 	libuboot.exit = libuboot_exit;
@@ -138,23 +144,6 @@  static bootloader* probe(void)
 	libuboot.load_file = libuboot_load_file;
 	libuboot.set_env = libuboot_set_env;
 	libuboot.env_store = libuboot_env_store;
-#else
-	void* handle = dlopen("libubootenv.so.0", RTLD_NOW | RTLD_GLOBAL);
-	if (!handle) {
-		return NULL;
-	}
-
-	(void)dlerror();
-	load_symbol(handle, &libuboot.open, "libuboot_open");
-	load_symbol(handle, &libuboot.close, "libuboot_close");
-	load_symbol(handle, &libuboot.exit, "libuboot_exit");
-	load_symbol(handle, &libuboot.initialize, "libuboot_initialize");
-	load_symbol(handle, &libuboot.get_env, "libuboot_get_env");
-	load_symbol(handle, &libuboot.read_config, "libuboot_read_config");
-	load_symbol(handle, &libuboot.load_file, "libuboot_load_file");
-	load_symbol(handle, &libuboot.set_env, "libuboot_set_env");
-	load_symbol(handle, &libuboot.env_store, "libuboot_env_store");
-#endif
 	return &uboot;
 }