zephyrproject-rtos / meta-zephyr-sdk

Zephyr SDK (obsolete)
MIT License
44 stars 29 forks source link

esp32 doesn't build with the SDK compiler #78

Closed zephyrbot closed 5 years ago

zephyrbot commented 7 years ago

Reported by Andy Ross:

Right now our SDK xtensa toolchain can't build for esp32 because of missing instruction support. Some code in swap.S wants to save off the "cpenable" special register when the number of coprocessors ("XCHAL_CP_NUM") is greater than 0. This is zero with the existing targets, but a header (part of the Espressif IDF kit, not ours) sets it to 1 for the ESP-32.

This results in an assembly instruction line that looks like "wsr.cpenable a3" (the code actually uses a numeric "224" instead, which seems weird to my eyes as the symbolic name is fixed by specification works just fine in the assembler)

On the Espressif-provided toolchain this compiles fine. It also builds just fine with a "xtensa-andy-elf" binutils (both head and 2.27) that I built from scratch on my workstation. But on the SDK compiler:

$ /opt/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/xtensa-zephyr-elf/xtensa-zephyr-elf-as test.S
test.S: Assembler messages:
test.S:2: Error: invalid register 'cpenable' for 'wsr' instruction

The root cause appears to be the use of an "xtensa_overlay" file in our SDK build, which itself is designed to modify the binutils config for a given xtensa core. Our setup uses "sample_controller" as the core name, and that apparently turns this off.

It seems crazy, but binutils appears to have no way to turn these features on or off at runtime with compile switches. The "official" xtensa model (I think this overlay thing comes from Cadence, it's not part of upstream binutils) is that every possible instantiation of a core needs its own complete toolchain!

This may not be 100% fixable in all cases: there may be toolchain features which simply don't generate compatible code. But this particular problem isn't one of them: we can simply arrange not to emit such instructions on devices that lack support. And in fact we already do.

Figure out the "overlay" mechanism and see if we can remove the special register limitations from it. It's a dumb feature, and not even part of upstream binutils. Alternatively choose a "superset" core type that encompasses features found on both Qemu and ESP-32.

(Imported from Jira SDK-62)

AlvinoL commented 6 years ago

I have the same problem. Did you solve this issue?

nashif commented 6 years ago

You need to follow the docs for building ESP32, the toolchain is not supported with the Zephyr SDK and probably will not be for a while.

AlvinoL commented 6 years ago

I followed the docs in Zephyr's Tutorial (ESP32 Overview), So I think that is a problem with Xtensa Version, because the assembler instructions is different... Should I use which Xtensa version? (Zephyr Compatible) Can you help me with a better tutorial? Because I think to It will be a problem to another developers. Thankful!

nashif commented 5 years ago

for esp32, use vendor toolchain