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>
This commit is contained in:
Andrew Boie 2019-01-30 13:44:54 -08:00 committed by Anas Nashif
commit 7adff462e7
6 changed files with 94 additions and 148 deletions

View file

@ -13,26 +13,26 @@
#error "Not implemented for this architecture"
#endif
/*
* There has got to be a better way of doing this. This
* tries to ensure that a) each subsection has a
* data_smem_#id_b part and b) that each k_mem_partition
* matches the page size or MPU region. If there is no
* data_smem_#id_b subsection, then the size calculations
* will fail. Additionally, if each k_mem_partition does
* not match the page size or MPU region, then the
* partition will fail to be created.
* checkpatch.pl complains that __aligned(size) is
* preferred, but, if implemented, then complains about
* complex macro without parentheses.
*/
#define _app_dmem_pad(id) \
__attribute__((aligned(MEM_DOMAIN_ALIGN_SIZE), \
section("data_smem_" #id)))
#define _app_bmem_pad(id) \
__attribute__((aligned(MEM_DOMAIN_ALIGN_SIZE), \
section("data_smem_" #id "b")))
/**
* @brief Name of the data section for a particular partition
*
* Useful for defining memory pools, or any other macro that takes a
* section name as a parameter.
*
* @param id Partition name
*/
#define K_APP_DMEM_SECTION(id) data_smem_##id##_data
/**
* @brief Name of the bss section for a particular partition
*
* Useful for defining memory pools, or any other macro that takes a
* section name as a parameter.
*
* @param id Partition name
*/
#define K_APP_BMEM_SECTION(id) data_smem_##id##_bss
/**
* @brief Place data in a partition's data section
@ -43,8 +43,7 @@
*
* @param id Name of the memory partition to associate this data
*/
#define K_APP_DMEM(id) \
__attribute__((section("data_smem_" #id)))
#define K_APP_DMEM(id) _GENERIC_SECTION(K_APP_DMEM_SECTION(id))
/**
* @brief Place data in a partition's bss section
@ -54,35 +53,17 @@
*
* @param id Name of the memory partition to associate this data
*/
#define K_APP_BMEM(id) \
__attribute__((section("data_smem_" #id "b")))
#define K_APP_BMEM(id) _GENERIC_SECTION(K_APP_BMEM_SECTION(id))
/*
* Creation of a struct to save start addresses, sizes, and
* a pointer to a k_mem_partition. It also adds a linked
* list node.
*/
struct app_region {
char *dmem_start;
char *bmem_start;
u32_t smem_size;
struct k_mem_partition *partition;
struct z_app_region {
void *bss_start;
size_t bss_size;
};
/*
* Declares a partition and provides a function to add the
* partition to the linked list and initialize the partition.
*/
#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
/* For power of 2 MPUs linker provides support to help us
* calculate the region sizes.
*/
#define smem_size_declare(name) extern char data_smem_##name##_size[]
#define smem_size_val(name) ((u32_t)&data_smem_##name##_size)
#else
#define smem_size_declare(name)
#define smem_size_val(name) 0
#endif /* CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT */
#define Z_APP_START(id) data_smem_##id##_start
#define Z_APP_SIZE(id) data_smem_##id##_size
#define Z_APP_BSS_START(id) data_smem_##id##_bss_start
#define Z_APP_BSS_SIZE(id) data_smem_##id##_bss_size
/**
* @brief Define an application memory partition with linker support
@ -97,21 +78,20 @@ struct app_region {
* @param name Name of the k_mem_partition to declare
*/
#define K_APPMEM_PARTITION_DEFINE(name) \
extern char *data_smem_##name; \
extern char *data_smem_##name##b; \
smem_size_declare(name); \
_app_dmem_pad(name) char name##_dmem_pad; \
_app_bmem_pad(name) char name##_bmem_pad; \
extern char Z_APP_START(name)[]; \
extern char Z_APP_SIZE(name)[]; \
struct k_mem_partition name = { \
.start = (u32_t) &data_smem_##name, \
.start = (u32_t) &Z_APP_START(name), \
.size = (u32_t) &Z_APP_SIZE(name), \
.attr = K_MEM_PARTITION_P_RW_U_RW \
}; \
extern char Z_APP_BSS_START(name)[]; \
extern char Z_APP_BSS_SIZE(name)[]; \
_GENERIC_SECTION(.app_regions.name) \
struct app_region name##_region = { \
.dmem_start = (char *)&data_smem_##name, \
.bmem_start = (char *)&data_smem_##name##b, \
.smem_size = smem_size_val(name), \
.partition = &name \
};
struct z_app_region name##_region = { \
.bss_start = &Z_APP_BSS_START(name), \
.bss_size = (size_t) &Z_APP_BSS_SIZE(name) \
}; \
K_APP_BMEM(name) char name##_placeholder;
#endif /* ZEPHYR_INCLUDE_APP_MEMORY_APP_MEMDOMAIN_H_ */