diff mbox

[U-Boot,3/3] MAKEALL: fix boards_by_field function

Message ID 1381995462-32556-4-git-send-email-yamada.m@jp.panasonic.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Oct. 17, 2013, 7:37 a.m. UTC
Commit 27af930e changed the boards.cfg format
and it changed boards_by_field() function incorrectly.
For tegra cpus it returned Board Name field,
not Target field.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
---

Commit 27af930e adjusted this part like follows:


                    -v field="$1" \
                    -v select="$2" \
                    -F "$FS" \
    -               '($1 !~ /^#/ && $field == select) { print $1 }' \
    +               '($1 !~ /^#/ && $field == select) { print $7 }' \
                    boards.cfg
     }
     boards_by_arch() { boards_by_field 2 "$@" ; }
     boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
    -boards_by_soc()  { boards_by_field 6 "$@" ; }
    +boards_by_soc()  { boards_by_field 4 "$@" ; }


TAB is also treated as a field speparator, so
we should have taken the 8th field for Tegra
whereas the 7th field for the other cpus.

Fortunately, Board Name field and Target filed are the same
for all Tegra LSIs.
But we should not expect it.



 MAKEALL | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Albert ARIBAUD Oct. 17, 2013, 8:52 a.m. UTC | #1
Hi Masahiro,

On Thu, 17 Oct 2013 16:37:42 +0900, Masahiro Yamada
<yamada.m@jp.panasonic.com> wrote:

> Commit 27af930e changed the boards.cfg format
> and it changed boards_by_field() function incorrectly.
> For tegra cpus it returned Board Name field,
> not Target field.
> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> 
> Commit 27af930e adjusted this part like follows:
> 
> 
>                     -v field="$1" \
>                     -v select="$2" \
>                     -F "$FS" \
>     -               '($1 !~ /^#/ && $field == select) { print $1 }' \
>     +               '($1 !~ /^#/ && $field == select) { print $7 }' \
>                     boards.cfg
>      }
>      boards_by_arch() { boards_by_field 2 "$@" ; }
>      boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
>     -boards_by_soc()  { boards_by_field 6 "$@" ; }
>     +boards_by_soc()  { boards_by_field 4 "$@" ; }
> 
> 
> TAB is also treated as a field speparator, so
> we should have taken the 8th field for Tegra
> whereas the 7th field for the other cpus.
> 
> Fortunately, Board Name field and Target filed are the same
> for all Tegra LSIs.
> But we should not expect it.

Not sure I am following here, as the commit you mention does not
change how tabs are processed.

Besides, the system should *not* be sensitive to tabs. If it is, this
must be fixed and tabs removed.

Amicalement,
Masahiro Yamada Oct. 17, 2013, 8:58 a.m. UTC | #2
Hello Albert.


> > Commit 27af930e adjusted this part like follows:
> > 
> > 
> >                     -v field="$1" \
> >                     -v select="$2" \
> >                     -F "$FS" \
> >     -               '($1 !~ /^#/ && $field == select) { print $1 }' \
> >     +               '($1 !~ /^#/ && $field == select) { print $7 }' \
> >                     boards.cfg
> >      }
> >      boards_by_arch() { boards_by_field 2 "$@" ; }
> >      boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
> >     -boards_by_soc()  { boards_by_field 6 "$@" ; }
> >     +boards_by_soc()  { boards_by_field 4 "$@" ; }
> > 
> > 
> > TAB is also treated as a field speparator, so
> > we should have taken the 8th field for Tegra
> > whereas the 7th field for the other cpus.
> > 
> > Fortunately, Board Name field and Target filed are the same
> > for all Tegra LSIs.
> > But we should not expect it.
> 
> Not sure I am following here, as the commit you mention does not
> change how tabs are processed.
> 
> Besides, the system should *not* be sensitive to tabs. If it is, this
> must be fixed and tabs removed.


Sorry, my mistake.

s/TAB/colon/


The comment should be:

Colon is also treated as a field speparator, so
we should have taken the 8th field for Tegra
whereas the 7th field for the other cpus.



Best Regards
Masahiro Yamada
Albert ARIBAUD Oct. 17, 2013, 9:41 a.m. UTC | #3
Hi Masahiro,

On Thu, 17 Oct 2013 16:37:42 +0900, Masahiro Yamada
<yamada.m@jp.panasonic.com> wrote:

