diff mbox series

gpt: allow spaces in partition list

Message ID 20240627112904.99969-1-mikhail.kshevetskiy@iopsys.eu
State Accepted
Commit 72e77ab1c9ef744a9d25e25f151db2c99ffbb95d
Delegated to: Tom Rini
Headers show
Series gpt: allow spaces in partition list | expand

Commit Message

Mikhail Kshevetskiy June 27, 2024, 11:29 a.m. UTC
This allows spliting partition list to several lines in environment file

ex:
--------------------
gpt_partition_list=
	name=boot1,size=5MiB,start=0x100000;
	name=boot2,size=5MiB;
	name=rootfs1,size=70MiB;
	name=rootfs2,size=70MiB;
	name=overlay1,size=20MiB;
	name=overlay2,size=20MiB;
	name=art,size=4MiB;

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
 cmd/gpt.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Simon Glass June 27, 2024, 7:05 p.m. UTC | #1
Hi Mikhail,

On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy
<mikhail.kshevetskiy@iopsys.eu> wrote:
>
> This allows spliting partition list to several lines in environment file
>
> ex:
> --------------------
> gpt_partition_list=
>         name=boot1,size=5MiB,start=0x100000;
>         name=boot2,size=5MiB;
>         name=rootfs1,size=70MiB;
>         name=rootfs2,size=70MiB;
>         name=overlay1,size=20MiB;
>         name=overlay2,size=20MiB;
>         name=art,size=4MiB;

Is this referring to a .env file, i.e. a text environment file? If so,
I would hope that spaces at the start of a line would be automatically
removed.

