esp_image: invalid SPI mode 76

mkotzjan
Posts: 2
Joined: Wed May 09, 2018 12:34 pm

esp_image: invalid SPI mode 76

Postby mkotzjan » Tue May 15, 2018 9:43 am

Hey there,

I'm currently working on porting OpenPEARL (Informations: https://sourceforge.net/projects/openpearl/ and https://en.wikipedia.org/wiki/PEARL_(pr ... _language)) as part of my bachelor thesis.
The user should be able to write PEARL code, which gets translated to C++. I am using the template-project to build all the ESP components with the ESP makefiles to use the correct compiler and linker flags. This is done once at the installation of OpenPEARL. I am using a modified version of the ESP32 build command to build and link my generated files (hello_world.cc and system.cc) every time I want to build my application:

Code: Select all

xtensa-esp32-elf-gcc -DTARGET=3 -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-static -Wl,--start-group -mlongcalls -frtti -u call_user_start_cpu0 -Os -I /usr/local/include system.cc hello_world.cc -L/usr/local/lib/OpenPEARLesp32 -lapp_trace -lapp_update -laws_iot -lboardsupport -lbootloader_support -lbt -lcoap -lconsole -lcxx -u __cxa_guard_dummy -ldriver -lesp32 /home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/esp32/libhal.a -L/home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/esp32/lib -lcore -lrtc -lnet80211 -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2 -lespnow -lphy -L/home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/esp32/ld -L/home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf-template/build/esp32 -T esp32_out.ld -u ld_include_panic_highint_hdl -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -lesp_adc_cal -lethernet -lexpat -lfatfs -lfreertos -Wl,--undefined=uxTopUsedPriority -lheap -lidf_test -ljsmn -ljson -llibsodium -llog -llwip -lmbedtls -lmdns -lmicro-ecc /home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/newlib/lib/libc.a /home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/newlib/lib/libm.a -lnewlib -lnghttp -lnvs_flash -lopenpearl_common -lopenssl -lpthread -lsdmmc -lsoc -lspi_flash -lspiffs -ltcpip_adapter -lulp -lvfs -lwear_levelling -lwpa_supplicant -lxtensa-debug-module -lmain -lgcc -lstdc++ -lgcov -Wl,--end-group -Wl,-EL -o $$fn -Wl,-Map=esp32.map
I'm using this as a flash command:

Code: Select all

python /home/michael/code/hfu/thesis/OpenPEARL/openpearl-code/runtime/esp32/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 115200 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /usr/local/lib/OpenPEARLesp32/bootloader.bin 0x10000 hello_world 0x8000 /usr/local/lib/OpenPEARLesp32/partitions_singleapp.bin
I added two components (openpearl-common and boardsupport) and I did some changes to the freertos component (added classes needed by OpenPEARL). I also exchanged the main.c with my personal main.cc, which starts the OpenPEARL tasks provided in hello_world.cc.

I'm able to build and flash, but on connection with miniterm I receive the following output:

Code: Select all

--- forcing DTR inactive
--- forcing RTS inactive
--- Miniterm on /dev/ttyUSB1  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x3e (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4684
load:0x40078000,len:0
load:0x40078000,len:12148
entry 0x40078e0c
E (37) esp_image: image at 0x10000 has invalid magic byte
W (37) esp_image: image at 0x10000 has invalid SPI mode 76
E (38) boot: Factory app partition is not bootable
E (43) boot: No bootable app partitions in the partition table
user code done
I am still able to build and flash the template project directly with "make flash monitor", although I'm getting an Guru Meditation Error (but this is a problem I have towork on afterwards ;) )

What could cause an SPI mode this high? What is the SPI mode of the image used for? I thought the SPI mode is used for flashing...
I know this could be a difficult question to answer because of my specific use case and I'm hoping for every small clue you can give me.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: esp_image: invalid SPI mode 76

Postby ESP_Angus » Tue May 15, 2018 10:14 am

Hi mkotzjan,

What type of file is "hello_world", as passed to esptool.py write_flash"? ESP-IDF bootloader can only boot .bin files produced by the esptool.py "elf2image" subcommand. The invalid magic number and SPI mode in the header makes me think this may not be a .bin file.

You can watch the output of "make V=1" in ESP-IDF to see the command required to convert the hello_world ELF to a .bin. It's also documented here:
https://github.com/espressif/esptool#co ... -elf2image

You may want to consider whether you can fit the OpenPEARL build system into ESP-IDF as a component, rather than adapting OpenPEARL to build an ESP32 binary. Some sections of the docs which may help:
https://esp-idf.readthedocs.io/en/lates ... t-makefile
or
https://esp-idf.readthedocs.io/en/lates ... generation

Angus

mkotzjan
Posts: 2
Joined: Wed May 09, 2018 12:34 pm

Re: esp_image: invalid SPI mode 76

Postby mkotzjan » Tue May 15, 2018 1:09 pm

Hey ESP_Angus,

thank you so much for your quick reply. This was the solution. I wasn't generating the image file and uploaded the (very big) elf file to the esp. :oops: I totally missed that step...

Also thank you for your suggestions regarding the build system. I always had the feeling that this is not the best solution but I'm running out of time. I will have a look into a better solution if I can, otherwise this will be a chapter in my thesis and maybe someone else can deal with it.

Who is online

Users browsing this forum: Bing [Bot] and 72 guests