app_shmem: overhaul partition specification
* K_APP_DMEM_SECTION/K_MEM_BMEM_SECTION macros now exist
to specifically define the name of the sections for data
and bss respectively.
* All boards now use the gen_app_partitions.py script, the
padding hacks for non-power-of-two arches didn't work right
in all cases. Linker scripts have been updated.
* The defined k_mem_partition is now completely initialized
at build time. The region data structures now only exist
to zero BSS.
Based on some work submitted by Adithya Baglody
<adithya.baglody@intel.com>
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/scripts/gen_app_partitions.py b/scripts/gen_app_partitions.py
index b8b407c..6efc0fd 100644
--- a/scripts/gen_app_partitions.py
+++ b/scripts/gen_app_partitions.py
@@ -13,15 +13,20 @@
from elftools.elf.elffile import ELFFile
-# This script will create linker comands for power of two aligned MPU
-# when APP_SHARED_MEM is enabled.
+# This script will create sections and linker variables to place the
+# application shared memory partitions.
+# these are later read by the macros defined in app_memdomain.h for
+# initialization purpose when APP_SHARED_MEM is enabled.
print_template = """
/* Auto generated code do not modify */
- MPU_ALIGN(data_smem_{0}b_end - data_smem_{0});
- data_smem_{0} = .;
- KEEP(*(SORT(data_smem_{0}*)))
- MPU_ALIGN(data_smem_{0}b_end - data_smem_{0});
- data_smem_{0}b_end = .;
+ SMEM_PARTITION_ALIGN(data_smem_{0}_bss_end - data_smem_{0}_start);
+ data_smem_{0}_start = .;
+ KEEP(*(data_smem_{0}_data))
+ data_smem_{0}_bss_start = .;
+ KEEP(*(data_smem_{0}_bss))
+ SMEM_PARTITION_ALIGN(data_smem_{0}_bss_end - data_smem_{0}_start);
+ data_smem_{0}_bss_end = .;
+ data_smem_{0}_end = .;
"""
linker_start_seq = """
SECTION_PROLOGUE(_APP_SMEM_SECTION_NAME, (OPTIONAL),)
@@ -31,15 +36,17 @@
"""
linker_end_seq = """
- _app_smem_end = .;
APP_SHARED_ALIGN;
+ _app_smem_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
"""
size_cal_string = """
- data_smem_{0}_size = data_smem_{0}b_end - data_smem_{0};
+ data_smem_{0}_size = data_smem_{0}_end - data_smem_{0}_start;
+ data_smem_{0}_bss_size = data_smem_{0}_bss_end - data_smem_{0}_bss_start;
"""
+section_regex = re.compile(r'data_smem_([A-Za-z0-9_]*)_(data|bss)')
def find_partitions(filename, full_list_of_partitions, partitions_source_file):
with open(filename, 'rb') as f:
@@ -48,22 +55,19 @@
print("Error parsing file: ",filename)
os.exit(1)
- sections = [ x for x in full_lib.iter_sections()]
+ sections = [x for x in full_lib.iter_sections()]
for section in sections:
- if ("smem" in section.name and not ".rel" in section.name):
- partition_name = section.name.split("data_smem_")[1]
- if partition_name not in full_list_of_partitions:
- full_list_of_partitions.append(partition_name)
- if args.verbose:
- partitions_source_file.update({partition_name: filename})
+ m = section_regex.match(section.name)
+ if not m:
+ continue
+
+ partition_name = m.groups()[0]
+ if partition_name not in full_list_of_partitions:
+ full_list_of_partitions.append(partition_name)
+ if args.verbose:
+ partitions_source_file.update({partition_name: filename})
- return( full_list_of_partitions, partitions_source_file)
-
-def cleanup_remove_bss_regions(full_list_of_partitions):
- for partition in full_list_of_partitions:
- if (partition+"b" in full_list_of_partitions):
- full_list_of_partitions.remove(partition+"b")
- return full_list_of_partitions
+ return (full_list_of_partitions, partitions_source_file)
def generate_final_linker(linker_file, full_list_of_partitions):
string = linker_start_seq
@@ -105,11 +109,11 @@
fullname = os.path.join(dirpath, filename)
full_list_of_partitions, partitions_source_file = find_partitions(fullname, full_list_of_partitions, partitions_source_file)
- full_list_of_partitions = cleanup_remove_bss_regions(full_list_of_partitions)
generate_final_linker(linker_file, full_list_of_partitions)
if args.verbose:
- print("Partitions retrieved: PARTITION, FILENAME")
- print([key + " "+ partitions_source_file[key] for key in full_list_of_partitions])
+ print("Partitions retrieved:")
+ for key in full_list_of_partitions:
+ print(" %s: %s\n", key, partitions_source_file[key])
if __name__ == '__main__':
main()