diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ca970408e..3304d94fdf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1697,7 +1697,7 @@ list(APPEND ) if(CONFIG_LOG_DICTIONARY_SUPPORT) - set(LOG_DICT_DB_NAME ${PROJECT_BINARY_DIR}/log_dictionary.json) + set(log_dict_db_output --json=${PROJECT_BINARY_DIR}/log_dictionary.json) list(APPEND post_build_commands @@ -1705,13 +1705,15 @@ if(CONFIG_LOG_DICTIONARY_SUPPORT) ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py ${KERNEL_ELF_NAME} - ${LOG_DICT_DB_NAME} + ${log_dict_db_output} --build-header ${PROJECT_BINARY_DIR}/include/generated/version.h ) list(APPEND post_build_byproducts ${LOG_DICT_DB_NAME} ) + + unset(log_dict_db_output) endif() # Add post_build_commands to post-process the final .elf file produced by diff --git a/scripts/logging/dictionary/database_gen.py b/scripts/logging/dictionary/database_gen.py index c1fdd01a9fa..618974fd61a 100755 --- a/scripts/logging/dictionary/database_gen.py +++ b/scripts/logging/dictionary/database_gen.py @@ -76,7 +76,6 @@ def parse_args(): argparser = argparse.ArgumentParser() argparser.add_argument("elffile", help="Zephyr ELF binary") - argparser.add_argument("dbfile", help="Dictionary Logging Database file") argparser.add_argument("--build", help="Build ID") argparser.add_argument("--build-header", help="Header file containing BUILD_VERSION define") @@ -85,6 +84,10 @@ def parse_args(): argparser.add_argument("-v", "--verbose", action="store_true", help="Print more information") + outfile_grp = argparser.add_mutually_exclusive_group(required=True) + outfile_grp.add_argument("--json", + help="Output Dictionary Logging Database file in JSON") + return argparser.parse_args() @@ -521,7 +524,12 @@ def main(): sys.exit(1) logger.info("ELF file %s", args.elffile) - logger.info("Database file %s", args.dbfile) + + if args.json: + logger.info("JSON Database file %s", args.json) + else: + logger.error("Need to specify output file.") + sys.exit(1) elf = ELFFile(elffile) @@ -560,9 +568,11 @@ def main(): extract_logging_subsys_information(elf, database) # Write database file - if not LogDatabase.write_json_database(args.dbfile, database): - logger.error("ERROR: Cannot open database file for write: %s, exiting...", args.dbfile) - sys.exit(1) + if args.json: + if not LogDatabase.write_json_database(args.json, database): + logger.error("ERROR: Cannot open database file for write: %s, exiting...", + args.json) + sys.exit(1) elffile.close()