1# Intel CAVS SoC family CMake file 2# 3# Copyright (c) 2020-2024 Intel Corporation 4# SPDX-License-Identifier: Apache-2.0 5 6zephyr_interface_library_named(INTEL_ADSP_COMMON) 7 8zephyr_library_named(intel_adsp_common) 9zephyr_include_directories(include) 10zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) 11 12zephyr_library_sources_ifdef(CONFIG_INTEL_ADSP_IPC ipc.c) 13 14zephyr_library_sources( 15 rimage_modules.c 16 boot.c 17 soc.c 18 mem_window.c 19 boot_complete.c 20 ) 21 22zephyr_library_sources_ifdef(CONFIG_ADSP_CLOCK clk.c) 23 24if(CONFIG_SMP OR CONFIG_MP_MAX_NUM_CPUS GREATER 1) 25 zephyr_library_sources(multiprocessing.c) 26endif() 27 28zephyr_library_link_libraries(INTEL_ADSP_COMMON) 29 30target_include_directories(INTEL_ADSP_COMMON INTERFACE include) 31target_link_libraries(INTEL_ADSP_COMMON INTERFACE intel_adsp_common) 32 33set(KERNEL_REMAPPED ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}-remapped.elf) 34set(EXTMAN ${CMAKE_BINARY_DIR}/zephyr/extman.bin) 35 36if(${CMAKE_HOST_WIN32}) 37 set(NULL_FILE nul) 38elseif(${CMAKE_HOST_UNIX}) 39 set(NULL_FILE /dev/null) 40endif() 41 42# Generate rimage modules from the base kernel ELF file. Note the 43# warning squashing on the objcopy steps. Binutils has a misfeature 44# where if the copy removes all the sections from an input ELF program 45# header (our link generates lots of phdrs because of the disjoint 46# cacheability addresses), it will warn about an "empty" segment even 47# though it was TOLD to drop the contents! 48# 49# Also note that rimage is picky with section flags: it will try to 50# include a section in the output data (even its own metadata in 51# .module!) if it has any of ALLOC, WRITABLE or EXEC flags in the ELF 52# file. The GNU linker will set these automatically based on the 53# flags of the sections coming out of C code, so this is fragile and 54# breaks easily. Set noload flags explicitly here. 55add_custom_target( 56 gen_modules ALL 57 DEPENDS ${CMAKE_BINARY_DIR}/zephyr/boot.mod ${CMAKE_BINARY_DIR}/zephyr/main.mod 58) 59 60add_custom_command( 61 OUTPUT ${CMAKE_BINARY_DIR}/zephyr/boot.mod ${CMAKE_BINARY_DIR}/zephyr/main.mod 62 COMMENT "Extracting .mod(ule) files for rimage" 63 DEPENDS ${ZEPHYR_FINAL_EXECUTABLE} ${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME} 64 65 # The .fw_metadata section may not be present (xcc's older linker 66 # will remove it if empty). Extract it here (which will create an 67 # empty file if not present) and add it back when we generate the 68 # main.mod file below. 69 COMMAND ${CMAKE_OBJCOPY} -O binary --only-section=.fw_metadata 70 ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}.elf ${EXTMAN} 71 72 # Remap uncached section addresses so they appear contiguous 73 COMMAND ${CMAKE_COMMAND} -E 74 copy ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}.elf ${KERNEL_REMAPPED} 75 76 # Extract modules for rimage 77 COMMAND ${CMAKE_OBJCOPY} 78 --only-section .imr 79 --only-section .imrdata 80 --only-section .module.boot 81 --set-section-flags .module.boot=noload,readonly 82 --rename-section .module.boot=.module 83 ${KERNEL_REMAPPED} ${CMAKE_BINARY_DIR}/zephyr/boot.mod 2>${NULL_FILE} 84 85 COMMAND ${CMAKE_OBJCOPY} 86 --only-section .cold 87 --only-section .coldrodata 88 --only-section .module.cold 89 --set-section-flags .module.cold=noload,readonly 90 --rename-section .module.cold=.module 91 ${KERNEL_REMAPPED} ${CMAKE_BINARY_DIR}/zephyr/cold.mod 2>${NULL_FILE} 92 93 # Remove .fw_metadata here... 94 COMMAND ${CMAKE_OBJCOPY} 95 --remove-section .imr 96 --remove-section .imrdata 97 --remove-section .cold 98 --remove-section .coldrodata 99 --remove-section .module.boot 100 --remove-section .module.cold 101 --remove-section .fw_metadata 102 --set-section-flags .module.main=noload,readonly 103 --set-section-flags .static_uuid_entries=noload,readonly 104 --set-section-flags .static_log_entries=noload,readonly 105 --rename-section .module.main=.module 106 ${KERNEL_REMAPPED} ${CMAKE_BINARY_DIR}/zephyr/main.mod 2>${NULL_FILE} 107 108 # ...and copy it back in 109 COMMAND ${CMAKE_OBJCOPY} 110 --add-section .fw_metadata=${EXTMAN} 111 --set-section-flags .fw_metadata=noload,readonly 112 ${CMAKE_BINARY_DIR}/zephyr/main.mod 113 ${CMAKE_BINARY_DIR}/zephyr/main.mod 2>${NULL_FILE} 114) 115 116if(CONFIG_BUILD_OUTPUT_STRIPPED) 117add_custom_command( 118 COMMENT "strip main.mod" 119 APPEND OUTPUT ${CMAKE_BINARY_DIR}/zephyr/main.mod 120 COMMAND $<TARGET_PROPERTY:bintools,strip_command> 121 $<TARGET_PROPERTY:bintools,strip_flag> 122 $<TARGET_PROPERTY:bintools,strip_flag_all> 123 $<TARGET_PROPERTY:bintools,strip_flag_infile>${CMAKE_BINARY_DIR}/zephyr/main.mod 124 $<TARGET_PROPERTY:bintools,strip_flag_outfile>${CMAKE_BINARY_DIR}/zephyr/main-stripped.mod 125 $<TARGET_PROPERTY:bintools,strip_flag_final> 126) 127endif() 128 129 130# west sign 131add_custom_target(zephyr.ri ALL 132 DEPENDS ${CMAKE_BINARY_DIR}/zephyr/zephyr.ri 133) 134 135# If some of your board(s) need to override default rimage parameters 136# then you can define WEST_SIGN_OPTS in boards/my/board/board.cmake. 137# Example: 138# 139# set(WEST_SIGN_OPTS -- -c "/home/sweet home/rimage/config/abc.toml" -i 4) 140 141# Parameters after the double dash -- are passed through to rimage. For 142# other ways to override default rimage parameters check 143# boards/intel/adsp/doc/intel_adsp_generic.rst 144 145# Warning: because `west sign` can also be used interactively, using 146# ${WEST_SIGN_OPTS} like this has _higher_ precedence than `west config 147# rimage.extra-args`! Avoid overriding default rimage parameters in 148# multiple places to avoid unexpected precedence rules. 149add_custom_command( 150 OUTPUT ${CMAKE_BINARY_DIR}/zephyr/zephyr.ri 151 COMMENT "west sign --if-tool-available --tool rimage ..." 152 # Use --if-tool-available so we don't force every CI to install 153 # rimage. We don't want to break build-only and other tests that don't 154 # require signing. When rimage is missing, `west flash` fails with a 155 # clear "zephyr.ri missing" error with an "rimage not found" warning 156 # from west sign immediately before it. 157 COMMAND west sign --if-tool-available --tool rimage --build-dir ${CMAKE_BINARY_DIR} ${WEST_SIGN_OPTS} 158 DEPENDS gen_modules 159 ${CMAKE_BINARY_DIR}/zephyr/boot.mod ${CMAKE_BINARY_DIR}/zephyr/main.mod 160) 161