> Commit 27af930e changed the boards.cfg format
> and it changed boards_by_field() function incorrectly.
> For tegra cpus it returned Board Name field,
> not Target field.
> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
> 
> Commit 27af930e adjusted this part like follows:
> 
> 
>                     -v field="$1" \
>                     -v select="$2" \
>                     -F "$FS" \
>     -               '($1 !~ /^#/ && $field == select) { print $1 }' \
>     +               '($1 !~ /^#/ && $field == select) { print $7 }' \
>                     boards.cfg
>      }
>      boards_by_arch() { boards_by_field 2 "$@" ; }
>      boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
>     -boards_by_soc()  { boards_by_field 6 "$@" ; }
>     +boards_by_soc()  { boards_by_field 4 "$@" ; }
> 
> 
> TAB is also treated as a field speparator, so
> we should have taken the 8th field for Tegra
> whereas the 7th field for the other cpus.

(As per our discussion, 'tab' here should be 'colon')

Not sure I am getting the logic here. Colon is *not* a field separator,
precisely because it is not present on all lines; it is a sub-field
separator. At this low level, the only field separator should be spaces.

Therefore, I would prefer boards_by_field() and board_by_cpu() to *not*
handle colons and thus consider the CPU field as a whole even when it
consists in a cpu:splcpu pair.

Splitting that pair and using either cpu or splcpu depending on
whether building SPL or not should only happen when the CPU field is
actually used, not fetched.

Can you try and provide a v2 patch (set) along these lines?

Amicalement,
Masahiro Yamada Oct. 17, 2013, 10:32 a.m. UTC | #4
Hello Albert




> >                     -v field="$1" \
> >                     -v select="$2" \
> >                     -F "$FS" \
> >     -               '($1 !~ /^#/ && $field == select) { print $1 }' \
> >     +               '($1 !~ /^#/ && $field == select) { print $7 }' \
> >                     boards.cfg
> >      }
> >      boards_by_arch() { boards_by_field 2 "$@" ; }
> >      boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
> >     -boards_by_soc()  { boards_by_field 6 "$@" ; }
> >     +boards_by_soc()  { boards_by_field 4 "$@" ; }
> > 
> > 
> > TAB is also treated as a field speparator, so
> > we should have taken the 8th field for Tegra
> > whereas the 7th field for the other cpus.
> 
> (As per our discussion, 'tab' here should be 'colon')

Yes, I answerd so in my previous reply.


> Not sure I am getting the logic here. Colon is *not* a field separator,
> precisely because it is not present on all lines; it is a sub-field
> separator. At this low level, the only field separator should be spaces.
> 
> Therefore, I would prefer boards_by_field() and board_by_cpu() to *not*
> handle colons and thus consider the CPU field as a whole even when it
> consists in a cpu:splcpu pair.

Yes. I think I already did this in my v1 patch.


  +		-v cut="$3" \
  +		'{sub(cut,"",$field)}

These lines split the pair into cpu and spl_cpu.
I simply cut down  spl_cpu because it is the same behaviour
as before Commit 27af930e.



> Splitting that pair and using either cpu or splcpu depending on
> whether building SPL or not should only happen when the CPU field is
> actually used, not fetched.
> 
> Can you try and provide a v2 patch (set) along these lines?


Sorry, I cannot understand what you mean.


Best Regards
Masahiro Yamada
Albert ARIBAUD Oct. 17, 2013, 11:41 a.m. UTC | #5
Hi Masahiro,

On Thu, 17 Oct 2013 19:32:31 +0900, Masahiro Yamada
<yamada.m@jp.panasonic.com> wrote:

> Hello Albert
> 
> 
> 
> 
> > >                     -v field="$1" \
> > >                     -v select="$2" \
> > >                     -F "$FS" \
> > >     -               '($1 !~ /^#/ && $field == select) { print $1 }' \
> > >     +               '($1 !~ /^#/ && $field == select) { print $7 }' \
> > >                     boards.cfg
> > >      }
> > >      boards_by_arch() { boards_by_field 2 "$@" ; }
> > >      boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
> > >     -boards_by_soc()  { boards_by_field 6 "$@" ; }
> > >     +boards_by_soc()  { boards_by_field 4 "$@" ; }
> > > 
> > > 
> > > TAB is also treated as a field speparator, so
> > > we should have taken the 8th field for Tegra
> > > whereas the 7th field for the other cpus.
> > 
> > (As per our discussion, 'tab' here should be 'colon')
> 
> Yes, I answerd so in my previous reply.
> 
> 
> > Not sure I am getting the logic here. Colon is *not* a field separator,
> > precisely because it is not present on all lines; it is a sub-field
> > separator. At this low level, the only field separator should be spaces.
> > 
> > Therefore, I would prefer boards_by_field() and board_by_cpu() to *not*
> > handle colons and thus consider the CPU field as a whole even when it
> > consists in a cpu:splcpu pair.
> 
> Yes. I think I already did this in my v1 patch.
> 
> 
>   +		-v cut="$3" \
>   +		'{sub(cut,"",$field)}
> 
> These lines split the pair into cpu and spl_cpu.
> I simply cut down  spl_cpu because it is the same behaviour
> as before Commit 27af930e.
> 
> 
> 
> > Splitting that pair and using either cpu or splcpu depending on
> > whether building SPL or not should only happen when the CPU field is
> > actually used, not fetched.
> > 
> > Can you try and provide a v2 patch (set) along these lines?
> 
> 
> Sorry, I cannot understand what you mean.

