Skip to content

Commit bae0a5b

Browse files
galakcarlescufi
authored andcommitted
logging: Use TYPE_SECTION macros for log const
Clean up log_const to utilize macros for handling sections. Update database_gen.py to match naming convention change. Signed-off-by: Kumar Gala <kumar.gala@intel.com>
1 parent f5eada5 commit bae0a5b

File tree

9 files changed

+26
-30
lines changed

9 files changed

+26
-30
lines changed

cmake/linker_script/common/common-rom.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ endif()
166166

167167
zephyr_iterable_section(NAME log_strings KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
168168

169-
zephyr_linker_section(NAME log_const KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT})
170-
zephyr_linker_section_configure(SECTION log_const INPUT ".log_const_*" KEEP SORT NAME)
169+
zephyr_iterable_section(NAME log_const KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
171170

172171
zephyr_iterable_section(NAME shell KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4)
173172

include/zephyr/linker/common-rom/common-rom-logging.ld

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
ITERABLE_SECTION_ROM(log_strings, 4)
44

5-
SECTION_DATA_PROLOGUE(log_const_sections,,)
6-
{
7-
__log_const_start = .;
8-
KEEP(*(SORT(.log_const_*)));
9-
__log_const_end = .;
10-
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
5+
ITERABLE_SECTION_ROM(log_const, 4)
116

127
ITERABLE_SECTION_ROM(log_backend, 4)
138

include/zephyr/logging/log.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ void z_log_vprintk(const char *fmt, va_list ap);
298298

299299
#define _LOG_MODULE_CONST_DATA_CREATE(_name, _level) \
300300
IF_ENABLED(LOG_IN_CPLUSPLUS, (extern)) \
301-
const struct log_source_const_data Z_LOG_ITEM_CONST_DATA(_name) \
302-
__attribute__ ((section("." STRINGIFY(Z_LOG_ITEM_CONST_DATA(_name))))) \
303-
__attribute__((used)) = { \
301+
const STRUCT_SECTION_ITERABLE_ALTERNATE(log_const, \
302+
log_source_const_data, \
303+
Z_LOG_ITEM_CONST_DATA(_name)) = \
304+
{ \
304305
.name = STRINGIFY(_name), \
305306
.level = _level \
306307
}

include/zephyr/logging/log_core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ static inline char z_log_minimal_level_to_char(int level)
389389
*/
390390
#define LOG_LEVEL_INTERNAL_RAW_STRING LOG_LEVEL_NONE
391391

392-
extern struct log_source_const_data __log_const_start[];
393-
extern struct log_source_const_data __log_const_end[];
392+
TYPE_SECTION_START_EXTERN(struct log_source_const_data, log_const);
393+
TYPE_SECTION_END_EXTERN(struct log_source_const_data, log_const);
394394

395395
/** @brief Create message for logging printk-like string or a raw string.
396396
*
@@ -429,7 +429,7 @@ extern struct log_source_const_data __log_const_end[];
429429
static inline uint32_t log_const_source_id(
430430
const struct log_source_const_data *data)
431431
{
432-
return ((const uint8_t *)data - (uint8_t *)__log_const_start)/
432+
return ((const uint8_t *)data - (uint8_t *)TYPE_SECTION_START(log_const))/
433433
sizeof(struct log_source_const_data);
434434
}
435435

include/zephyr/logging/log_instance.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ struct log_source_dynamic_data {
6161
* @param _level Messages up to this level are compiled in.
6262
*/
6363
#define Z_LOG_CONST_ITEM_REGISTER(_name, _str_name, _level) \
64-
const struct log_source_const_data Z_LOG_ITEM_CONST_DATA(_name) \
65-
__attribute__ ((section("." STRINGIFY(Z_LOG_ITEM_CONST_DATA(_name))))) \
66-
__attribute__((used)) = { \
64+
const STRUCT_SECTION_ITERABLE_ALTERNATE(log_const, \
65+
log_source_const_data, \
66+
Z_LOG_ITEM_CONST_DATA(_name)) = \
67+
{ \
6768
.name = _str_name, \
6869
.level = (_level), \
6970
}

include/zephyr/logging/log_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static inline uint32_t *z_log_dynamic_filters_get(uint32_t source_id)
9292
/** @brief Get number of registered sources. */
9393
static inline uint32_t z_log_sources_count(void)
9494
{
95-
return log_const_source_id(__log_const_end);
95+
return log_const_source_id(TYPE_SECTION_END(log_const));
9696
}
9797

9898
/** @brief Return number of external domains.

scripts/logging/dictionary/database_gen.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def find_log_const_symbols(elf):
167167
return ret_list
168168

169169

170-
def parse_log_const_symbols(database, log_const_section, log_const_symbols, string_mappings):
170+
def parse_log_const_symbols(database, log_const_area, log_const_symbols, string_mappings):
171171
"""Find the log instances and map source IDs to names"""
172172
if database.is_tgt_little_endian():
173173
formatter = "<"
@@ -192,17 +192,17 @@ def parse_log_const_symbols(database, log_const_section, log_const_symbols, stri
192192
if sym.entry['st_value'] < first_offset:
193193
first_offset = sym.entry['st_value']
194194

195-
first_offset -= log_const_section['start']
195+
first_offset -= log_const_area['start']
196196

197197
# find all log_const_*
198198
for sym in log_const_symbols:
199-
# Find data offset in log_const_section for this symbol
200-
offset = sym.entry['st_value'] - log_const_section['start']
199+
# Find data offset in log_const_area for this symbol
200+
offset = sym.entry['st_value'] - log_const_area['start']
201201

202202
idx_s = offset
203203
idx_e = offset + datum_size
204204

205-
datum = log_const_section['data'][idx_s:idx_e]
205+
datum = log_const_area['data'][idx_s:idx_e]
206206

207207
if len(datum) != datum_size:
208208
# Not enough data to unpack
@@ -266,13 +266,13 @@ def extract_logging_subsys_information(elf, database, string_mappings):
266266
mapping from source ID to name.
267267
"""
268268
# Extract log constant section for module names
269-
section_log_const = find_elf_sections(elf, "log_const_sections")
269+
section_log_const = find_elf_sections(elf, "log_const_area")
270270
if section_log_const is None:
271-
# ESP32 puts "log_const_*" info log_static_section instead of log_const_sections
271+
# ESP32 puts "log_const_*" info log_static_section instead of log_const_areas
272272
section_log_const = find_elf_sections(elf, "log_static_section")
273273

274274
if section_log_const is None:
275-
logger.error("Cannot find section 'log_const_sections' in ELF file, exiting...")
275+
logger.error("Cannot find section 'log_const_areas' in ELF file, exiting...")
276276
sys.exit(1)
277277

278278
# Find all "log_const_*" symbols and parse them

subsys/logging/log_mgmt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static uint16_t link_source_count(uint8_t domain_id)
196196
uint32_t log_src_cnt_get(uint32_t domain_id)
197197
{
198198
if (z_log_is_local_domain(domain_id)) {
199-
return log_const_source_id(__log_const_end);
199+
return z_log_sources_count();
200200
}
201201

202202
return link_source_count(domain_id);
@@ -242,7 +242,7 @@ const char *log_source_name_get(uint32_t domain_id, uint32_t source_id)
242242
{
243243
if (z_log_is_local_domain(domain_id)) {
244244
if (source_id < log_src_cnt_get(domain_id)) {
245-
return __log_const_start[source_id].name;
245+
return TYPE_SECTION_START(log_const)[source_id].name;
246246
} else {
247247
return NULL;
248248
}
@@ -308,7 +308,7 @@ uint8_t log_compiled_level_get(uint8_t domain_id, uint32_t source_id)
308308
{
309309
if (z_log_is_local_domain(domain_id)) {
310310
if (source_id < log_src_cnt_get(domain_id)) {
311-
return __log_const_start[source_id].level;
311+
return TYPE_SECTION_START(log_const)[source_id].level;
312312
} else {
313313
return LOG_LEVEL_NONE;
314314
}

tests/subsys/logging/log_links/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ZTEST(log_links, test_log_domain_count)
131131
ZTEST(log_links, test_log_source_count)
132132
{
133133
uint8_t exp_source_cnt[] = {
134-
log_const_source_id(__log_const_end),
134+
log_const_source_id(TYPE_SECTION_END(log_const)),
135135
/*link1*/
136136
domains_a[0]->source_cnt,
137137
domains_a[1]->source_cnt,

0 commit comments

Comments
 (0)