esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.07k stars 13.33k forks source link

xtensa-lx106-elf-g++: bad CPU type in executable on a M2 Mac without rosetta emulation installed #8725

Open aleroot opened 1 year ago

aleroot commented 1 year ago

I'm trying to compile and upload a sketch to a NodeMCU Lolin V3 board using arduino-cli_0.29.0_macOS_ARM64 but I get the following error whenever I try to compile:

alessio@AleMacBookPro Tools % ./arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 example

Used platform   Version Path                                                                    
esp8266:esp8266 3.0.2   /Users/alessio/Library/Arduino15/packages/esp8266/hardware/esp8266/3.0.2

Error during build: fork/exec /Users/alessio/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/xtensa-lx106-elf-g++: bad CPU type in executable

Looks clear that the executable file xtensa-lx106-elf-g++ has been built for x86-64 Mac instead of AMR64... How can I download the correct files for my architecture?

I have been following this procedure, the problem is that arduino-cli core install esp8266:esp8266 downloads the wrong architecture executables, it should download executables built for ARM64 instead of those for x86-64.

earlephilhower commented 1 year ago

Sorry, for now you need to use Rosetta/etc. None of the maintainers use Macs, and all tools are cross-built under Linux using a Docker image w/full toolchains set up.

If you, or some other Mac user, can add Linux-hosted cross-building tools for the Apple ARM workflow to https://github.com/earlephilhower/gcc-cross then we can easily add it to the build process.

earlephilhower commented 1 year ago

On further inspection, looks like OSXCross was updated to later Mac SDKs to include ARM target support.

https://github.com/tpoechtrager/osxcross

The issue now is that by moving the SDK forward, we'll lose support for older Macs stuck on obsolete/EOL versions of MacOS. Also will need to rebuild a portable Python for ARM...

aleroot commented 1 year ago

@earlephilhower can't you create a new 4.X version of the tool with the new SDK and compiled for ARM64 ? The older Macs could still point to the older branch version 3.X ...

seemywingz commented 1 year ago

I realize this issue states "without rosetta emulation installed", but I was able to get this working on a 2022 M2 MacBook Air using rosetta and VSCode, if you're using the Arduino IDE, just run softwareupdate --install-rosetta --agree-to-license

Software:

    System Software Overview:

      System Version: macOS 14.1 (23B74)
      Kernel Version: Darwin 23.1.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: MacBook Air
      Secure Virtual Memory: Enabled
      System Integrity Protection: Enabled
      Time since boot: 1 hour, 58 minutes

Hardware:

    Hardware Overview:

      Model Name: MacBook Air
      Model Identifier: Mac14,2
      Model Number: MLY33LL/A
      Chip: Apple M2
      Total Number of Cores: 8 (4 performance and 4 efficiency)
      Memory: 8 GB
      System Firmware Version: 10151.41.12
      OS Loader Version: 10151.41.12
      Activation Lock Status: Enabled

Install Rosetta, HomeBrew , Arduino IDE, and CLI (if not already installed)

softwareupdate --install-rosetta --agree-to-license
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install arduino-ide arduino-cli

Install the VSCode Arduino Extension

https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino

Configure the Arduino Extention to use arduino-cli

Arduino: Command Path: arduino-cli

Arduino: Path: /opt/homebrew/bin/

Arduino: Use Arduino CLI: checked

ℹ️ Important! Restart Visual Studio Code

I don't notice any additional overhead when compiling or uploading

. Variables and constants in RAM (global, static), used 31160 / 80192 bytes (38%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1508     initialized variables
╠══ RODATA   3436     constants       
╚══ BSS      26216    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 61355 / 65536 bytes (93%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     28587    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 278932 / 1048576 bytes (26%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     278932   code in flash   
...
esptool.py v3.0
Serial port /dev/tty.usbserial-10
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 08:3a:8d:cd:9b:55
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 316608 bytes to 228202...
Writing at 0x00000000... (7 %)
Writing at 0x00004000... (14 %)
Writing at 0x00008000... (21 %)
Writing at 0x0000c000... (28 %)
Writing at 0x00010000... (35 %)
Writing at 0x00014000... (42 %)
Writing at 0x00018000... (50 %)
Writing at 0x0001c000... (57 %)
Writing at 0x00020000... (64 %)
Writing at 0x00024000... (71 %)
Writing at 0x00028000... (78 %)
Writing at 0x0002c000... (85 %)
Writing at 0x00030000... (92 %)
Writing at 0x00034000... (100 %)
Wrote 316608 bytes (228202 compressed) at 0x00000000 in 22.1 seconds (effective 114.8 kbit/s)...
Hash of data verified.