Gentoo Archives: gentoo-embedded

From: Markos Chandras <hwoarang@g.o>
To: gentoo-embedded@l.g.o
Subject: Re: [gentoo-embedded] Crossdev and arm-none-eabi and armv7m-none-eabi toolchain builds.
Date: Fri, 02 Nov 2012 15:08:13
Message-Id: CAG2jQ8g_iXpLT9wGPLmw2dP1gVjDhr0Ni1qEXadc0rcFerCJTA@mail.gmail.com
In Reply to: [gentoo-embedded] Crossdev and arm-none-eabi and armv7m-none-eabi toolchain builds. by "Pablo Pölcher"
1 On Fri, Nov 2, 2012 at 4:19 AM, "Pablo Pölcher" <talosds@×××.de> wrote:
2 > Hello,
3 >
4 > this is my first post in this list, so please forgive any mistakes I may be doing here.
5 >
6 > I have been recently trying to compile a toolchain for the NXP LPC17xx
7 > microcontroller series using crossdev and came across a series of
8 > problems, which I have solved to a certain extent and wanted to share them in case somebody is interested.
9 >
10 > The CHOST I was trying to (and could finally) build for is «armv7m-none-eabi» (by running crossdev -t armv7m-none-eabi -s4 --ex-gdb). The main problem I encountered is that I couldn't get a stage1 gcc built. The build log would always end with the error message:
11 >
12 > «configure: error: cannot compute suffix of object files: cannot compile»
13 >
14 > After poking among the different log files, I found out that the problem
15 > was that the compiler was being asked to generate ARM code for a Thumb-only microcontroller, to what gcc would simply exit with the error code:
16 >
17 > «Error: Target CPU does not support ARM mode»
18 >
19 > So I traced back the generation of the argument list for the configure script back to toolchain.eclass, wrote a little patch and bingo! I could get past the annoying error. I just checked for the architecture to be armv7-m and added the --with-mode=thumb switch. There's an additional case to consider, and that is the armv6m architectures, but since I haven't tried them, yet, I haven't tested it nor included them in my patch.
20 >
21 > Anyway, once I got through this first problem, I had trouble again while compiling the stage3 gcc. Poking around a bit more, I found out that if the openmp USE flag is set, the gcc ebuild will try to build libgomp, even if no support for pthreads is present (as is the case with my newlib-based toolchain), so I could get around by disabling openmp during crossdev execution, but I guess this could also go as a toolchain.eclass patch.
22 >
23 > One more thing is that I couldn't see any place where the use of the multilib USE flag is recommended when compiling newlib, but still I found
24 > it useful.
25 >
26 > And one last thing I noticed (but couldn't get to solve, yet) is that I could never get crossdev to generate thumb code when compiling newlib for the «arm-none-eabi» CHOST, even if I pass the multilib USE flag. I tried tweaking several things, but I guess I should take a longer while to trace
27 > the error (feature?) and fix it. The crt0.o in /usr/arm-none-eabi/lib/thumb/ looks like this:
28 >
29 > 00000000 <_mainCRTStartup>:
30 > 0: e3b00016 movs r0, #22
31 > 4: e28f10e8 add r1, pc, #232 ; 0xe8
32 > 8: ef123456 svc 0x00123456
33 > c: e59f00e0 ldr r0, [pc, #224] ; f4 <change_back+0x4>
34 > 10: e5901000 ldr r1, [r0]
35 > 14: e3510000 cmp r1, #0
36 > ...
37 >
38 > As you can see, it's ARM code. The armv7m-none-eabi version of crt0.o in
39 > the thumb directory looks like:
40 >
41 > 00000000 <_mainCRTStartup>:
42 > 0: 2016 movs r0, #22
43 > 2: a12d add r1, pc, #180 ; (adr r1, b8 <_mainCRTStartup+0xb8>)
44 > 4: beab bkpt 0x00ab
45 > 6: 482c ldr r0, [pc, #176] ; (b8 <_mainCRTStartup+0xb8>)
46 > 8: 6801 ldr r1, [r0, #0]
47 > a: 2900 cmp r1, #0
48 >
49 > Nice Thumb code. I found out this while pulling my hair off trying to find out why my nicely compiled code would throw a double hardfault on an LPC1765. I was using the arm-none-eabi toolchain, then. Once I switched to
50 > the armv7m one, everything was solved.
51 >
52 > Anyway, I hope this helps somebody somehow, and I'm sorry if you already
53 > knew about all this.
54 >
55 > Best regards,
56 > Pablo Pölcher
57
58 Hi Pablo,
59
60 I'd say that patches for portage eclasses should be attached on
61 bugzilla[1] as a new bug
62
63 [1]: https://bugs.gentoo.org
64
65 --
66 Regards,
67 Markos Chandras / Gentoo Linux Developer / Key ID: B4AFF2C2

Replies