Freedom Studio sifive-welcome.elf: file format not recognized


/Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf: file format not recognized
make: *** [Makefile:315: /Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.hex] Error 1

How to fix it ?

Is /Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf actually a RISC-V ELF file? What does file /Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf say?

I work with this file for more than two months now. Freedom studio compile RISC-V .S and .c without problem until now.

I am sorry I don’t understand what … /sifive-welcome.elf say?

Run the exact command there.

zsh: permission denied: /Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf

The Finder info show that I have a Read & Write permission.
I set the same permission to “staff” and “everyone” but the same error message is shown.

I said run file /Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf. Clearly trying to run the bare-metal RISC-V binary on x86 or arm64 macOS is not going to work.

Hi Alain,

Jessica is suggesting running the ‘file’ command with the elf file as an arqument, like:

$ file sifive-welcome.elf

That should give you output like:

$ file sifive-welcome.elf
sifive-welcome.elf: ELF 32-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, with debug_info, not stripped

That is what I see on Ubuntu, should be similar on MacOS (but I have not tried). I don’t know that the ‘file’ command is natively available on MacOS, you may need to install it via homebrew, if not.

My apologies, “file” is part of the command. The output of the command is:

/Users/alain/wsFreedomStudio/qemu_sifive_s51_sifive_welcome/src/debug/sifive-welcome.elf: GCC precompiled header (version 014) for C

1 Like

So it looks like the ELF file was produced using, possibly, a native toolchain and not the SiFive RISC-V toolchain. Can you do a clean build and look at the build log to see which compiler and linker is being used? Are you building this in Freedom Studio?

A precompiled header is what you get when you try to compile a header file.

rohan:2054$ cat tmp.h
#define FOO 1
rohan:2055$ gcc -o program.elf tmp.h
rohan:2056$ file program.elf 
program.elf: GCC precompiled header (version 014) for C

This suggests an error in your build command where you accidentally tried to compile a header file instead of a source file.

Without the -o option, compiling tmp.h produces a tmp.h.gch file.

Replacing sifive-welcome.elf with a copy from a backup disk solve the problem. Why this file was corrupted, I don’t know…

Thank you everyone for suggestions.