I do understand that your patch wants to restore the behavior prior to
27af930e.

My problem is, while things worked prior to 27af930e, they were not
done the right way, because boards_by_<field>() functions should not
depend on the fact that a field contains a colon or not; they should
only depend on the fact that fields are space-separated.

IOW, target integratorcp_cm1136 on line 46 in boards.cfg has 9 fields,
and its CPU field is "arm1136"; and line 348, dalmore, *also* has 9
fields even though its CPU field is "armv7:arm720t".

The way the code is written now, board_by_field() has to do the job of 
board_by_cpu() and has to know the CPU field has colon-separated
subfields. What should be done is, board_by_field should not even worry
about colons at all, and it is board_by_cpu() which should know about
CPU dubfields and treat them properly.

Is this clearer?

> Best Regards
> Masahiro Yamada
> 


Amicalement,
Masahiro Yamada Oct. 18, 2013, 6:37 a.m. UTC | #6
Hello Albert.


> The way the code is written now, board_by_field() has to do the job of 
> board_by_cpu() and has to know the CPU field has colon-separated
> subfields. What should be done is, board_by_field should not even worry
> about colons at all, and it is board_by_cpu() which should know about
> CPU dubfields and treat them properly.
> 
> Is this clearer?


OK. It's clear now.

I re-wrote like follows:


boards_by_field()
{
	field=$1
	regexp=$2

	awk '($1 !~ /^#/ && $'"$field"' ~ /^'"$regexp"'$/) { print $7 }' \
		boards.cfg
}

boards_by_arch() { boards_by_field 2 "$@" ; }
boards_by_cpu()  { boards_by_field 3 "$@" ; boards_by_field 3 "$@:.*" ; }
boards_by_soc()  { boards_by_field 4 "$@" ; }



Is this good enough?




BTW, I think these function names are misleading.


We want to get the 7th field (Target),
not 6th field (Board Name) of boards.cfg
by these functions.


So I think we should rename

s/boards_by_field/targets_by_field/
s/boards_by_arch/targets_by_arch/
s/boards_by_cpu/targets_by_cpu/
s/boards_by_soc/targets_by_soc/



Best Regards
Masahiro Yamada
Masahiro Yamada Oct. 21, 2013, 10:09 a.m. UTC | #7
Hello Albert.

> 
> The way the code is written now, board_by_field() has to do the job of 
> board_by_cpu() and has to know the CPU field has colon-separated
> subfields. What should be done is, board_by_field should not even worry
> about colons at all, and it is board_by_cpu() which should know about
> CPU dubfields and treat them properly.
> 
> Is this clearer?
> 

I posted v2.

Best Regards
Masahiro Yamada
diff mbox

Patch

diff --git a/MAKEALL b/MAKEALL
index 4f685e1..485721e 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -226,17 +226,17 @@  RC=0
 # Helper funcs for parsing boards.cfg
 boards_by_field()
 {
-	FS="[ \t]+"
-	[ -n "$3" ] && FS="$3"
 	awk \
 		-v field="$1" \
 		-v select="$2" \
-		-F "$FS" \
-		'($1 !~ /^#/ && $field == select) { print $7 }' \
+		-v cut="$3" \
+		'{sub(cut,"",$field)}
+		($1 !~ /^#/ && $field == select) { print $7 }' \
 		boards.cfg
 }
+
 boards_by_arch() { boards_by_field 2 "$@" ; }
-boards_by_cpu()  { boards_by_field 3 "$@" "[: \t]+" ; }
+boards_by_cpu()  { boards_by_field 3 "$@" ":.*" ; }
 boards_by_soc()  { boards_by_field 4 "$@" ; }
 
 #########################################################################