Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build system for native loadable modules #8399

Merged
merged 8 commits into from
Nov 9, 2023
24 changes: 19 additions & 5 deletions lmdk/cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ foreach(MODULE ${MODULES_LIST})
add_executable(${MODULE})
add_subdirectory(${LMDK_BASE}/modules/${MODULE} ${MODULE}_module)

### set_target_properties(${MODULE} PROPERTIES OUTPUT_NAME ${MODULE}.mod)
# uncomment line below to compile module with debug information
#target_compile_options(${MODULE} PUBLIC "-g3")

target_include_directories(${MODULE} PRIVATE
"${LMDK_BASE}/include"
Expand All @@ -35,9 +36,9 @@ foreach(MODULE ${MODULES_LIST})
)

target_link_options(${MODULE} PRIVATE
"-nostdlib" "-nodefaultlibs"
"-nostartfiles"
"-Wl,--no-undefined" "-Wl,--unresolved-symbols=report-all" "-Wl,--error-unresolved-symbols"
#"-Wl,--gc-sections" # may remove .bss and that will result in rimage error, do not use for now
"-Wl,--gc-sections"
"-Wl,-Map,$<TARGET_FILE:${MODULE}>.map" # optional: just for debug
"-T" "${MODULE}_ldscripts/elf32xtensa.x"
)
Expand All @@ -55,13 +56,26 @@ cmake_path(APPEND SOF_BASE "../build-rimage" OUTPUT_VARIABLE RIMAGE_SOF_INSTALL_
cmake_path(NORMAL_PATH RIMAGE_SOF_INSTALL_DIR)
cmake_path(ABSOLUTE_PATH SIGNING_KEY BASE_DIRECTORY ${CMAKE_SOURCE_DIR} NORMALIZE)

foreach(MOD_NAME IN LISTS MODULES_LIST)
list(APPEND RIMAGE_MODULES_LIST ${MOD_NAME}.mod)

# Change .module section flags to tell rimage to not include it in a final image
add_custom_target(${MOD_NAME}.mod
COMMENT "Preparing .mod(ule) files for rimage"
DEPENDS ${MOD_NAME}
COMMAND ${CMAKE_OBJCOPY}
--set-section-flags .module=noload,readonly
${MOD_NAME} ${MOD_NAME}.mod
)
endforeach()

find_program(RIMAGE_COMMAND NAMES rimage
PATHS "${RIMAGE_INSTALL_DIR}"
HINTS "${RIMAGE_SOF_INSTALL_DIR}"
REQUIRED)

add_custom_target(${PROJECT_NAME}_target ALL
DEPENDS ${MODULES_LIST}
COMMAND ${RIMAGE_COMMAND} -k ${SIGNING_KEY} -f 2.0.0 -b 1 -o ${RIMAGE_OUTPUT_FILE} -c ${TOML} -e ${MODULES_LIST}
DEPENDS ${RIMAGE_MODULES_LIST}
COMMAND ${RIMAGE_COMMAND} -k ${SIGNING_KEY} -f 2.0.0 -b 1 -o ${RIMAGE_OUTPUT_FILE} -c ${TOML} -e ${RIMAGE_MODULES_LIST}
COMMAND ${CMAKE_COMMAND} -E cat ${RIMAGE_OUTPUT_FILE}.xman ${RIMAGE_OUTPUT_FILE} > ${OUTPUT_FILE}
)
2 changes: 1 addition & 1 deletion lmdk/cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ cmake_path(ABSOLUTE_PATH LMDK_BASE NORMALIZE)
set(SOF_BASE ${LMDK_BASE}/..)
cmake_path(ABSOLUTE_PATH SOF_BASE NORMALIZE)

set(RIMAGE_INCLUDE_DIR ${SOF_BASE}/rimage/src/include)
set(RIMAGE_INCLUDE_DIR ${SOF_BASE}/tools/rimage/src/include)
cmake_path(ABSOLUTE_PATH RIMAGE_INCLUDE_DIR NORMALIZE)
13 changes: 13 additions & 0 deletions lmdk/cmake/ldscripts/bss_linker_script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,18 @@ SECTIONS {
_next_end = ABSOLUTE(.);
*(.bss)
*(.bss.*)

/* Heap memory */
. = ALIGN(4);
__stack = .;
softwarecki marked this conversation as resolved.
Show resolved Hide resolved
_end = .;
softwarecki marked this conversation as resolved.
Show resolved Hide resolved
KEEP(*(.heap_mem))

/* Use the unused rest of the memory page as a heap */
. = ALIGN(4096);

/* The sbrk function implementation by xtensa incorrectly checks whether the allocated
memory block fits in the heap, so we have to add 1 to the end of the heap marker. */
_heap_sentry = . + 1;
} >HPSRAM_seg : bss_phdr
}
7 changes: 4 additions & 3 deletions lmdk/cmake/ldscripts/data_linker_script.txt
softwarecki marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ SECTIONS {
_data_start = ABSOLUTE(.);
*(.data)
*(.data.*)
*(.*.data)
_data_end = ABSOLUTE(.);
} >HPSRAM_seg : data_phdr

.rodata : ALIGN(4096) {
.rodata : {
_rodata_start = ABSOLUTE(.);
*(.gnu.linkonce.r.*)
*(.rodata)
Expand All @@ -24,7 +25,7 @@ SECTIONS {
} >HPSRAM_seg : rodata_phdr

/* Module manifest is here */
.module : ALIGN(4096) {
.module 0 : {
KEEP(*(.module))
} >HPSRAM_seg : rodata_phdr
}
}
4 changes: 2 additions & 2 deletions lmdk/cmake/xtensa-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ cmake_path(APPEND XTENSA_TOOLCHAIN_PATH "XtensaTools" OUTPUT_VARIABLE TOOLCHAIN_
set(CROSS_COMPILE xt-)

# clang or xcc
find_program(CMAKE_C_COMPILER NAMES ${CROSS_COMPILE}xcc
find_program(CMAKE_C_COMPILER NAMES ${CROSS_COMPILE}clang
softwarecki marked this conversation as resolved.
Show resolved Hide resolved
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)
# clang++ or xc++
find_program(CMAKE_CXX_COMPILER NAMES ${CROSS_COMPILE}xc++
find_program(CMAKE_CXX_COMPILER NAMES ${CROSS_COMPILE}clang++
PATHS ${TOOLCHAIN_BASE} PATH_SUFFIXES "bin" REQUIRED NO_DEFAULT_PATH
)
find_program(CMAKE_LD NAMES ${CROSS_COMPILE}ld
Expand Down
2 changes: 1 addition & 1 deletion tools/rimage/src/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static int man_module_create(struct image *image, struct manifest_module *module
fprintf(stdout, "info: ignore .bss section for bootloader module\n");
} else {
err = elf_section_header_get_by_name(&module->file.elf, ".bss", &bss);
if (err)
if (err && !image->loadable_module)
fprintf(stderr, "warning: can't find '.bss' section in module %s.\n",
module->file.elf.filename);

Expand Down