Patchwork [v6,6/7] arch: toolchain: Install blackfin FDPIC and FLAT libraries in external toolchain makefile.

login
register
mail settings
Submitter Sonic Zhang
Date April 18, 2013, 10:06 a.m.
Message ID <1366279592-9055-6-git-send-email-sonic.adi@gmail.com>
Download mbox | patch
Permalink /patch/237593/
State Superseded
Headers show

Comments

Sonic Zhang - April 18, 2013, 10:06 a.m.
From: Sonic Zhang <sonic.zhang@analog.com>

Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
Install FDPIC and FLAT library in target ext-toolchain-installed.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>

---

v6-changes:
- Move options of installing blackfin toolchain libraries into external
toolchain Config.in.
- Fix typo error.
- Merge the options of the same name and add descriptions.

v5-changes:
- Update comments.

v3-changes:
- Remove arch specific makefiles.
- Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
- Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
- Move FDPIC and FLAT library installation target from blackfin makefile to
the ext-toolchain-installed target in external toolchain makefile.

v2-changes:
- Remove useless Macro __uClinux__

v1-changes:
- Create arch makefile.
- Create blackfin makefile.
- Add FDPIC and FLAT library options and makefile targets to install
libraries for different binary formats into the same rootfs image.
- update the TARGET_EXCEPTIONS variable in support/scripts/graph-depends for
new custom targets
---
 toolchain/toolchain-external/Config.in   |   25 ++++++++++++++++
 toolchain/toolchain-external/ext-tool.mk |   46 ++++++++++++++++++++++-------
 2 files changed, 60 insertions(+), 11 deletions(-)
Sonic Zhang - April 26, 2013, 3:21 a.m.
Hi Thomas,

