[U-Boot] [PATCH 1/3] common: Add symbol handling for generic lists into Makefile

Joe Hershberger joe.hershberger at gmail.com
Mon Sep 24 17:36:13 CEST 2012


Hi Marek,

On Sun, Sep 23, 2012 at 8:21 PM, Marek Vasut <marex at denx.de> wrote:
> This patch adds essential components for generation of the contents of
> the linker section that is used by the linker-generated array. All of
> the contents is held in a separate file, u-boot.lst, which is generated
> at runtime just before U-Boot is linked.
>
> The purpose of this code is to especially generate the appropriate
> boundary symbols around each subsection in the section carrying the
> linker-generated arrays. Obviously, the interim linker code for actual
> placement of the variables into the section is generated too. The
> generated file, u-boot.lst, is included into u-boot.lds via the linker
> INCLUDE directive in u-boot.lds .
>
> Adjustments are made in the Makefile and spl/Makefile so that the
> u-boot.lds and u-boot-spl.lds depend on their respective .lst files.
>
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Joe Hershberger <joe.hershberger at gmail.com>
> Cc: Mike Frysinger <vapier at gentoo.org>
> ---
>  Makefile     |   21 ++++++++++++++++++---
>  spl/Makefile |   14 +++++++++++++-
>  2 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index e3a27c6..592987a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -510,7 +510,10 @@ else
>  GEN_UBOOT = \
>                 UNDEF_SYM=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
>                 sed  -n -e 's/.*\($(SYM_PREFIX)__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
> -               cd $(LNDIR) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $$UNDEF_SYM $(__OBJS) \
> +               UNDEF_LST=`$(OBJDUMP) -x $(LIBBOARD) $(LIBS) | \
> +               sed  -n -e 's/.*\($(SYM_PREFIX)__u_boot_list_.*\)/-u\1/p'|sort|uniq`;\
> +               cd $(LNDIR) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
> +                       $$UNDEF_SYM $$UNDEF_LST $(__OBJS) \
>                         --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
>                         -Map u-boot.map -o u-boot
>  endif
> @@ -543,8 +546,20 @@ $(SUBDIR_EXAMPLES): $(obj)u-boot
>  $(LDSCRIPT):   depend
>                 $(MAKE) -C $(dir $@) $(notdir $@)
>
> -$(obj)u-boot.lds: $(LDSCRIPT)
> -               $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
> +$(obj)u-boot.lst: $(LIBBOARD) $(LIBS)
> +       $(OBJDUMP) -h $(LIBBOARD) $(LIBS) | \
> +       sed -n -e 's/.*\(\.u_boot_list[^ ]\+\).*$$/\1/p' | \
> +       sed 's/\.[^\.]\+$$//' | \
> +       sed -n ':s /^.\+$$/ { p;s/^\(.*\)\.[^\.]*$$/\1/;b s }' | \
> +       sed -n 's/\./.#/g;h;s/$$/\a/p;g;s/$$/@/p;g;s/$$/~/p;' | \
> +       LC_COLLATE=C sort -u | \
> +       sed 's/#//g' | \
> +       sed -n -e '/\a$$/ { s/\./_/g;s/\a$$/__start = .;/p; }'\
> +               -e '/~$$/ { s/\./_/g;s/~$$/__end = .;/p; }'\
> +               -e '/@$$/ { s/\(.*\)@$$/*(SORT(\1.*));/p }' >$@

It might be nice to litter this with comments indicating what you're
accomplishing at each step.

> +
> +$(obj)u-boot.lds: $(LDSCRIPT) $(obj)u-boot.lst
> +               $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$< >$@
>
>  nand_spl:      $(TIMESTAMP_FILE) $(VERSION_FILE) depend
>                 $(MAKE) -C nand_spl/board/$(BOARDDIR) all
> diff --git a/spl/Makefile b/spl/Makefile
> index d4cb668..545adfe 100644
> --- a/spl/Makefile
> +++ b/spl/Makefile
> @@ -148,7 +148,19 @@ $(START):  depend
>  $(LIBS):       depend
>         $(MAKE) -C $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))
>
> -$(obj)u-boot-spl.lds: $(LDSCRIPT) depend
> +$(obj)u-boot-spl.lst: $(LIBS)
> +       $(OBJDUMP) -h $(LIBS) | \
> +       sed -n -e 's/.*\(\.u_boot_list[^ ]\+\).*$$/\1/p' | \
> +       sed 's/\.[^\.]\+$$//' | \
> +       sed -n ':s /^.\+$$/ { p;s/^\(.*\)\.[^\.]*$$/\1/;b s }' | \
> +       sed -n 's/\./.#/g;h;s/$$/\a/p;g;s/$$/@/p;g;s/$$/~/p;' | \
> +       LC_COLLATE=C sort -u | \
> +       sed 's/#//g' | \
> +       sed -n -e '/\a$$/ { s/\./_/g;s/\a$$/__start = .;/p; }'\
> +               -e '/~$$/ { s/\./_/g;s/~$$/__end = .;/p; }'\
> +               -e '/@$$/ { s/\(.*\)@$$/*(SORT(\1.*));/p }' >$@

Could you not reuse this complicated logic by defining a make function
and then call + eval it?  Something like this:

define list_rule_template
$(1) : $(2)
        $(OBJDUMP) -h $^ | \
        sed -n -e 's/.*\(\.u_boot_list[^ ]\+\).*$$/\1/p' | \
        sed 's/\.[^\.]\+$$//' | \
        sed -n ':s /^.\+$$/ { p;s/^\(.*\)\.[^\.]*$$/\1/;b s }' | \
        sed -n 's/\./.#/g;h;s/$$/\a/p;g;s/$$/@/p;g;s/$$/~/p;' | \
        LC_COLLATE=C sort -u | \
        sed 's/#//g' | \
        sed -n -e '/\a$$/ { s/\./_/g;s/\a$$/__start = .;/p; }'\
                -e '/~$$/ { s/\./_/g;s/~$$/__end = .;/p; }'\
                -e '/@$$/ { s/\(.*\)@$$/*(SORT(\1.*));/p }' >$@
endef
...
$(eval $(call list_rule_template,$(obj)u-boot.lst,$(LIBBOARD) $(LIBS)))
...
$(eval $(call list_rule_template,$(obj)u-boot-spl.lst,$(LIBS)))

> +
> +$(obj)u-boot-spl.lds: $(LDSCRIPT) $(obj)u-boot-spl.lst depend
>         $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - < $< > $@

-Joe


More information about the U-Boot mailing list