AtomVM icon indicating copy to clipboard operation
AtomVM copied to clipboard

esp32: system_architecture returns <<"Generic--">>

Open petermm opened this issue 1 year ago • 6 comments

erlang:system_info(system_architecture), seems off. https://www.atomvm.net/doc/main/apidocs/erlang/estdlib/erlang.html#system-info-1 : system_architecture the processor and OS architecture (binary)

0.6.5 release image and also local builds return <<"Generic--">> on esp32.

code search suggests it should return something like <<"ESP_IDF-3.2-xtensa_esp32">>

petermm avatar Nov 20 '24 19:11 petermm

So the documentation is not clear, or our implementation is wrong… it looks like this is returning the OS architecture as defined by the compiler… any of the platforms will report “Generic” if they are using neither X86_64 or ARM compilers.

UncleGrumpy avatar Dec 16 '24 19:12 UncleGrumpy

I should have said as defined by cmake configuration, not necessarily the compiler itself.

UncleGrumpy avatar Dec 19 '24 23:12 UncleGrumpy

Yeah,

I cooked this up (from some of your code):

src/platforms/esp32/components/libatomvm/CMakeLists.txt

if (CMAKE_SYSTEM_NAME STREQUAL "Generic")
     if (CONFIG_IDF_TARGET_ARCH_XTENSA)
         set(CMAKE_SYSTEM_NAME "xtensa")
     elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
         set(CMAKE_SYSTEM_NAME "riscv32")
     endif()
 endif()

 if (CMAKE_SYSTEM_PROCESSOR STREQUAL "")
     if (CONFIG_IDF_TARGET)
         set(CMAKE_SYSTEM_PROCESSOR "${CONFIG_IDF_TARGET}")
     endif()
 endif()

 if (CMAKE_SYSTEM_VERSION STREQUAL "")
         execute_process(
             COMMAND idf.py --version
             WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
             OUTPUT_VARIABLE SYSTEM_VERSION
             OUTPUT_STRIP_TRAILING_WHITESPACE
         )
         # Use idf_get_version() to get the version directly
         string(REPLACE "ESP-IDF" "" SYSTEM_VERSION "${SYSTEM_VERSION}")
         string(REPLACE "-" "_" SYSTEM_VERSION "${SYSTEM_VERSION}")
         string(STRIP "${SYSTEM_VERSION}" SYSTEM_VERSION)
         string(REPLACE " " "" SYSTEM_VERSION "${SYSTEM_VERSION}")
     if (NOT SYSTEM_VERSION STREQUAL "")
         set(CMAKE_SYSTEM_VERSION "${SYSTEM_VERSION}")
     endif()
 endif()

which gives you: "riscv32-v5.3.2_210_g12938e511e_dirty-esp32c3"

but it runs into build issue due to this "Generic" check https://github.com/atomvm/AtomVM/blob/1ca523c6c9834e890ad59ac611703a9d3ea4f048/src/libAtomVM/CMakeLists.txt#L278

And I have a very limited understanding of the build system, especially across platforms..

but the utility of erlang:system_info(system_architecture) is limited, so low priority, and mostly it's deciding what output should be.

petermm avatar Dec 20 '24 08:12 petermm

I don't think we want to chant the CMAKE_ configuration there, that would lead to build problems... but I believe we could add a separate definition for the compiler - like AVM_SYSTEM_PROCESSOR.

UncleGrumpy avatar Dec 20 '24 10:12 UncleGrumpy

That definition for Generic is important for all of the MCU platforms in the cmake configuration process, so we don't want to mess with that.

UncleGrumpy avatar Dec 20 '24 10:12 UncleGrumpy

This is also slightly related to PR #1117 which I closed. I didn’t feel like we ever came to a logical consensus on what the returns should be, and as you point out, is not frequently needed.

UncleGrumpy avatar Dec 28 '24 23:12 UncleGrumpy