mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] bbu: command: update via TFTP if no image given
@ 2024-07-01  7:14 Ahmad Fatoum
  2024-07-01 10:08 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-01  7:14 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>
---
 commands/barebox-update.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index 4b23433e84f2..59db315e5650 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[PATH_MAX];
 	int opt, ret, repair = 0;
 	struct bbu_data data = {};
 	struct bbu_handler *handler;
@@ -82,14 +84,17 @@ static int do_barebox_update(int argc, char *argv[])
 
 	if (argc - optind > 0) {
 		data.imagefile = argv[optind];
+	} else if (!repair) {
+		snprintf(pathbuf, sizeof(pathbuf), "/mnt/tftp/%s-barebox-%s",
+			 globalvar_get("user"), globalvar_get("hostname"));
+		data.imagefile = pathbuf;
+	}
 
+	if (data.imagefile) {
 		image = read_file(data.imagefile, &data.len);
 		if (!image)
 			return -errno;
 		data.image = image;
-	} else {
-		if (!repair)
-			return COMMAND_ERROR_USAGE;
 	}
 
 	ret = barebox_update(&data, handler);
-- 
2.39.2




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

* Re: [PATCH] bbu: command: update via TFTP if no image given
  2024-07-01  7:14 [PATCH] bbu: command: update via TFTP if no image given Ahmad Fatoum
@ 2024-07-01 10:08 ` Sascha Hauer
  2024-07-01 10:11   ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2024-07-01 10:08 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jul 01, 2024 at 09:14:55AM +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}
> 
> 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>
> ---
>  commands/barebox-update.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/commands/barebox-update.c b/commands/barebox-update.c
> index 4b23433e84f2..59db315e5650 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[PATH_MAX];

Do we really want to allocate 1KiB on the stack?

sascha

>  	int opt, ret, repair = 0;
>  	struct bbu_data data = {};
>  	struct bbu_handler *handler;
> @@ -82,14 +84,17 @@ static int do_barebox_update(int argc, char *argv[])
>  
>  	if (argc - optind > 0) {
>  		data.imagefile = argv[optind];
> +	} else if (!repair) {
> +		snprintf(pathbuf, sizeof(pathbuf), "/mnt/tftp/%s-barebox-%s",
> +			 globalvar_get("user"), globalvar_get("hostname"));
> +		data.imagefile = pathbuf;
> +	}
>  
> +	if (data.imagefile) {
>  		image = read_file(data.imagefile, &data.len);
>  		if (!image)
>  			return -errno;
>  		data.image = image;
> -	} else {
> -		if (!repair)
> -			return COMMAND_ERROR_USAGE;
>  	}
>  
>  	ret = barebox_update(&data, handler);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

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

Hello Sascha,

On 01.07.24 12:08, Sascha Hauer wrote:
> On Mon, Jul 01, 2024 at 09:14:55AM +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}
>>
>> 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>
>> ---
>>  commands/barebox-update.c | 11 ++++++++---
>>  1 file changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/commands/barebox-update.c b/commands/barebox-update.c
>> index 4b23433e84f2..59db315e5650 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[PATH_MAX];
> 
> Do we really want to allocate 1KiB on the stack?

The default STACK_SIZE is 32K, so it should be ok normally, but I can switch
this to a dynamic allocation for v2 if you prefer.

Cheers,
Ahmad

> 
> sascha
> 
>>  	int opt, ret, repair = 0;
>>  	struct bbu_data data = {};
>>  	struct bbu_handler *handler;
>> @@ -82,14 +84,17 @@ static int do_barebox_update(int argc, char *argv[])
>>  
>>  	if (argc - optind > 0) {
>>  		data.imagefile = argv[optind];
>> +	} else if (!repair) {
>> +		snprintf(pathbuf, sizeof(pathbuf), "/mnt/tftp/%s-barebox-%s",
>> +			 globalvar_get("user"), globalvar_get("hostname"));
>> +		data.imagefile = pathbuf;
>> +	}
>>  
>> +	if (data.imagefile) {
>>  		image = read_file(data.imagefile, &data.len);
>>  		if (!image)
>>  			return -errno;
>>  		data.image = image;
>> -	} else {
>> -		if (!repair)
>> -			return COMMAND_ERROR_USAGE;
>>  	}
>>  
>>  	ret = barebox_update(&data, handler);
>> -- 
>> 2.39.2
>>
>>
>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

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

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

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