>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
>  cmd/gpt.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 7aaf1889a5a..2b29ab98ccc 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
>                 k = strsep(&v, "=");
>                 if (!k)
>                         break;
> +               k += strspn(k, " \t");
>                 if  (strcmp(k, key) == 0) {
>                         new = strdup(v);
>                         break;
> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
>                 k = strsep(&s, ",");
>                 if (!k)
>                         break;
> +               k += strspn(k, " \t");
>                 if  (strcmp(k, key) == 0) {
>                         result = true;
>                         break;
> --
> 2.43.0
>

Regards,
Simon
Mikhail Kshevetskiy July 2, 2024, 9:42 a.m. UTC | #2
On 27.06.2024 22:05, Simon Glass wrote:
> Hi Mikhail,
>
> On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy
> <mikhail.kshevetskiy@iopsys.eu> wrote:
>> This allows spliting partition list to several lines in environment file
>>
>> ex:
>> --------------------
>> gpt_partition_list=
>>         name=boot1,size=5MiB,start=0x100000;
>>         name=boot2,size=5MiB;
>>         name=rootfs1,size=70MiB;
>>         name=rootfs2,size=70MiB;
>>         name=overlay1,size=20MiB;
>>         name=overlay2,size=20MiB;
>>         name=art,size=4MiB;
> Is this referring to a .env file, i.e. a text environment file? If so,
> I would hope that spaces at the start of a line would be automatically
> removed.

This is refer to a .env file, so starting space/tabs will be removed,
all '\n' will be replaced by spaces. Thus we will get a single line where
each partition divided from other with a single space (like below)

gpt_partition_list=name=boot1,size=5MiB,start=0x100000; name=boot2,size=5MiB; ...

>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>> ---
>>  cmd/gpt.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/cmd/gpt.c b/cmd/gpt.c
>> index 7aaf1889a5a..2b29ab98ccc 100644
>> --- a/cmd/gpt.c
>> +++ b/cmd/gpt.c
>> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
>>                 k = strsep(&v, "=");
>>                 if (!k)
>>                         break;
>> +               k += strspn(k, " \t");
>>                 if  (strcmp(k, key) == 0) {
>>                         new = strdup(v);
>>                         break;
>> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
>>                 k = strsep(&s, ",");
>>                 if (!k)
>>                         break;
>> +               k += strspn(k, " \t");
>>                 if  (strcmp(k, key) == 0) {
>>                         result = true;
>>                         break;
>> --
>> 2.43.0
>>
> Regards,
> Simon
Simon Glass July 2, 2024, 3:51 p.m. UTC | #3
Hi Mikhail,

On Tue, 2 Jul 2024 at 10:42, Mikhail Kshevetskiy
<mikhail.kshevetskiy@genexis.eu> wrote:
>
>
> On 27.06.2024 22:05, Simon Glass wrote:
> > Hi Mikhail,
> >
> > On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy
> > <mikhail.kshevetskiy@iopsys.eu> wrote:
> >> This allows spliting partition list to several lines in environment file
> >>
> >> ex:
> >> --------------------
> >> gpt_partition_list=
> >>         name=boot1,size=5MiB,start=0x100000;
> >>         name=boot2,size=5MiB;
> >>         name=rootfs1,size=70MiB;
> >>         name=rootfs2,size=70MiB;
> >>         name=overlay1,size=20MiB;
> >>         name=overlay2,size=20MiB;
> >>         name=art,size=4MiB;
> > Is this referring to a .env file, i.e. a text environment file? If so,
> > I would hope that spaces at the start of a line would be automatically
> > removed.
>
> This is refer to a .env file, so starting space/tabs will be removed,
> all '\n' will be replaced by spaces. Thus we will get a single line where
> each partition divided from other with a single space (like below)
>
> gpt_partition_list=name=boot1,size=5MiB,start=0x100000; name=boot2,size=5MiB; ...

Reviewed-by: Simon Glass <sjg@chromium.org>

But I wonder if the \t is needed?


>
> >> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> >> ---
> >>  cmd/gpt.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/cmd/gpt.c b/cmd/gpt.c
> >> index 7aaf1889a5a..2b29ab98ccc 100644
> >> --- a/cmd/gpt.c
> >> +++ b/cmd/gpt.c
> >> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
> >>                 k = strsep(&v, "=");
> >>                 if (!k)
> >>                         break;
> >> +               k += strspn(k, " \t");
> >>                 if  (strcmp(k, key) == 0) {
> >>                         new = strdup(v);
> >>                         break;
> >> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
> >>                 k = strsep(&s, ",");
> >>                 if (!k)
> >>                         break;
> >> +               k += strspn(k, " \t");
> >>                 if  (strcmp(k, key) == 0) {
> >>                         result = true;
> >>                         break;
> >> --
> >> 2.43.0
Regards,
Simon
Mikhail Kshevetskiy July 3, 2024, 1:29 a.m. UTC | #4
On 7/2/24 19:51, Simon Glass wrote:
> Hi Mikhail,
>
> On Tue, 2 Jul 2024 at 10:42, Mikhail Kshevetskiy
> <mikhail.kshevetskiy@genexis.eu> wrote:
>>
>> On 27.06.2024 22:05, Simon Glass wrote:
>>> Hi Mikhail,
>>>
>>> On Thu, 27 Jun 2024 at 12:29, Mikhail Kshevetskiy
>>> <mikhail.kshevetskiy@iopsys.eu> wrote:
>>>> This allows spliting partition list to several lines in environment file
>>>>
>>>> ex:
>>>> --------------------
>>>> gpt_partition_list=
>>>>         name=boot1,size=5MiB,start=0x100000;
>>>>         name=boot2,size=5MiB;
>>>>         name=rootfs1,size=70MiB;
>>>>         name=rootfs2,size=70MiB;
>>>>         name=overlay1,size=20MiB;
>>>>         name=overlay2,size=20MiB;
>>>>         name=art,size=4MiB;
>>> Is this referring to a .env file, i.e. a text environment file? If so,
>>> I would hope that spaces at the start of a line would be automatically
>>> removed.
>> This is refer to a .env file, so starting space/tabs will be removed,
>> all '\n' will be replaced by spaces. Thus we will get a single line where
>> each partition divided from other with a single space (like below)
>>
>> gpt_partition_list=name=boot1,size=5MiB,start=0x100000; name=boot2,size=5MiB; ...
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> But I wonder if the \t is needed?

no, \t is not mandatory. Spaces can be used instead.

>
>>>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>>>> ---
>>>>  cmd/gpt.c | 2 ++
>>>>  1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/cmd/gpt.c b/cmd/gpt.c
>>>> index 7aaf1889a5a..2b29ab98ccc 100644
>>>> --- a/cmd/gpt.c
>>>> +++ b/cmd/gpt.c
>>>> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
>>>>                 k = strsep(&v, "=");
>>>>                 if (!k)
>>>>                         break;
>>>> +               k += strspn(k, " \t");
>>>>                 if  (strcmp(k, key) == 0) {
>>>>                         new = strdup(v);
>>>>                         break;
>>>> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
>>>>                 k = strsep(&s, ",");
>>>>                 if (!k)
>>>>                         break;
>>>> +               k += strspn(k, " \t");
>>>>                 if  (strcmp(k, key) == 0) {
>>>>                         result = true;
>>>>                         break;
>>>> --
>>>> 2.43.0
> Regards,
> Simon
Sam Protsenko July 10, 2024, 2 a.m. UTC | #5
On Thu, Jun 27, 2024 at 6:29 AM Mikhail Kshevetskiy
<mikhail.kshevetskiy@iopsys.eu> wrote:
>
> This allows spliting partition list to several lines in environment file
>
> ex:
> --------------------
> gpt_partition_list=
>         name=boot1,size=5MiB,start=0x100000;
>         name=boot2,size=5MiB;
>         name=rootfs1,size=70MiB;
>         name=rootfs2,size=70MiB;
>         name=overlay1,size=20MiB;
>         name=overlay2,size=20MiB;
>         name=art,size=4MiB;
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---

Feel free to add:

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>

With this patch the next command succeeds, when having $partitions
described in multi-line variable in .env file:

    => gpt verify mmc 0 "$partitions"

I wonder if it makes sense to also change cmd_gen_envp command in
Makefile to avoid adding spaces in place of newlines, in the first
place? It would allow us to specify unbroken multi-line variables in
.env, though I'm not sure if anyone actually relies on that behavior
in their .env files.

>  cmd/gpt.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 7aaf1889a5a..2b29ab98ccc 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
>                 k = strsep(&v, "=");
>                 if (!k)
>                         break;
> +               k += strspn(k, " \t");
>                 if  (strcmp(k, key) == 0) {
>                         new = strdup(v);
>                         break;
> @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
>                 k = strsep(&s, ",");
>                 if (!k)
>                         break;
> +               k += strspn(k, " \t");
>                 if  (strcmp(k, key) == 0) {
>                         result = true;
>                         break;
> --
> 2.43.0
>
Sam Protsenko July 10, 2024, 11:23 p.m. UTC | #6
On Tue, Jul 9, 2024 at 9:00 PM Sam Protsenko <semen.protsenko@linaro.org> wrote:
>
> On Thu, Jun 27, 2024 at 6:29 AM Mikhail Kshevetskiy
> <mikhail.kshevetskiy@iopsys.eu> wrote:
> >
> > This allows spliting partition list to several lines in environment file
> >
> > ex:
> > --------------------
> > gpt_partition_list=
> >         name=boot1,size=5MiB,start=0x100000;
> >         name=boot2,size=5MiB;
> >         name=rootfs1,size=70MiB;
> >         name=rootfs2,size=70MiB;
> >         name=overlay1,size=20MiB;
> >         name=overlay2,size=20MiB;
> >         name=art,size=4MiB;
> >
> > Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> > ---
>
> Feel free to add:
>
> Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
> Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
>
> With this patch the next command succeeds, when having $partitions
> described in multi-line variable in .env file:
>
>     => gpt verify mmc 0 "$partitions"
>
> I wonder if it makes sense to also change cmd_gen_envp command in
> Makefile to avoid adding spaces in place of newlines, in the first
> place? It would allow us to specify unbroken multi-line variables in
> .env, though I'm not sure if anyone actually relies on that behavior
> in their .env files.
>

Tom, can you please apply this one? I think it actually fixes this existing env:

    board/sifive/unmatched/unmatched.env

which has multi-line $partitions definition in it. I'd also want to
keep $partitions in .env file (as opposed to .h) for E850-96 board in
my new series, which requires this patch to be applied as well.

Thanks!

> >  cmd/gpt.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/cmd/gpt.c b/cmd/gpt.c
> > index 7aaf1889a5a..2b29ab98ccc 100644
> > --- a/cmd/gpt.c
> > +++ b/cmd/gpt.c
> > @@ -117,6 +117,7 @@ static char *extract_val(const char *str, const char *key)
> >                 k = strsep(&v, "=");
> >                 if (!k)
> >                         break;
> > +               k += strspn(k, " \t");
> >                 if  (strcmp(k, key) == 0) {
> >                         new = strdup(v);
> >                         break;
> > @@ -151,6 +152,7 @@ static bool found_key(const char *str, const char *key)
> >                 k = strsep(&s, ",");
> >                 if (!k)
> >                         break;
> > +               k += strspn(k, " \t");
> >                 if  (strcmp(k, key) == 0) {
> >                         result = true;
> >                         break;
> > --
> > 2.43.0
> >
Tom Rini July 11, 2024, 9:27 p.m. UTC | #7
On Thu, 27 Jun 2024 14:29:04 +0300, Mikhail Kshevetskiy wrote:

> This allows spliting partition list to several lines in environment file
> 
> ex:
> --------------------
> gpt_partition_list=
> 	name=boot1,size=5MiB,start=0x100000;
> 	name=boot2,size=5MiB;
> 	name=rootfs1,size=70MiB;
> 	name=rootfs2,size=70MiB;
> 	name=overlay1,size=20MiB;
> 	name=overlay2,size=20MiB;
> 	name=art,size=4MiB;
> 
> [...]

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 7aaf1889a5a..2b29ab98ccc 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -117,6 +117,7 @@  static char *extract_val(const char *str, const char *key)
 		k = strsep(&v, "=");
 		if (!k)
 			break;
+		k += strspn(k, " \t");
 		if  (strcmp(k, key) == 0) {
 			new = strdup(v);
 			break;
@@ -151,6 +152,7 @@  static bool found_key(const char *str, const char *key)
 		k = strsep(&s, ",");
 		if (!k)
 			break;
+		k += strspn(k, " \t");
 		if  (strcmp(k, key) == 0) {
 			result = true;
 			break;