* [U-Boot] [PATCH] pxe: Allow use of environment variables in append string
@ 2014-08-01 9:21 Hans de Goede
2014-08-01 19:07 ` Stephen Warren
0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2014-08-01 9:21 UTC (permalink / raw)
To: u-boot
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 <hdegoede@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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] pxe: Allow use of environment variables in append string
2014-08-01 9:21 [U-Boot] [PATCH] pxe: Allow use of environment variables in append string Hans de Goede
@ 2014-08-01 19:07 ` Stephen Warren
2014-08-04 18:29 ` Hans de Goede
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Warren @ 2014-08-01 19:07 UTC (permalink / raw)
To: u-boot
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] pxe: Allow use of environment variables in append string
2014-08-01 19:07 ` Stephen Warren
@ 2014-08-04 18:29 ` Hans de Goede
0 siblings, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2014-08-04 18:29 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-04 18:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 9:21 [U-Boot] [PATCH] pxe: Allow use of environment variables in append string Hans de Goede
2014-08-01 19:07 ` Stephen Warren
2014-08-04 18:29 ` Hans de Goede
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.