build ROM library


Jacob Avraham
 

Hi,
I'm planning to build a couple of libraries that will reside in ROM, and call them from a Zephyr application.
The nature of these libraries is that I don't have control of their source code and their APIs, so calling them
indirectly using a function pointers table is not a route I'd like to go.
The ROM code could be some standard compression library, or maybe portions of commonly used libc functions, and it will not make calls to external code, like OS or other libraries.
 
The questions are:
1. Can I use Zephyr's build infrastructure to build a library (preferred ELF format) that does not contain the Zephyr OS and is not an application? I figure I'll probably need to relocate the data section of this library from ROM to RAM during boot.
2. How can I link a Zephyr application with this library so that all the calls will be resolved?

Thanks,
Jacob


Lawrence King
 

Hi Jacob:

Yes you can use the Zephyr build system to build a library. Just put a CMakeLists.txt file in the subdirectory where you have your library (the atmel crypto library in  my case). Here is the CMakeLists.txt file
cmake_minimum_required(VERSION 3.13.1)
set (CMAKE_C_FLAGS "-Wall -Wextra -Wcast-align -fstack-usage -fwrapv -fno-strict-aliasing -O1 -pedantic -Wall -Wextra -fmessage-length=0 -ffunction-sections -fdata-sections -Wstrict-prototypes --save-temps -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -I $ENV{ZEPHYR_BASE}/../modules/crypto/tinycrypt/lib/include " CACHE INTERNAL "")
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
add_subdirectory(lib)

To build the library I have this bash script in the directory above
# rebuild the atmel library
cd atmel_crypto/; rm -rf build; west build; cd ..

To link the prebuilt libraries into the zephyr build, it is just a latter of telling CMakeLists.txt where the libraries are, add something like this to your CMakeLists.txt
target_sources(app PRIVATE ${app_sources})
include_directories(./atmel_crypto/lib)
# add the prebuilt library
find_library(ATMEL_LIB libcryptoauth.a PATHS ./atmel_crypto/build/lib/)
target_link_libraries(zephyr INTERFACE "${ATMEL_LIB}")


The part I haven't done is forcing the libraries to link to a specific location (your ROM), maybe someone else can tell you how to do that.

On Wed, May 25, 2022 at 9:03 AM Jacob Avraham <jacob.avraham@...> wrote:
Hi,
I'm planning to build a couple of libraries that will reside in ROM, and call them from a Zephyr application.
The nature of these libraries is that I don't have control of their source code and their APIs, so calling them
indirectly using a function pointers table is not a route I'd like to go.
The ROM code could be some standard compression library, or maybe portions of commonly used libc functions, and it will not make calls to external code, like OS or other libraries.
 
The questions are:
1. Can I use Zephyr's build infrastructure to build a library (preferred ELF format) that does not contain the Zephyr OS and is not an application? I figure I'll probably need to relocate the data section of this library from ROM to RAM during boot.
2. How can I link a Zephyr application with this library so that all the calls will be resolved?

Thanks,
Jacob