mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] bbu: command: update via TFTP if no image given
@ 2024-07-01 10:22 Ahmad Fatoum
  2024-07-01 13:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-07-01 10:22 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Booting barebox over TFTP is a common operation that even has a default
boot target: `boot bnet`.

Once, a chainloaded barebox was tested to work, it may need to be
persisted, which needs a cumbersome:

  barebox_update /mnt/tftp/${global.user}-barebox-${global.hostname}

Make this more straight-forward by interpreting barebox_update called
without any non-option argument to mean just that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
   - only fallback to /mnt/tftp if TFTP filesystem support is enabled
   - allocate pathbuffer dynamically instead of on the stack (Sascha)
---
 commands/barebox-update.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 4b23433e84f2..a50de505007a 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <command.h>
 #include <libfile.h>
+#include <globalvar.h>
 #include <getopt.h>
 #include <malloc.h>
 #include <errno.h>
@@ -20,6 +21,7 @@ static void print_handlers_list(void)
 
 static int do_barebox_update(int argc, char *argv[])
 {
+	char *pathbuf = NULL;
 	int opt, ret, repair = 0;
 	struct bbu_data data = {};
 	struct bbu_handler *handler;
@@ -82,19 +84,34 @@ static int do_barebox_update(int argc, char *argv[])
 
 	if (argc - optind > 0) {
 		data.imagefile = argv[optind];
-
-		image = read_file(data.imagefile, &data.len);
-		if (!image)
-			return -errno;
-		data.image = image;
-	} else {
-		if (!repair)
+	} else if (!repair) {
+		if (!IS_ENABLED(CONFIG_FS_TFTP))
 			return COMMAND_ERROR_USAGE;
+
+		pathbuf = basprintf("/mnt/tftp/%s-barebox-%s",
+				    globalvar_get("user"), globalvar_get("hostname"));
+		if (!pathbuf) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		data.imagefile = pathbuf;
+	}
+
+	if (data.imagefile) {
+		image = read_file(data.imagefile, &data.len);
+		if (!image) {
+			ret = -errno;
+			goto out;
+		}
+		data.image = image;
 	}
 
 	ret = barebox_update(&data, handler);
 
 	free(image);
+out:
+	free(pathbuf);
 
 	return ret;
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] bbu: command: update via TFTP if no image given
  2024-07-01 10:22 [PATCH v2] bbu: command: update via TFTP if no image given Ahmad Fatoum
@ 2024-07-01 13:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-07-01 13:23 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 01 Jul 2024 12:22:29 +0200, Ahmad Fatoum wrote:
> Booting barebox over TFTP is a common operation that even has a default
> boot target: `boot bnet`.
> 
> Once, a chainloaded barebox was tested to work, it may need to be
> persisted, which needs a cumbersome:
> 
>   barebox_update /mnt/tftp/${global.user}-barebox-${global.hostname}
> 
> [...]

Applied, thanks!

[1/1] bbu: command: update via TFTP if no image given
      https://git.pengutronix.de/cgit/barebox/commit/?id=34beebcfe2ca (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-01 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01 10:22 [PATCH v2] bbu: command: update via TFTP if no image given Ahmad Fatoum
2024-07-01 13:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox