All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Peter Saunderson <peteasa@gmail.com>
Cc: yocto@yoctoproject.org
Subject: Re: Cross compiler which runs on the target architecture.
Date: Tue, 23 Dec 2014 09:08:45 +0000	[thread overview]
Message-ID: <1419325725.1777.7.camel@linuxfoundation.org> (raw)
In-Reply-To: <54958B25.8080505@gmail.com>

On Sat, 2014-12-20 at 14:43 +0000, Peter Saunderson wrote:
> I have seen a brief IRC chat 
> (https://www.yoctoproject.org/irc/%23yocto.2013-09-23.log.html talking 
> about https://github.com/nathanrossi/meta-parallella) about this 
> question but nothing much else so this is an attempt to get more public 
> feedback on this request.
> 
> I am trying to build a cross compiler that runs on the target processor 
> and a cross compiler that runs on the host processor so that I can build 
> code for a third processor (Epiphany).  If you want examples of the 
> traditional way to build this compiler look at 
> https://github.com/adapteva/epiphany-sdk epiphany-gcc epiphany-newlib 
> epiphany-binutils... The end result would be a set of recipes that run 
> on a pc build machine that build both arm code for the interim target 
> and epiphany code for the final target and provides an SDK for the pc 
> that enables you to cross compile for both arm and epiphany.
> 
> As I am just starting to look at this I would like to know what size of 
> task I am up against!  My initial efforts based on review of 
> poky/meta/recipes-devtools/binutils etc seem to suggest that I have to 
> modify at least ${HOST_PREFIX}, ${TARGET_PREFIX}, ${TARGET_ARCH} etc for 
> my epiphany-??? recipes so that the I can install the compiler in a 
> suitable location with a suitable prefix, the IRC chat indicates that 
> there are more things to consider also.
> 
> The question I have is about how easy it will be to use existing recipes 
> for existing compiler / binutils etc... or is this likely to end up as a 
> completely new set of recipes from the ground up because the existing 
> recipes cant cope with building cross / cross compilers where there are 
> three processors to consider (host (intel based pc), interim target 
> (arm) and final target (epiphany)), or at least a lot of changes in the 
> existing recipes to cope with something like TARGET_TARGET_ARCH = 
> ${TARGET_ARCH}_${FINAL_TARGET_ARCH}??

As mentioned, I had need to do something like this for an avr target.
I've created some *extremely* hacky recipes which do this and the
resulting toolchain does actually work, much to my surprise. I've
included the recipes I created below, warts and all in case it helps.

Basically, its all a bit of a hack, the trouble is the system is very
much tuned to have TARGET pointed at HOST for standard recipes. In the
end I found it easier to 'sed' in the right target values into configure
and then 'sed' other variables to change TARGET_PREFIX/TARGET_SYS where
needed.

Ultimately if we were doing a lot of this, we may be able to use a
different variable name to make the recipes a lot neater.

Cheers,

Richard


From f58f90257a5af3e6b6974090e62cad9d90d53ae5 Mon Sep 17 00:00:00 2001
From: Richard Purdie <richard.purdie@linuxfoundation.org>
Date: Tue, 23 Dec 2014 09:01:34 +0000
Subject: Add target avr support

Known issues:

* dependencies between the recipes is missing/incorrect
* on target avr libgcc isn't installed

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>

diff --git a/meta/recipes-devtools/avr-libc/avr-libc_1.8.1.bb b/meta/recipes-devtools/avr-libc/avr-libc_1.8.1.bb
new file mode 100644
index 0000000..81481ba
--- /dev/null
+++ b/meta/recipes-devtools/avr-libc/avr-libc_1.8.1.bb
@@ -0,0 +1,31 @@
+SRC_URI = "http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.8.1.tar.bz2"
+LICENSE = "BSD"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=8d91a8f153d3de715f67a5df0d841c43"
+
+SRC_URI[md5sum] = "0caccead59eaaa61ac3f060ca3a803ef"
+SRC_URI[sha256sum] = "c3062a481b6b2c6959dc708571c00b0e26301897ba21171ed92acd0af7c4a969"
+
+inherit autotools
+
+TOOLCHAIN_OPTIONS = ""
+
+TARGET_CFLAGS = ""
+TARGET_LDFLAGS = ""
+
+export CC = "avr-gcc"
+export AS = "avr-as"
+export RANLIB = "avr-ranlib"
+export AR = "avr-ar"
+
+FILES_${PN} += "${exec_prefix}/avr"
+INSANE_SKIP_${PN} = "arch staticdev"
+
+python () {
+    def replace(var, x, y):
+        d.setVar(var, d.getVar(var, True).replace(d.expand(x),y))
+
+    replace('CONFIGUREOPTS', '--host=${HOST_SYS}','--host=avr')
+    replace('CONFIGUREOPTS', '--target=${TARGET_SYS}','--target=avr')
+}
+
+
diff --git a/meta/recipes-devtools/binutils/binutils-cross-target-avr_2.24.bb b/meta/recipes-devtools/binutils/binutils-cross-target-avr_2.24.bb
new file mode 100644
index 0000000..e19cf54
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils-cross-target-avr_2.24.bb
@@ -0,0 +1,37 @@
+require binutils.inc
+require binutils-${PV}.inc
+require binutils-cross.inc
+
+DEPENDS += "flex bison zlib"
+PROVIDES = "virtual/binutils-target-avr"
+
+BPN = "binutils"
+
+
+
+python () {
+    def replace(var, x, y):
+        d.setVar(var, d.getVar(var, True).replace(d.expand(x),y))
+
+    replace('CONFIGUREOPTS', '--target=${TARGET_SYS}','--target=avr')
+    replace('EXTRA_OECONF', '--program-prefix=${TARGET_PREFIX}' ,'--program-prefix=avr-')
+    replace('do_install', '${TARGET_PREFIX}' ,'avr-')
+    replace('do_install', '${TARGET_SYS}' ,'avr')
+}
+
+EXTRA_OECONF += "--with-sysroot=/ \
+                --enable-install-libbfd \
+                --enable-install-libiberty \
+                --enable-shared \
+                "
+
+do_install () {
+    oe_runmake 'DESTDIR=${D}' install
+}
+
+sysroot_stage_all() {
+    sysroot_stage_dirs ${D} ${SYSROOT_DESTDIR}
+    sysroot_stage_dir ${D}${STAGING_DIR_NATIVE}${prefix_native}/avr ${SYSROOT_DESTDIR}${STAGING_DIR_NATIVE}${prefix_native}/avr
+    sysroot_stage_dir ${D}${STAGING_DIR_NATIVE}${prefix_native}/${BUILD_SYS} ${SYSROOT_DESTDIR}${STAGING_DIR_NATIVE}${prefix_native}/${BUILD_SYS}
+}
+
diff --git a/meta/recipes-devtools/binutils/binutils-target-avr_2.24.bb b/meta/recipes-devtools/binutils/binutils-target-avr_2.24.bb
new file mode 100644
index 0000000..66a899c
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils-target-avr_2.24.bb
@@ -0,0 +1,57 @@
+require binutils.inc
+require binutils-${PV}.inc
+
+DEPENDS += "flex bison zlib"
+
+BPN = "binutils"
+
+FILES_${PN}-dev += " \
+    ${exec_prefix}/${HOST_SYS}/avr/lib/lib*.la \
+    ${exec_prefix}/${HOST_SYS}/avr/lib/libopcodes.so \
+    ${exec_prefix}/${HOST_SYS}/avr/lib/libbfd.so \
+    ${exec_prefix}/${HOST_SYS}/avr/include \
+"
+FILES_${PN}-staticdev += " \
+    ${exec_prefix}/${HOST_SYS}/avr/lib/lib*.a \
+"
+
+USE_ALTERNATIVES_FOR = ""
+
+python () {
+    def replace(var, x, y):
+        d.setVar(var, d.getVar(var, True).replace(d.expand(x),y))
+
+    replace('CONFIGUREOPTS', '--target=${TARGET_SYS}','--target=avr')
+    replace('EXTRA_OECONF', '--program-prefix=${TARGET_PREFIX}' ,'--program-prefix=avr-')
+    replace('do_install', '${TARGET_PREFIX}' ,'avr-')
+    replace('do_install', '${TARGET_SYS}' ,'avr')
+    replace(d.expand('FILES_${PN}'), '${TARGET_PREFIX}' ,'avr-')
+    replace(d.expand('FILES_${PN}'), '${TARGET_SYS}' ,'avr')
+    d.appendVar(d.expand('FILES_${PN}'), " ${exec_prefix}/${HOST_SYS}/avr/lib/*-*.so ${libdir}/ldscripts")
+    d.appendVar(d.expand('FILES_${PN}-dbg'), " ${exec_prefix}/${HOST_SYS}/avr/lib/.debug")
+}
+
+EXTRA_OECONF += "--with-sysroot=/ \
+                --enable-install-libbfd \
+                --enable-install-libiberty \
+                --enable-shared \
+                "
+
+#do_install_append() {
+#	# Remove symlinks created by do_install
+#	for p in ${TARGET_PREFIX}* ; do
+#		rm `echo $p | sed -e s,${TARGET_PREFIX},,`
+#	done
+#}
+
+do_install () {
+    autotools_do_install
+
+    # Fix the /usr/${TARGET_SYS}/bin/* links
+    for l in ${D}${prefix}/${TARGET_SYS}/bin/*; do
+	rm -f $l
+	ln -sf `echo ${prefix}/${TARGET_SYS}/bin \
+	    | tr -s / \
+	    | sed -e 's,^/,,' -e 's,[^/]*,..,g'`${bindir}/${TARGET_PREFIX}`basename $l` $l
+    done
+}
\ No newline at end of file
diff --git a/meta/recipes-devtools/gcc/gcc-cross-target-avr_4.8.bb b/meta/recipes-devtools/gcc/gcc-cross-target-avr_4.8.bb
new file mode 100644
index 0000000..aa5c469
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-cross-target-avr_4.8.bb
@@ -0,0 +1,41 @@
+require recipes-devtools/gcc/gcc-${PV}.inc
+require gcc-cross.inc
+
+BPN = "gcc"
+PROVIDES = "virtual/gcc-target-avr"
+
+ARCH_FLAGS_FOR_TARGET = ""
+TARGET_CFLAGS = ""
+
+EXTRA_OECONF = "${@['--enable-clocale=generic', ''][d.getVar('USE_NLS', True) != 'no']} \
+                --with-gnu-ld \
+                --enable-languages=c \
+                ${GCCMULTILIB} \
+                --disable-libssp \
+                --program-prefix=avr- \
+                --without-local-prefix \
+                ${OPTSPACE} \
+                --enable-lto \
+                --disable-bootstrap \
+                --disable-libmudflap \
+                --with-system-zlib \
+                --enable-linker-build-id \
+                --with-ppl=no \
+                --with-cloog=no \
+                --enable-checking=release \
+                ${EXTRA_OECONF_PATHS}"
+
+python () {
+    def replace(var, x, y):
+        #bb.warn(x)
+        #bb.warn(d.expand(x))
+        #bb.warn(d.getVar(var))
+        #bb.warn(d.getVar(var, True).replace(d.expand(x),y))
+        d.setVar(var, d.getVar(var, True).replace(d.expand(x),y))
+
+    replace('CONFIGUREOPTS', '--target=${TARGET_SYS}','--target=avr')
+    #replace('do_configure', '${HOST_PREFIX}' ,'avr-')
+    replace('do_install', '${TARGET_PREFIX}' ,'avr-')
+    replace('do_install', '${TARGET_SYS}' ,'avr')
+}
+
diff --git a/meta/recipes-devtools/gcc/gcc-target-avr_4.8.bb b/meta/recipes-devtools/gcc/gcc-target-avr_4.8.bb
new file mode 100644
index 0000000..b2be069
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-target-avr_4.8.bb
@@ -0,0 +1,50 @@
+require recipes-devtools/gcc/gcc-${PV}.inc
+require gcc-target.inc
+
+BPN = "gcc"
+
+ARCH_FLAGS_FOR_TARGET = ""
+
+EXTRA_OECONF = "${@['--enable-clocale=generic', ''][d.getVar('USE_NLS', True) != 'no']} \
+                --with-gnu-ld \
+                --enable-languages=c \
+                ${GCCMULTILIB} \
+                --disable-libssp \
+                --program-prefix=avr- \
+                --without-local-prefix \
+                ${OPTSPACE} \
+                --enable-lto \
+                --disable-bootstrap \
+                --disable-libmudflap \
+                --with-system-zlib \
+                --with-ppl=no \
+                --with-cloog=no \
+                --enable-checking=release \
+                ${EXTRA_OECONF_PATHS}"
+
+
+python () {
+    def replace(var, x, y, d):
+        d.setVar(var, d.getVar(var, True).replace(d.expand(x),y))
+
+    ld = bb.data.createCopy(d)
+    ld.setVar("TARGET_CFLAGS", "")
+    ld.setVar("HOST_CC_ARCH", "")
+    ld.setVar("TOOLCHAIN_OPTIONS", "")
+
+    replace('CONFIGUREOPTS', '--target=${TARGET_SYS}','--target=avr', d)
+    replace('EXTRA_OECONF', '--program-prefix=${TARGET_PREFIX}' ,'--program-prefix=avr-', d)
+    replace('do_configure', '${HOST_PREFIX}' ,'avr-', ld)
+    d.setVar('do_configure', ld.getVar('do_configure'))
+    replace('do_install', '${TARGET_PREFIX}' ,'avr-', d)
+    replace('do_install', '${TARGET_SYS}' ,'avr', d)
+    replace(d.expand('FILES_${PN}'), '${TARGET_PREFIX}' ,'avr-', d)
+    replace(d.expand('FILES_cpp'), '${TARGET_PREFIX}' ,'avr-', d)
+    replace(d.expand('FILES_gcov'), '${TARGET_PREFIX}' ,'avr-', d)
+    replace(d.expand('FILES_${PN}'), '${TARGET_SYS}' ,'avr', d)
+    replace(d.expand('FILES_${PN}-plugin-dev'), '${TARGET_SYS}' ,'avr', d)
+    replace(d.expand('FILES_${PN}-dbg'), '${TARGET_SYS}' ,'avr', d)
+    replace(d.expand('FILES_${PN}-dev'), '${TARGET_SYS}' ,'avr', d)
+    #d.appendVar(d.expand('FILES_${PN}'), " ${exec_prefix}/${HOST_SYS}/avr/lib/*-*.so")
+    #d.appendVar(d.expand('FILES_${PN}-dbg'), " ${exec_prefix}/${HOST_SYS}/avr/lib/.debug")
+}




  parent reply	other threads:[~2014-12-23  9:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-20 14:43 Cross compiler which runs on the target architecture Peter Saunderson
2014-12-22 14:53 ` Richard Purdie
2014-12-23 12:49   ` Nathan Rossi
2014-12-23 13:13     ` Peter Saunderson
2015-01-11 15:23       ` Peter Saunderson
2014-12-23  9:08 ` Richard Purdie [this message]
2020-12-09 12:38   ` [yocto] " Stefan Herbrechtsmeier
2020-12-09 18:23     ` Khem Raj
2020-12-16 17:17       ` Stefan Herbrechtsmeier
2020-12-17 18:59         ` Peter
2020-12-17 21:04           ` [yocto] " Stefan Herbrechtsmeier
2020-12-18 11:10             ` Peter
     [not found]   ` <164F0CAF395EE75B.22015@lists.yoctoproject.org>
     [not found]     ` <e3b2fe77-585c-51dd-b4df-7265090feb50@herbrechtsmeier.net>
     [not found]       ` <CAF+qF8fNJvCRZrjhCwnAzZScGRUSbUarwi7+SYaw7Jc-Dh2W7g@mail.gmail.com>
2020-12-16 16:40         ` [yocto] " Stefan Herbrechtsmeier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1419325725.1777.7.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=peteasa@gmail.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.