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

Submitted by Sonic Zhang on April 12, 2013, 10:18 a.m.

Details

Message ID 1365761909-15305-6-git-send-email-sonic.adi@gmail.com
State Changes Requested
Headers show

Commit Message

Sonic Zhang April 12, 2013, 10:18 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>

---

v5-change:
- 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
---
 arch/Config.in.bfin                      |   22 ++++++++++++++
 toolchain/toolchain-external/ext-tool.mk |   46 ++++++++++++++++++++++-------
 2 files changed, 57 insertions(+), 11 deletions(-)

Comments

Thomas Petazzoni April 16, 2013, 9:29 p.m.
Dear Sonic Zhang,

On Fri, 12 Apr 2013 18:18:28 +0800, Sonic Zhang wrote:
> diff --git a/arch/Config.in.bfin b/arch/Config.in.bfin
> index f755c8d..917282d 100644
> --- a/arch/Config.in.bfin
> +++ b/arch/Config.in.bfin
> @@ -62,6 +62,28 @@ config BR2_bf561
>  	bool "bf561"
>  endchoice
>  
> +config BR2_BFIN_INSTALL_FDPIC_SHARED
> +	bool "Install FDPIC shared libraries"
> +	depends on !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.
> +
> +config BR2_BFIN_INSTALL_FLAT_SHARED
> +	depends on BR2_BINFMT_FLAT_SHARED
> +	default y
> +
> +config BR2_BFIN_INSTALL_FLAT_SHARED
> +	bool "Install FLAT shared libraries"

Same name as the previous option.

> +	depends on !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.

I think those options should be preference of the external toolchain,
so in toolchain/toolchain-external/Config.in. Because if we ever
support internal toolchain for Blackfin, they won't be multilib
toolchains, so it won't make sense to have those options.