On Thu, Apr 18, 2013 at 6:06 PM, Sonic Zhang <sonic.adi@gmail.com> wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
>
> Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
> Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
> Install FDPIC and FLAT library in target ext-toolchain-installed.
>
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
>
> ---
>
> v6-changes:
> - Move options of installing blackfin toolchain libraries into external
> toolchain Config.in.
> - Fix typo error.
> - Merge the options of the same name and add descriptions.
>
> v5-changes:
> - Update comments.
>
> v3-changes:
> - Remove arch specific makefiles.
> - Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
> - Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
> - Move FDPIC and FLAT library installation target from blackfin makefile to
> the ext-toolchain-installed target in external toolchain makefile.
>
> v2-changes:
> - Remove useless Macro __uClinux__
>
> v1-changes:
> - Create arch makefile.
> - Create blackfin makefile.
> - Add FDPIC and FLAT library options and makefile targets to install
> libraries for different binary formats into the same rootfs image.
> - update the TARGET_EXCEPTIONS variable in support/scripts/graph-depends for
> new custom targets
> ---
>  toolchain/toolchain-external/Config.in   |   25 ++++++++++++++++
>  toolchain/toolchain-external/ext-tool.mk |   46 ++++++++++++++++++++++-------
>  2 files changed, 60 insertions(+), 11 deletions(-)
>
> diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
> index 6cf29aa..c4d17e0 100644
> --- a/toolchain/toolchain-external/Config.in
> +++ b/toolchain/toolchain-external/Config.in
> @@ -887,5 +887,30 @@ config BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS
>
>  endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM
>
> +# When the FDPIC shared binary format is used, the corresponding libraries are
> +# always installed. When a different binary format is used, we offer the option
> +# of installing the FDPIC shared libraries.
> +config BR2_BFIN_INSTALL_FDPIC_SHARED
> +       bool "Install FDPIC shared libraries"
> +       depends on BR2_bfin && !BR2_BINFMT_FDPIC
> +       help
> +         The Linux kernel supports running both FDPIC and FLAT applications
> +         concurrently if the binary format specific libraries are installed properly.
> +         This option allows developer to install FDPIC libraries into a buildroot
> +         rootfs image built with binary format that is not FDPIC.
> +
> +# When the FLAT shared binary format is used, we force the installation
> +# of the corresponding libraries. When a different binary format is
> +# used, we offer the option of installing the FLAT shared libraries.
> +config BR2_BFIN_INSTALL_FLAT_SHARED
> +       bool "Install FLAT shared libraries"
> +       depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
> +       default y if BR2_BINFMT_FLAT_SHARED
> +       help
> +         The Linux kernel supports running both FDPIC and FLAT applications
> +         concurrently if the binary format specific libraries are installed properly.
> +         This option allows developer to install FLAT libraries into a buildroot
> +         rootfs image built with binary format that is not shared FLAT.
> +
>  endif # BR2_TOOLCHAIN_EXTERNAL
>
> diff --git a/toolchain/toolchain-external/ext-tool.mk b/toolchain/toolchain-external/ext-tool.mk
> index 57ea266..dbada0e 100644
> --- a/toolchain/toolchain-external/ext-tool.mk
> +++ b/toolchain/toolchain-external/ext-tool.mk
> @@ -115,8 +115,12 @@ ifeq ($(TOOLCHAIN_EXTERNAL_DIR),)
>  # if no path set, figure it out from path
>  TOOLCHAIN_EXTERNAL_BIN:=$(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
>  else
> +ifeq ($(BR2_bfin),y)
> +TOOLCHAIN_EXTERNAL_BIN:=$(TOOLCHAIN_EXTERNAL_DIR)/$(TOOLCHAIN_EXTERNAL_PREFIX)/bin
> +else
>  TOOLCHAIN_EXTERNAL_BIN:=$(TOOLCHAIN_EXTERNAL_DIR)/bin
>  endif
> +endif
>
>  TOOLCHAIN_EXTERNAL_CROSS=$(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
>  TOOLCHAIN_EXTERNAL_CC=$(TOOLCHAIN_EXTERNAL_CROSS)gcc
> @@ -312,17 +316,6 @@ $(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_1) $
>                 $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
>         $(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE_2))) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_2) | \
>                 $(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
> -ifeq ($(TOOLCHAIN_EXTERNAL_PREFIX),bfin-uclinux)
> -       rm -rf $(TOOLCHAIN_EXTERNAL_DIR)/bfin-linux-uclibc
> -       mv $(TOOLCHAIN_EXTERNAL_DIR)/bfin-uclinux $(TOOLCHAIN_EXTERNAL_DIR)/tmp
> -       mv $(TOOLCHAIN_EXTERNAL_DIR)/tmp/* $(TOOLCHAIN_EXTERNAL_DIR)/
> -       rmdir $(TOOLCHAIN_EXTERNAL_DIR)/tmp
> -else
> -       rm -rf $(TOOLCHAIN_EXTERNAL_DIR)/bfin-uclinux
> -       mv $(TOOLCHAIN_EXTERNAL_DIR)/bfin-linux-uclibc $(TOOLCHAIN_EXTERNAL_DIR)/tmp
> -       mv $(TOOLCHAIN_EXTERNAL_DIR)/tmp/* $(TOOLCHAIN_EXTERNAL_DIR)/
> -       rmdir $(TOOLCHAIN_EXTERNAL_DIR)/tmp
> -endif
>         $(Q)touch $@
>  else
>  # Download and extraction of a toolchain
> @@ -417,6 +410,37 @@ $(STAMP_DIR)/ext-toolchain-installed: $(STAMP_DIR)/ext-toolchain-checked
>                 @echo "External toolchain doesn't support --sysroot. Cannot use." ; \
>                 exit 1 ; \
>         fi ; \
> +       if test x"$(BR2_BFIN_INSTALL_FDPIC_SHARED)" == x"y" ; then \
> +               $(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \
> +               FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \
> +               FDPIC_LIBC_A_LOCATION=`readlink -f $$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
> +               FDPIC_SYSROOT_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(64)?/(.*/)?libc\.a::'` ; \
> +               FDPIC_LIB_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(64)?)/(.*/)?libc.a:\1:'` ; \
> +               FDPIC_SUPPORT_LIB_DIR="" ; \
> +               if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
> +                       FDPIC_LIBSTDCPP_A_LOCATION=$$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
> +                       if [ -e "$${FDPIC_LIBSTDCPP_A_LOCATION}" ]; then \
> +                               FDPIC_SUPPORT_LIB_DIR=`readlink -f $${FDPIC_LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
> +                       fi ; \
> +               fi ; \
> +               for libs in $(LIB_EXTERNAL_LIBS); do \
> +                       $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/lib); \
> +               done ; \
> +               for libs in $(USR_LIB_EXTERNAL_LIBS); do \
> +                       $(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/usr/lib); \
> +               done ; \
> +       fi ; \
> +       if test x"$(BR2_BFIN_INSTALL_FLAT_SHARED)" == x"y" ; then \
> +               $(call MESSAGE,"Install external toolchain FLAT libraries to target...") ; \
> +               FLAT_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))../../bfin-uclinux/bin/bfin-uclinux-gcc ; \
> +               FLAT_LIBC_A_LOCATION=`$${FLAT_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -mid-shared-library -print-file-name=libc`; \
> +               if [ -f $${FLAT_LIBC_A_LOCATION} -a ! -h $${FLAT_LIBC_A_LOCATION} ] ; then \
> +# The flat libraries are found and linked according to the index in \
> +# name "libN.so". Index 1 is reserved for the standard C library. \
> +# Customer libraries can use 4 and above. \
> +                       $(INSTALL) -D $${FLAT_LIBC_A_LOCATION} $(TARGET_DIR)/lib/lib1.so; \
> +               fi ; \
> +       fi ; \
>         ARCH_LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
>         ARCH_SYSROOT_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(64)?/(.*/)?libc\.a::'` ; \
>         ARCH_LIB_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(64)?)/(.*/)?libc.a:\1:'` ; \
> --
> 1.7.0.4
>
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

May I have you Acked-by against this patch?

Thanks

Sonic Zhang
Sonic Zhang - May 2, 2013, 7:36 a.m.
Hi Thomas,

On Thu, Apr 18, 2013 at 6:06 PM, Sonic Zhang <sonic.adi@gmail.com> wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
>
> Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
> Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
> Install FDPIC and FLAT library in target ext-toolchain-installed.
>
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
>
> ---
>
> v6-changes:
> - Move options of installing blackfin toolchain libraries into external
> toolchain Config.in.
> - Fix typo error.
> - Merge the options of the same name and add descriptions.
>
> v5-changes:
> - Update comments.
>
> v3-changes:
> - Remove arch specific makefiles.
> - Reserve all 3 blackfin toolchain folders under the TOOLCHAIN_EXTERNAL_DIR.
> - Set current blackfin toolchain bin folder to the toolchain prefix subfolder.
> - Move FDPIC and FLAT library installation target from blackfin makefile to
> the ext-toolchain-installed target in external toolchain makefile.
>
> v2-changes:
> - Remove useless Macro __uClinux__
>
> v1-changes:
> - Create arch makefile.
> - Create blackfin makefile.
> - Add FDPIC and FLAT library options and makefile targets to install
> libraries for different binary formats into the same rootfs image.
> - update the TARGET_EXCEPTIONS variable in support/scripts/graph-depends for
> new custom targets
> ---
>  toolchain/toolchain-external/Config.in   |   25 ++++++++++++++++
>  toolchain/toolchain-external/ext-tool.mk |   46 ++++++++++++++++++++++-------
>  2 files changed, 60 insertions(+), 11 deletions(-)
>
> diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
> index 6cf29aa..c4d17e0 100644
> --- a/toolchain/toolchain-external/Config.in
> +++ b/toolchain/toolchain-external/Config.in
> @@ -887,5 +887,30 @@ config BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS
>
>  endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM
>
> +# When the FDPIC shared binary format is used, the corresponding libraries are
> +# always installed. When a different binary format is used, we offer the option
> +# of installing the FDPIC shared libraries.
> +config BR2_BFIN_INSTALL_FDPIC_SHARED
> +       bool "Install FDPIC shared libraries"
> +       depends on BR2_bfin && !BR2_BINFMT_FDPIC
> +       help
> +         The Linux kernel supports running both FDPIC and FLAT applications
> +         concurrently if the binary format specific libraries are installed properly.
> +         This option allows developer to install FDPIC libraries into a buildroot
> +         rootfs image built with binary format that is not FDPIC.
> +
> +# When the FLAT shared binary format is used, we force the installation
> +# of the corresponding libraries. When a different binary format is
> +# used, we offer the option of installing the FLAT shared libraries.
> +config BR2_BFIN_INSTALL_FLAT_SHARED
> +       bool "Install FLAT shared libraries"
> +       depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
> +       default y if BR2_BINFMT_FLAT_SHARED
> +       help
> +         The Linux kernel supports running both FDPIC and FLAT applications
> +         concurrently if the binary format specific libraries are installed properly.
> +         This option allows developer to install FLAT libraries into a buildroot
> +         rootfs image built with binary format that is not shared FLAT.
> +

Your former suggestion to merge 2 options

---------------------------------
config BR2_BFIN_INSTALL_FLAT_SHARED
       default y if BR2_BINFMT_FLAT_SHARED

config BR2_BFIN_INSTALL_FLAT_SHARED
       bool "Install FLAT shared libraries"
       depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
---------------------------------
into one
---------------------------------
config BR2_BFIN_INSTALL_FLAT_SHARED
       bool "Install FLAT shared libraries"
       depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
       default y if BR2_BINFMT_FLAT_SHARED
---------------------------------

doesn't work. In the later case, if BR2_BINFMT_FLAT_SHARED is
selected, option BR2_BFIN_INSTALL_FLAT_SHARED is not set to y by
default. Only the former case works correctly.

So, I have to revert the options back.

Regards,

Sonic Zhang
Thomas Petazzoni - May 2, 2013, 10:01 a.m.
Dear Sonic Zhang,

On Thu, 2 May 2013 15:36:11 +0800, Sonic Zhang wrote:

> ---------------------------------
> config BR2_BFIN_INSTALL_FLAT_SHARED
>        bool "Install FLAT shared libraries"
>        depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
>        default y if BR2_BINFMT_FLAT_SHARED
> ---------------------------------
> 
> doesn't work. In the later case, if BR2_BINFMT_FLAT_SHARED is
> selected, option BR2_BFIN_INSTALL_FLAT_SHARED is not set to y by
> default. Only the former case works correctly.

Wasn't my suggestion:

config BR2_BFIN_INSTALL_FLAT_SHARED
        bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
        depends on BR2_bfin
        default y if BR2_BINFMT_FLAT_SHARED

So: option enabled by default when BR2_BINFMT_FLAT_SHARED, and the
prompt is shown to optionally enable/disable it when
BR2_BINFMT_FLAT_SHARED is not selected.

Thomas
Sonic Zhang - May 2, 2013, 10:11 a.m.
Hi Thomas,

On Thu, May 2, 2013 at 6:01 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> On Thu, 2 May 2013 15:36:11 +0800, Sonic Zhang wrote:
>
>> ---------------------------------
>> config BR2_BFIN_INSTALL_FLAT_SHARED
>>        bool "Install FLAT shared libraries"
>>        depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
>>        default y if BR2_BINFMT_FLAT_SHARED
>> ---------------------------------
>>
>> doesn't work. In the later case, if BR2_BINFMT_FLAT_SHARED is
>> selected, option BR2_BFIN_INSTALL_FLAT_SHARED is not set to y by
>> default. Only the former case works correctly.
>
> Wasn't my suggestion:
>
> config BR2_BFIN_INSTALL_FLAT_SHARED
>         bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
>         depends on BR2_bfin
>         default y if BR2_BINFMT_FLAT_SHARED
>
> So: option enabled by default when BR2_BINFMT_FLAT_SHARED, and the
> prompt is shown to optionally enable/disable it when
> BR2_BINFMT_FLAT_SHARED is not selected.

In this way, the developer can disable the option
BR2_BFIN_INSTALL_FLAT_SHARED in share flat binary mode. This is
incorrect. My solution ensures the developer have no way to disable
BR2_BFIN_INSTALL_FLAT_SHARED when BR2_BINFMT_FLAT_SHARED is selected.

Regards,

Sonic
Thomas Petazzoni - May 3, 2013, 6:46 p.m.
Dear Sonic Zhang,

On Thu, 2 May 2013 18:11:40 +0800, Sonic Zhang wrote:

> > Wasn't my suggestion:
> >
> > config BR2_BFIN_INSTALL_FLAT_SHARED
> >         bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
> >         depends on BR2_bfin
> >         default y if BR2_BINFMT_FLAT_SHARED
> >
> > So: option enabled by default when BR2_BINFMT_FLAT_SHARED, and the
> > prompt is shown to optionally enable/disable it when
> > BR2_BINFMT_FLAT_SHARED is not selected.
> 
> In this way, the developer can disable the option
> BR2_BFIN_INSTALL_FLAT_SHARED in share flat binary mode. This is
> incorrect. My solution ensures the developer have no way to disable
> BR2_BFIN_INSTALL_FLAT_SHARED when BR2_BINFMT_FLAT_SHARED is selected.

This is what my proposed code is doing. I've just tested it on a small
example:

config BR2_OPTIONA
	bool "optionA"

config BR2_OPTIONB
	bool "optionB" if !BR2_OPTIONA
	default y if BR2_OPTIONA

With the following results:

 * If the user selects option A, then the possibility of choosing the
   value for option B disappears, and option B is forcefully enabled.

 * If the user doesn't select option A, then he is free to select or
   not select option B.

Thanks,

Thomas
Sonic Zhang - May 6, 2013, 6:36 a.m.
Hi Thomas,

On Sat, May 4, 2013 at 2:46 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> On Thu, 2 May 2013 18:11:40 +0800, Sonic Zhang wrote:
>
>> > Wasn't my suggestion:
>> >
>> > config BR2_BFIN_INSTALL_FLAT_SHARED
>> >         bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
>> >         depends on BR2_bfin
>> >         default y if BR2_BINFMT_FLAT_SHARED
>> >
>> > So: option enabled by default when BR2_BINFMT_FLAT_SHARED, and the
>> > prompt is shown to optionally enable/disable it when
>> > BR2_BINFMT_FLAT_SHARED is not selected.
>>
>> In this way, the developer can disable the option
>> BR2_BFIN_INSTALL_FLAT_SHARED in share flat binary mode. This is
>> incorrect. My solution ensures the developer have no way to disable
>> BR2_BFIN_INSTALL_FLAT_SHARED when BR2_BINFMT_FLAT_SHARED is selected.
>
> This is what my proposed code is doing. I've just tested it on a small
> example:
>
> config BR2_OPTIONA
>         bool "optionA"
>
> config BR2_OPTIONB
>         bool "optionB" if !BR2_OPTIONA
>         default y if BR2_OPTIONA
>
> With the following results:
>
>  * If the user selects option A, then the possibility of choosing the
>    value for option B disappears, and option B is forcefully enabled.
>
>  * If the user doesn't select option A, then he is free to select or
>    not select option B.
>

Thank you for your explanation. You are right, the if condition should
be after bool other than depend.

Regards,

Sonic

Patch

diff --git a/toolchain/toolchain-external/Config.in b/toolchain/toolchain-external/Config.in
index 6cf29aa..c4d17e0 100644
--- a/toolchain/toolchain-external/Config.in
+++ b/toolchain/toolchain-external/Config.in
@@ -887,5 +887,30 @@  config BR2_TOOLCHAIN_EXTRA_EXTERNAL_LIBS
 
 endif # BR2_TOOLCHAIN_EXTERNAL_CUSTOM
 
+# When the FDPIC shared binary format is used, the corresponding libraries are
+# always installed. When a different binary format is used, we offer the option
+# of installing the FDPIC shared libraries.
+config BR2_BFIN_INSTALL_FDPIC_SHARED
+	bool "Install FDPIC shared libraries"
+	depends on BR2_bfin && !BR2_BINFMT_FDPIC
+	help
+	  The Linux kernel supports running both FDPIC and FLAT applications
+	  concurrently if the binary format specific libraries are installed properly.
+	  This option allows developer to install FDPIC libraries into a buildroot
+	  rootfs image built with binary format that is not FDPIC.
+
+# When the FLAT shared binary format is used, we force the installation
+# of the corresponding libraries. When a different binary format is
+# used, we offer the option of installing the FLAT shared libraries.
+config BR2_BFIN_INSTALL_FLAT_SHARED
+	bool "Install FLAT shared libraries"
+	depends on BR2_bfin && !BR2_BINFMT_FLAT_SHARED
+	default y if BR2_BINFMT_FLAT_SHARED
+	help
+	  The Linux kernel supports running both FDPIC and FLAT applications
+	  concurrently if the binary format specific libraries are installed properly.
+	  This option allows developer to install FLAT libraries into a buildroot
+	  rootfs image built with binary format that is not shared FLAT.
+
 endif # BR2_TOOLCHAIN_EXTERNAL
 
diff --git a/toolchain/toolchain-external/ext-tool.mk b/toolchain/toolchain-external/ext-tool.mk
index 57ea266..dbada0e 100644
--- a/toolchain/toolchain-external/ext-tool.mk
+++ b/toolchain/toolchain-external/ext-tool.mk
@@ -115,8 +115,12 @@  ifeq ($(TOOLCHAIN_EXTERNAL_DIR),)
 # if no path set, figure it out from path
 TOOLCHAIN_EXTERNAL_BIN:=$(shell dirname $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
 else
+ifeq ($(BR2_bfin),y)
+TOOLCHAIN_EXTERNAL_BIN:=$(TOOLCHAIN_EXTERNAL_DIR)/$(TOOLCHAIN_EXTERNAL_PREFIX)/bin
+else
 TOOLCHAIN_EXTERNAL_BIN:=$(TOOLCHAIN_EXTERNAL_DIR)/bin
 endif
+endif
 
 TOOLCHAIN_EXTERNAL_CROSS=$(TOOLCHAIN_EXTERNAL_BIN)/$(TOOLCHAIN_EXTERNAL_PREFIX)-
 TOOLCHAIN_EXTERNAL_CC=$(TOOLCHAIN_EXTERNAL_CROSS)gcc
@@ -312,17 +316,6 @@  $(TOOLCHAIN_EXTERNAL_DIR)/.extracted: $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_1) $
 		$(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
 	$(INFLATE$(suffix $(TOOLCHAIN_EXTERNAL_SOURCE_2))) $(DL_DIR)/$(TOOLCHAIN_EXTERNAL_SOURCE_2) | \
 		$(TAR) $(TAR_STRIP_COMPONENTS)=3 --hard-dereference -C $(@D) $(TAR_OPTIONS) -
-ifeq ($(TOOLCHAIN_EXTERNAL_PREFIX),bfin-uclinux)
-	rm -rf $(TOOLCHAIN_EXTERNAL_DIR)/bfin-linux-uclibc
-	mv $(TOOLCHAIN_EXTERNAL_DIR)/bfin-uclinux $(TOOLCHAIN_EXTERNAL_DIR)/tmp
-	mv $(TOOLCHAIN_EXTERNAL_DIR)/tmp/* $(TOOLCHAIN_EXTERNAL_DIR)/
-	rmdir $(TOOLCHAIN_EXTERNAL_DIR)/tmp
-else
-	rm -rf $(TOOLCHAIN_EXTERNAL_DIR)/bfin-uclinux
-	mv $(TOOLCHAIN_EXTERNAL_DIR)/bfin-linux-uclibc $(TOOLCHAIN_EXTERNAL_DIR)/tmp
-	mv $(TOOLCHAIN_EXTERNAL_DIR)/tmp/* $(TOOLCHAIN_EXTERNAL_DIR)/
-	rmdir $(TOOLCHAIN_EXTERNAL_DIR)/tmp
-endif
 	$(Q)touch $@
 else
 # Download and extraction of a toolchain
@@ -417,6 +410,37 @@  $(STAMP_DIR)/ext-toolchain-installed: $(STAMP_DIR)/ext-toolchain-checked
 		@echo "External toolchain doesn't support --sysroot. Cannot use." ; \
 		exit 1 ; \
 	fi ; \
+	if test x"$(BR2_BFIN_INSTALL_FDPIC_SHARED)" == x"y" ; then \
+		$(call MESSAGE,"Install external toolchain FDPIC libraries to target...") ; \
+		FDPIC_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))/../../bfin-linux-uclibc/bin/bfin-linux-uclibc-gcc ; \
+		FDPIC_LIBC_A_LOCATION=`readlink -f $$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
+		FDPIC_SYSROOT_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(64)?/(.*/)?libc\.a::'` ; \
+		FDPIC_LIB_DIR=`echo $${FDPIC_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(64)?)/(.*/)?libc.a:\1:'` ; \
+		FDPIC_SUPPORT_LIB_DIR="" ; \
+		if test `find $${FDPIC_SYSROOT_DIR} -name 'libstdc++.a' | wc -l` -eq 0 ; then \
+			FDPIC_LIBSTDCPP_A_LOCATION=$$(LANG=C $${FDPIC_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libstdc++.a) ; \
+			if [ -e "$${FDPIC_LIBSTDCPP_A_LOCATION}" ]; then \
+				FDPIC_SUPPORT_LIB_DIR=`readlink -f $${FDPIC_LIBSTDCPP_A_LOCATION} | sed -r -e 's:libstdc\+\+\.a::'` ; \
+			fi ; \
+		fi ; \
+		for libs in $(LIB_EXTERNAL_LIBS); do \
+			$(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/lib); \
+		done ; \
+		for libs in $(USR_LIB_EXTERNAL_LIBS); do \
+			$(call copy_toolchain_lib_root,$${FDPIC_SYSROOT_DIR},$${FDPIC_SUPPORT_LIB_DIR},$${FDPIC_LIB_DIR},$$libs,/usr/lib); \
+		done ; \
+	fi ; \
+	if test x"$(BR2_BFIN_INSTALL_FLAT_SHARED)" == x"y" ; then \
+		$(call MESSAGE,"Install external toolchain FLAT libraries to target...") ; \
+		FLAT_EXTERNAL_CC=$(dir $(TOOLCHAIN_EXTERNAL_CC))../../bfin-uclinux/bin/bfin-uclinux-gcc ; \
+		FLAT_LIBC_A_LOCATION=`$${FLAT_EXTERNAL_CC} $(TOOLCHAIN_EXTERNAL_CFLAGS) -mid-shared-library -print-file-name=libc`; \
+		if [ -f $${FLAT_LIBC_A_LOCATION} -a ! -h $${FLAT_LIBC_A_LOCATION} ] ; then \
+# The flat libraries are found and linked according to the index in \
+# name "libN.so". Index 1 is reserved for the standard C library. \
+# Customer libraries can use 4 and above. \
+			$(INSTALL) -D $${FLAT_LIBC_A_LOCATION} $(TARGET_DIR)/lib/lib1.so; \
+		fi ; \
+	fi ; \
 	ARCH_LIBC_A_LOCATION=`readlink -f $$(LANG=C $(TOOLCHAIN_EXTERNAL_CC) $(TOOLCHAIN_EXTERNAL_CFLAGS) -print-file-name=libc.a)` ; \
 	ARCH_SYSROOT_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:usr/lib(64)?/(.*/)?libc\.a::'` ; \
 	ARCH_LIB_DIR=`echo $${ARCH_LIBC_A_LOCATION} | sed -r -e 's:.*/usr/(lib(64)?)/(.*/)?libc.a:\1:'` ; \