im-tomu / tomu-quickstart

A quicker way to get started building samples
Apache License 2.0
151 stars 38 forks source link

Nothing builds with Ubuntu 18.04 #13

Open sowbug opened 6 years ago

sowbug commented 6 years ago

This isn't your fault, but you should know about it. Something broke in the gcc toolchain between Ubuntu 16.04 and 18.04, and many programs you build and try to flash to your Tomu will fail to load. The miniblink example works, but u2f and usb-audiostream don't. They all work if built with 16.04.

I think this was happening with GnuK as well.

I worked around this by starting up a Google Compute Engine instance with 16.04 and scping stuff back and forth. It scratched my itch, but it's pretty annoying.

I hope someone narrows down exactly what's wrong and files a good bug with whichever tool is broken. I haven't had time to compare generated object files, which is what I'd do to start with.

xobs commented 6 years ago

Thanks for reporting this.

It appears to be an issue with libopencm32. Specifically, the usbd_poll() function -- if you disable the USB ISR, it works just fine.

I'm without my debugger right now, so I'll see how much debugging I can do. It certainly feels like 18.04 got aggressive when it comes to packing, and maybe some struct got not-word-aligned.

xobs commented 6 years ago

Ubuntu 18.04 is completely broken.

Their memcpy() jumps to an address that doesn't exist:

xobs@Pazuzu:~/Code/Tomu/quickstart/usb-hid$ gdb-multiarch usb-hid.elf
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from usb-hid.elf...done.
(gdb) disassemble memcpy,+4
Dump of assembler code from 0x5950 to 0x5954:
   0x00005950 <memcpy+0>:       movs    r7, r1
   0x00005952 <memcpy+2>:       b.n     0x5ffa
End of assembler dump.
(gdb) x 0x5ffa
0x5ffa: Cannot access memory at address 0x5ffa
(gdb)

You may need to try a different compiler.

xobs commented 6 years ago

Upstream bug: https://bugs.launchpad.net/ubuntu/+source/gcc-arm-none-eabi/+bug/1767223

The issue is that it's ignoring the -mcpu=cortex-m0plus and linking in the desktop version of libc, which contains ARM instructions. The Cortex M-series only supports Thumb2 instructions, so any time you call any standard library function the program will crash.

xobs commented 6 years ago

Workaround to fix the issue on Ubuntu 18.04 LTS (courtesy of @MadHacker on #tomu): https://github.com/bbcmicrobit/micropython/issues/514#issuecomment-404759614