> +ifeq ($(BR2_bfin,y)

Do you actually test the patches you're posting?

> +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:'` ; \

This external toolchain installation starts to be complicated, and
should probably be split in sub-functions. But that can be done as a
followup improvement, you don't have to do it right now.

Thanks,

Thomas
Sonic Zhang April 17, 2013, 7:50 a.m.
Hi Thomas,

On Wed, Apr 17, 2013 at 5:29 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> On Fri, 12 Apr 2013 18:18:28 +0800, Sonic Zhang wrote:
>> diff --git a/arch/Config.in.bfin b/arch/Config.in.bfin
>> index f755c8d..917282d 100644
>> --- a/arch/Config.in.bfin
>> +++ b/arch/Config.in.bfin
>> @@ -62,6 +62,28 @@ config BR2_bf561
>>       bool "bf561"
>>  endchoice
>>
>> +config BR2_BFIN_INSTALL_FDPIC_SHARED
>> +     bool "Install FDPIC shared libraries"
>> +     depends on !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.
>> +
>> +config BR2_BFIN_INSTALL_FLAT_SHARED
>> +     depends on BR2_BINFMT_FLAT_SHARED
>> +     default y
>> +
>> +config BR2_BFIN_INSTALL_FLAT_SHARED
>> +     bool "Install FLAT shared libraries"
>
> Same name as the previous option.

This is intended. When option BINFMT_FLAT_SHARED is selected option
BR2_BFIN_INSTALL_FLAT_SHARED should always be set to y. While other
BINFMT is selected, BR2_BFIN_INSTALL_FLAT_SHARED is optional for
developer to decide.


>
>> +     depends on !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.
>
> I think those options should be preference of the external toolchain,
> so in toolchain/toolchain-external/Config.in. Because if we ever
> support internal toolchain for Blackfin, they won't be multilib
> toolchains, so it won't make sense to have those options.
>
>> +ifeq ($(BR2_bfin,y)
>
> Do you actually test the patches you're posting?

Yes, but when I prepare patches for upstream, I apply to a different
branch, and sometimes make typo error.

Regards,

Sonic
Thomas Petazzoni April 17, 2013, 8:05 a.m.
Dear Sonic Zhang,

On Wed, 17 Apr 2013 15:50:01 +0800, Sonic Zhang wrote:

> This is intended. When option BINFMT_FLAT_SHARED is selected option
> BR2_BFIN_INSTALL_FLAT_SHARED should always be set to y. While other
> BINFMT is selected, BR2_BFIN_INSTALL_FLAT_SHARED is optional for
> developer to decide.

Ok, I see, makes sense. But then, why don't we have the same for FDPIC?
Also, I think I'd prefer something like:

# When the FDPIC 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 FDPIC shared libraries
# (typically in addition to the FLAT shared ones).
config BR2_BFIN_INSTALL_FDPIC_SHARED
	bool "Install FDPIC shared libraries" if !BR2_BINFMT_FDPIC
	default y if BR2_BINFMT_FDPIC
	help
	  ...

# 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
# (typically in addition to the FDPIC ones).
config BR2_BFIN_INSTALL_FLAT_SHARED
	bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
	default y if BR2_BINFMT_FLAT_SHARED
	help
	  ...

Would this makes sense?

> >> +ifeq ($(BR2_bfin,y)
> >
> > Do you actually test the patches you're posting?
> 
> Yes, but when I prepare patches for upstream, I apply to a different
> branch, and sometimes make typo error.

Ok. But then at some point we'll want to apply your patches, so they
should be working :-) (Though I understand during the review process
you want to make quick iterations, that's fine, but ultimately, we'll
want working patches).

Thanks!

Thomas
Sonic Zhang April 17, 2013, 8:16 a.m.
Hi Thomas,

On Wed, Apr 17, 2013 at 4:05 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> On Wed, 17 Apr 2013 15:50:01 +0800, Sonic Zhang wrote:
>
>> This is intended. When option BINFMT_FLAT_SHARED is selected option
>> BR2_BFIN_INSTALL_FLAT_SHARED should always be set to y. While other
>> BINFMT is selected, BR2_BFIN_INSTALL_FLAT_SHARED is optional for
>> developer to decide.
>
> Ok, I see, makes sense. But then, why don't we have the same for FDPIC?
> Also, I think I'd prefer something like:
>
> # When the FDPIC 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 FDPIC shared libraries
> # (typically in addition to the FLAT shared ones).
> config BR2_BFIN_INSTALL_FDPIC_SHARED
>         bool "Install FDPIC shared libraries" if !BR2_BINFMT_FDPIC
>         default y if BR2_BINFMT_FDPIC
>         help
>           ...

Because current library installation scripts in
toolchain-external/ext-tool.mk always install FDPIC libraries when
BINFMT_FDPIC is selected. No necessary to set
BR2_BFIN_INSTALL_FDPIC_SHARED y in this case.

>
> # 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
> # (typically in addition to the FDPIC ones).
> config BR2_BFIN_INSTALL_FLAT_SHARED
>         bool "Install FLAT shared libraries" if !BR2_BINFMT_FLAT_SHARED
>         default y if BR2_BINFMT_FLAT_SHARED
>         help
>           ...
>
> Would this makes sense?
>

Looks better.

>> >> +ifeq ($(BR2_bfin,y)
>> >
>> > Do you actually test the patches you're posting?
>>
>> Yes, but when I prepare patches for upstream, I apply to a different
>> branch, and sometimes make typo error.
>
> Ok. But then at some point we'll want to apply your patches, so they
> should be working :-) (Though I understand during the review process
> you want to make quick iterations, that's fine, but ultimately, we'll
> want working patches).
>
> Thanks!
>
> Thomas
> --
> Thomas Petazzoni, Free Electrons
> Kernel, drivers, real-time and embedded Linux
> development, consulting, training and support.
> http://free-electrons.com
Thomas Petazzoni April 17, 2013, 8:56 a.m.
Dear Sonic Zhang,

On Wed, 17 Apr 2013 16:16:21 +0800, Sonic Zhang wrote:

> > # When the FDPIC 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 FDPIC shared libraries
> > # (typically in addition to the FLAT shared ones).
> > config BR2_BFIN_INSTALL_FDPIC_SHARED
> >         bool "Install FDPIC shared libraries" if !BR2_BINFMT_FDPIC
> >         default y if BR2_BINFMT_FDPIC
> >         help
> >           ...
> 
> Because current library installation scripts in
> toolchain-external/ext-tool.mk always install FDPIC libraries when
> BINFMT_FDPIC is selected. No necessary to set
> BR2_BFIN_INSTALL_FDPIC_SHARED y in this case.

Ok. But then why do we have to duplicate this code in ext-tool.mk. If
it already has the code to copy the FDPIC libraries when FDPIC is
selected as the primary binary format, we should be able to re-use this
code when FLAT shared is used as the primary binary format, but we want
the FDPIC libraries to be installed in addition.

Thanks,

Thomas
Sonic Zhang April 17, 2013, 9:40 a.m.
Hi Thomas,


On Wed, Apr 17, 2013 at 4:56 PM, Thomas Petazzoni <
thomas.petazzoni@free-electrons.com> wrote:

> Dear Sonic Zhang,
>
> On Wed, 17 Apr 2013 16:16:21 +0800, Sonic Zhang wrote:
>
> > > # When the FDPIC 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 FDPIC shared libraries
> > > # (typically in addition to the FLAT shared ones).
> > > config BR2_BFIN_INSTALL_FDPIC_SHARED
> > >         bool "Install FDPIC shared libraries" if !BR2_BINFMT_FDPIC
> > >         default y if BR2_BINFMT_FDPIC
> > >         help
> > >           ...
> >
> > Because current library installation scripts in
> > toolchain-external/ext-tool.mk always install FDPIC libraries when
> > BINFMT_FDPIC is selected. No necessary to set
> > BR2_BFIN_INSTALL_FDPIC_SHARED y in this case.
>
> Ok. But then why do we have to duplicate this code in ext-tool.mk. If
> it already has the code to copy the FDPIC libraries when FDPIC is
> selected as the primary binary format, we should be able to re-use this
> code when FLAT shared is used as the primary binary format, but we want
> the FDPIC libraries to be installed in addition.
>

Yes, I do reuse the function copy_toolchain_lib_root() in the code to
install shared FDPIC libraries when FLAT format is selected. But, rest part
of the library installation code depends on current TOOLCHAIN_EXTERNAL_CC,
which is different from the FDPIC one in this case. And the following
sysroot to staging installation code depends on macro SYSROOT_DIR,
ARCH_SYSROOT_DIR, ARCH_SUBDIR, ARCH_LIB_DIR and SUPPORT_LIB_DIR, which are
based on current TOOLCHAIN_EXTERNAL_CC as well.

I feel the individual FDPIC installation code for FLAT format is a simple
and clear solution.

Regards,

Sonic
Arnout Vandecappelle April 17, 2013, 4:41 p.m.
On 17/04/13 11:40, Sonic Zhang wrote:
> Hi Thomas,
>
>
> On Wed, Apr 17, 2013 at 4:56 PM, Thomas Petazzoni
> <thomas.petazzoni@free-electrons.com
> <mailto:thomas.petazzoni@free-electrons.com>> wrote:
>
>     Dear Sonic Zhang,
>
>     On Wed, 17 Apr 2013 16:16:21 +0800, Sonic Zhang wrote:
>
>      > > # When the FDPIC 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 FDPIC shared libraries
>      > > # (typically in addition to the FLAT shared ones).
>      > > config BR2_BFIN_INSTALL_FDPIC_SHARED
>      > >         bool "Install FDPIC shared libraries" if !BR2_BINFMT_FDPIC
>      > >         default y if BR2_BINFMT_FDPIC
>      > >         help
>      > >           ...
>      >
>      > Because current library installation scripts in
>      > toolchain-external/ext-tool.mk <http://ext-tool.mk> always install
>     FDPIC libraries when
>      > BINFMT_FDPIC is selected. No necessary to set
>      > BR2_BFIN_INSTALL_FDPIC_SHARED y in this case.
>
>     Ok. But then why do we have to duplicate this code in ext-tool.mk
>     <http://ext-tool.mk>. If
>     it already has the code to copy the FDPIC libraries when FDPIC is
>     selected as the primary binary format, we should be able to re-use this
>     code when FLAT shared is used as the primary binary format, but we want
>     the FDPIC libraries to be installed in addition.
>
>
> Yes, I do reuse the function copy_toolchain_lib_root() in the code to
> install shared FDPIC libraries when FLAT format is selected. But, rest
> part of the library installation code depends on current
> TOOLCHAIN_EXTERNAL_CC, which is different from the FDPIC one in this
> case. And the following sysroot to staging installation code depends on
> macro SYSROOT_DIR, ARCH_SYSROOT_DIR, ARCH_SUBDIR, ARCH_LIB_DIR and
> SUPPORT_LIB_DIR, which are based on current TOOLCHAIN_EXTERNAL_CC as well.
>
> I feel the individual FDPIC installation code for FLAT format is a simple
> and clear solution.

  And anyway it can be refactored away later (e.g. when moving the 
ext-toolchain stuff to a script or to functions).


  Regards,
  Arnout
Thomas Petazzoni April 18, 2013, 7:25 a.m.
Dear Arnout Vandecappelle,

On Wed, 17 Apr 2013 18:41:02 +0200, Arnout Vandecappelle wrote:

> > Yes, I do reuse the function copy_toolchain_lib_root() in the code to
> > install shared FDPIC libraries when FLAT format is selected. But, rest
> > part of the library installation code depends on current
> > TOOLCHAIN_EXTERNAL_CC, which is different from the FDPIC one in this
> > case. And the following sysroot to staging installation code depends on
> > macro SYSROOT_DIR, ARCH_SYSROOT_DIR, ARCH_SUBDIR, ARCH_LIB_DIR and
> > SUPPORT_LIB_DIR, which are based on current TOOLCHAIN_EXTERNAL_CC as well.
> >
> > I feel the individual FDPIC installation code for FLAT format is a simple
> > and clear solution.
> 
>   And anyway it can be refactored away later (e.g. when moving the 
> ext-toolchain stuff to a script or to functions).

Yes, I agree. Let's keep Sonic code as is for now, and as we get a
better understanding of the potential similarities with the existing
code, we can refactor if it makes sense.

Thomas

Patch hide | download patch | download mbox

diff --git a/arch/Config.in.bfin b/arch/Config.in.bfin
index f755c8d..917282d 100644
--- a/arch/Config.in.bfin
+++ b/arch/Config.in.bfin
@@ -62,6 +62,28 @@  config BR2_bf561
 	bool "bf561"
 endchoice
 
+config BR2_BFIN_INSTALL_FDPIC_SHARED
+	bool "Install FDPIC shared libraries"
+	depends on !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.
+
+config BR2_BFIN_INSTALL_FLAT_SHARED
+	depends on BR2_BINFMT_FLAT_SHARED
+	default y
+
+config BR2_BFIN_INSTALL_FLAT_SHARED
+	bool "Install FLAT shared libraries"
+	depends on !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.
+
 config BR2_ARCH
 	default "bfin"
 
diff --git a/toolchain/toolchain-external/ext-tool.mk b/toolchain/toolchain-external/ext-tool.mk
index 27fd296..23824ab 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:'` ; \