diff --git a/scripts/cmake/version.cmake b/scripts/cmake/version.cmake index 0223d4982987..f806845eaded 100644 --- a/scripts/cmake/version.cmake +++ b/scripts/cmake/version.cmake @@ -59,6 +59,34 @@ if(NOT SOF_TAG) set(SOF_TAG 0) endif() +# Calculate source hash value, used to check ldc file and firmware compatibility +if(EXISTS ${CMAKE_SOURCE_DIR}/.git/) + # list tracked files from src directory + execute_process(COMMAND git ls-files src + WORKING_DIRECTORY ${SOF_ROOT_SOURCE_DIRECTORY} + OUTPUT_FILE tracked_file_list + ) + # calculate hash of each listed files (from file version saved in file system) + execute_process(COMMAND git hash-object --stdin-paths + WORKING_DIRECTORY ${SOF_ROOT_SOURCE_DIRECTORY} + INPUT_FILE tracked_file_list + OUTPUT_FILE tracked_file_hash_list + ) + # then calculate single hash of previously calculated hash list + execute_process(COMMAND git hash-object --stdin + WORKING_DIRECTORY ${SOF_ROOT_SOURCE_DIRECTORY} + OUTPUT_STRIP_TRAILING_WHITESPACE + INPUT_FILE tracked_file_hash_list + OUTPUT_VARIABLE SOF_SRC_HASH_LONG + ) + file(REMOVE tracked_file_list tracked_file_hash_list) + string(SUBSTRING ${SOF_SRC_HASH_LONG} 0 8 SOF_SRC_HASH) + message(STATUS "Source content hash: ${SOF_SRC_HASH}") +else() + set(SOF_SRC_HASH ${GIT_LOG_HASH}) + message(WARNING "Source content hash can't be calculated, use GIT_LOG_HASH") +endif() + # for SOF_BUILD include(${CMAKE_CURRENT_LIST_DIR}/version-build-counter.cmake) @@ -69,6 +97,8 @@ function(sof_check_version_h) "#define SOF_MICRO ${SOF_MICRO}\n" "#define SOF_TAG \"${SOF_TAG}\"\n" "#define SOF_BUILD ${SOF_BUILD}\n" + "#define SOF_GIT_TAG \"${GIT_TAG}\"\n" + "#define SOF_SRC_HASH 0x${SOF_SRC_HASH}\n" ) if(EXISTS "${VERSION_H_PATH}") diff --git a/src/include/ipc/info.h b/src/include/ipc/info.h index 52e5ee78bd27..3f628b174467 100644 --- a/src/include/ipc/info.h +++ b/src/include/ipc/info.h @@ -54,9 +54,11 @@ struct sof_ipc_fw_version { uint8_t time[10]; uint8_t tag[6]; uint32_t abi_version; + /* used to check FW and ldc file compatibility, reproducible value */ + uint32_t src_hash; /* reserved for future use */ - uint32_t reserved[4]; + uint32_t reserved[3]; } __attribute__((packed)); /* FW ready Message - sent by firmware when boot has completed */ diff --git a/src/include/user/abi_dbg.h b/src/include/user/abi_dbg.h index 8ea8ef37da2f..16bf77fa9c92 100644 --- a/src/include/user/abi_dbg.h +++ b/src/include/user/abi_dbg.h @@ -19,7 +19,7 @@ #define __USER_ABI_DBG_H__ #define SOF_ABI_DBG_MAJOR 5 -#define SOF_ABI_DBG_MINOR 0 +#define SOF_ABI_DBG_MINOR 1 #define SOF_ABI_DBG_PATCH 0 #define SOF_ABI_DBG_VERSION SOF_ABI_VER(SOF_ABI_DBG_MAJOR, \ diff --git a/src/init/ext_manifest.c b/src/init/ext_manifest.c index d209752977ab..985cbfbfad47 100644 --- a/src/init/ext_manifest.c +++ b/src/init/ext_manifest.c @@ -32,6 +32,7 @@ const struct ext_man_fw_version ext_man_fw_ver #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS, }; diff --git a/src/platform/baytrail/platform.c b/src/platform/baytrail/platform.c index 63c9e02fef44..3195f47bea75 100644 --- a/src/platform/baytrail/platform.c +++ b/src/platform/baytrail/platform.c @@ -72,6 +72,7 @@ static const struct sof_ipc_fw_ready ready #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS }; diff --git a/src/platform/haswell/platform.c b/src/platform/haswell/platform.c index dca7a66ca9ca..5762e4f9d10a 100644 --- a/src/platform/haswell/platform.c +++ b/src/platform/haswell/platform.c @@ -58,6 +58,7 @@ static const struct sof_ipc_fw_ready ready #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS, }; diff --git a/src/platform/imx8/platform.c b/src/platform/imx8/platform.c index 6710241af565..be6801a43a1a 100644 --- a/src/platform/imx8/platform.c +++ b/src/platform/imx8/platform.c @@ -57,6 +57,7 @@ static const struct sof_ipc_fw_ready ready #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS, }; diff --git a/src/platform/imx8m/platform.c b/src/platform/imx8m/platform.c index f415fdb16964..92383495698f 100644 --- a/src/platform/imx8m/platform.c +++ b/src/platform/imx8m/platform.c @@ -56,6 +56,7 @@ static const struct sof_ipc_fw_ready ready #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS, }; diff --git a/src/platform/intel/cavs/platform.c b/src/platform/intel/cavs/platform.c index 14afc8b3ff51..ba46cbad2eb6 100644 --- a/src/platform/intel/cavs/platform.c +++ b/src/platform/intel/cavs/platform.c @@ -68,6 +68,7 @@ static const struct sof_ipc_fw_ready ready #endif .tag = SOF_TAG, .abi_version = SOF_ABI_VERSION, + .src_hash = SOF_SRC_HASH, }, .flags = DEBUG_SET_FW_READY_FLAGS, }; diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index e3a9fbe07ba4..ec6e5cfd7268 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include #include @@ -335,6 +338,11 @@ int dma_trace_enable(struct dma_trace_data *d) d->enabled = 1; schedule_task(&d->dmat_work, DMA_TRACE_PERIOD, DMA_TRACE_PERIOD); + /* it should be the very first sent log for easily identification */ + tr_info(&dt_tr, "FW ABI 0x%x DBG ABI 0x%x tag " SOF_GIT_TAG " src hash 0x%x (ldc hash " META_QUOTE(SOF_SRC_HASH) ")", + SOF_ABI_VERSION, SOF_ABI_DBG_VERSION, SOF_SRC_HASH); + trace_flush(); + out: platform_shared_commit(d, sizeof(*d)); diff --git a/tools/logger/convert.c b/tools/logger/convert.c index 1f26e44112df..2fe837a0da4e 100644 --- a/tools/logger/convert.c +++ b/tools/logger/convert.c @@ -660,7 +660,7 @@ static int verify_fw_ver(const struct convert_config *config, const struct snd_sof_logs_header *snd) { struct sof_ipc_fw_version ver; - int count, ret = 0; + int count; if (!config->version_fd) return 0; @@ -673,30 +673,11 @@ static int verify_fw_ver(const struct convert_config *config, return -ferror(config->version_fd); } - ret = memcmp(&ver, &snd->version, sizeof(struct sof_ipc_fw_version)); - if (ret) { - log_err(config->out_fd, - "fw version in %s file does not coincide with fw version in %s file.\n", - config->ldc_file, config->version_file); - return -EINVAL; - } - - /* logger and version_file abi dbg verification */ - if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_DBG_VERSION, - ver.abi_version)) { - log_err(config->out_fd, - "abi version in %s file does not coincide with abi version used by logger.\n", - config->version_file); - log_err(config->out_fd, - "logger ABI Version is %d:%d:%d\n", - SOF_ABI_VERSION_MAJOR(SOF_ABI_DBG_VERSION), - SOF_ABI_VERSION_MINOR(SOF_ABI_DBG_VERSION), - SOF_ABI_VERSION_PATCH(SOF_ABI_DBG_VERSION)); + /* compare source hash value from version file and ldc file */ + if (ver.src_hash != snd->version.src_hash) { log_err(config->out_fd, - "version_file ABI Version is %d:%d:%d\n", - SOF_ABI_VERSION_MAJOR(ver.abi_version), - SOF_ABI_VERSION_MINOR(ver.abi_version), - SOF_ABI_VERSION_PATCH(ver.abi_version)); + "src hash value from version file (0x%x) differ from src hash version saved in dictionary (0x%x).\n", + ver.src_hash, snd->version.src_hash); return -EINVAL; } return 0;