Re: [U-Boot] [PATCH] pxe: Allow use of environment variables in append string

2014-08-04 Thread Hans de Goede
Hi,

On 08/01/2014 09:07 PM, Stephen Warren wrote:
 On 08/01/2014 03:21 AM, Hans de Goede wrote:
 Use run_command(setenv bootargs label-append) so that environment
 variables (e.g. $console) can be used in append strings.
 
 I'm slightly worried that this changes the semantics of the append line in 
 the PXE/extlinux config file. Namely, you suddenly have to start worrying 
 about escaping any $ signs or semi-colons etc..

I'm not that worried about $ needing escaping, as I cannot think
of any kernel commandline options using $, maybe they exist but if
they do they are quite rare.

But you make a good point about the ; I know some kernel cmdline
options which use those...

 
 diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
 
   if (!localcmd)
   return -ENOENT;

 -if (label-append)
 -setenv(bootargs, label-append);
 +if (label-append) {
 +bootargs = malloc(strlen(setenv bootargs ) +
 +  strlen(label-append) + 1);
 +if (!bootargs)
 +return 1;
 
 Shouldn't this return a -ve error code for consistency with the other 
 pre-existing error case I quoted above.

Yeah this is weird, I copy pasted this from
the label_boot() function, of which is a special version,
also label_boot() is the only caller of label_localboot()
(where this hunk applies), and it does not check the return
value at all...

I could make it -ENOMEM if you prefer.


 +strcpy(bootargs, setenv bootargs );
 +strcat(bootargs, label-append);
 +run_command(bootargs, 0);
 
 Using whatever C function that the shell uses to expand variable references 
 in the command-line, rather than run_command(), would at least avoid the 
 issue of ; in label-append causing part of label-append after the ; to be 
 execututed as a separate command.

Ack, I'll look into that and post a v2 with that change.

 There would still be the issue of $ suddenly meaning something different.

Right, but as said I'm not really worried about that.

Regards,

Hans
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] pxe: Allow use of environment variables in append string

2014-08-01 Thread Hans de Goede
Use run_command(setenv bootargs label-append) so that environment
variables (e.g. $console) can be used in append strings.

Signed-off-by: Hans de Goede hdego...@redhat.com
---
 common/cmd_pxe.c | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
index ba48692..3866604 100644
--- a/common/cmd_pxe.c
+++ b/common/cmd_pxe.c
@@ -571,14 +571,23 @@ static void label_print(void *data)
 static int label_localboot(struct pxe_label *label)
 {
char *localcmd;
+   char *bootargs;
 
localcmd = from_env(localcmd);
 
if (!localcmd)
return -ENOENT;
 
-   if (label-append)
-   setenv(bootargs, label-append);
+   if (label-append) {
+   bootargs = malloc(strlen(setenv bootargs ) +
+ strlen(label-append) + 1);
+   if (!bootargs)
+   return 1;
+   strcpy(bootargs, setenv bootargs );
+   strcat(bootargs, label-append);
+   run_command(bootargs, 0);
+   free(bootargs);
+   }
 
debug(running: %s\n, localcmd);
 
@@ -669,17 +678,17 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label 
*label)
len += strlen(label-append);
 
if (len) {
-   bootargs = malloc(len + 1);
+   bootargs = malloc(strlen(setenv bootargs ) + len + 1);
if (!bootargs)
return 1;
-   bootargs[0] = '\0';
+   strcpy(bootargs, setenv bootargs );
if (label-append)
-   strcpy(bootargs, label-append);
+   strcat(bootargs, label-append);
strcat(bootargs, ip_str);
strcat(bootargs, mac_str);
 
-   setenv(bootargs, bootargs);
-   printf(append: %s\n, bootargs);
+   run_command(bootargs, 0);
+   printf(append: %s\n, getenv(bootargs));
 
free(bootargs);
}
-- 
2.0.3

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] pxe: Allow use of environment variables in append string

2014-08-01 Thread Stephen Warren

On 08/01/2014 03:21 AM, Hans de Goede wrote:

Use run_command(setenv bootargs label-append) so that environment
variables (e.g. $console) can be used in append strings.


I'm slightly worried that this changes the semantics of the append line 
in the PXE/extlinux config file. Namely, you suddenly have to start 
worrying about escaping any $ signs or semi-colons etc..



diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c



if (!localcmd)
return -ENOENT;

-   if (label-append)
-   setenv(bootargs, label-append);
+   if (label-append) {
+   bootargs = malloc(strlen(setenv bootargs ) +
+ strlen(label-append) + 1);
+   if (!bootargs)
+   return 1;


Shouldn't this return a -ve error code for consistency with the other 
pre-existing error case I quoted above.



+   strcpy(bootargs, setenv bootargs );
+   strcat(bootargs, label-append);
+   run_command(bootargs, 0);


Using whatever C function that the shell uses to expand variable 
references in the command-line, rather than run_command(), would at 
least avoid the issue of ; in label-append causing part of 
label-append after the ; to be execututed as a separate command.


There would still be the issue of $ suddenly meaning something different.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot