-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: memory regions from devicetree & explicit code locations #33656
Changes from all commits
52b5311
cdfea7c
0279ba0
ba76b22
9f999e0
8ea65e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&flash0 { | ||
partitions { | ||
boot_partition: partition@0 { | ||
label = "mcuboot"; | ||
reg = <0x000000000 0x0000C000>; | ||
}; | ||
slot0_partition: partition@c000 { | ||
label = "image-0"; | ||
reg = <0x0000C000 0x00067000>; | ||
}; | ||
slot1_partition: partition@73000 { | ||
label = "image-1"; | ||
reg = <0x00073000 0x00067000>; | ||
}; | ||
scratch_partition: partition@da000 { | ||
label = "image-scratch"; | ||
reg = <0x000da000 0x0001e000>; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <mcuboot_partitions.dtsi> | ||
|
||
/ { | ||
chosen { | ||
zephyr,code-partition = &boot_partition; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
chosen { | ||
zephyr,code-partition = &code_partition; | ||
}; | ||
}; | ||
|
||
&flash0 { | ||
|
||
partitions { | ||
code_partition: partition@0 { | ||
label = "code"; | ||
reg = <0x000000000 0x000f8000>; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_BOOTLOADER_MCUBOOT=y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <mcuboot_partitions.dtsi> | ||
|
||
/ { | ||
chosen { | ||
zephyr,code-partition = &slot0_partition; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -13,14 +13,15 @@ | |||
|
||||
#include <autoconf.h> | ||||
#include <linker/sections.h> | ||||
#include <linker/devicetree_regions.h> | ||||
#include <devicetree.h> | ||||
|
||||
#include <linker/linker-defs.h> | ||||
#include <linker/linker-tool.h> | ||||
|
||||
/* physical address of RAM */ | ||||
#ifdef CONFIG_XIP | ||||
#define ROMABLE_REGION FLASH | ||||
#define ROMABLE_REGION DT_CODE_PARITION() | ||||
#define RAMABLE_REGION SRAM | ||||
#else | ||||
#define ROMABLE_REGION SRAM | ||||
|
@@ -33,25 +34,6 @@ | |||
#define _DATA_IN_ROM | ||||
#endif | ||||
|
||||
#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0) | ||||
#define ROM_ADDR RAM_ADDR | ||||
#else | ||||
#define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET) | ||||
#endif | ||||
|
||||
#ifdef CONFIG_HAS_TI_CCFG | ||||
#define CCFG_SIZE 88 | ||||
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET - \ | ||||
CCFG_SIZE) | ||||
#define CCFG_ADDR (ROM_ADDR + ROM_SIZE) | ||||
#else | ||||
#if CONFIG_FLASH_LOAD_SIZE > 0 | ||||
#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE | ||||
#else | ||||
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET) | ||||
#endif | ||||
#endif | ||||
|
||||
#if defined(CONFIG_XIP) | ||||
#if defined(CONFIG_IS_BOOTLOADER) | ||||
#define RAM_SIZE (CONFIG_BOOTLOADER_SRAM_SIZE * 1K) | ||||
|
@@ -66,21 +48,6 @@ | |||
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS | ||||
#endif | ||||
|
||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) | ||||
#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm)) | ||||
#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm)) | ||||
#endif | ||||
|
||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) | ||||
#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm)) | ||||
#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm)) | ||||
#endif | ||||
|
||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) | ||||
#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm)) | ||||
#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm)) | ||||
#endif | ||||
|
||||
#if defined(CONFIG_CUSTOM_SECTION_ALIGN) | ||||
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE; | ||||
#else | ||||
|
@@ -106,37 +73,28 @@ _region_min_align = 4; | |||
|
||||
MEMORY | ||||
{ | ||||
FLASH (rx) : ORIGIN = ROM_ADDR, LENGTH = ROM_SIZE | ||||
#ifdef CONFIG_HAS_TI_CCFG | ||||
FLASH_CCFG (rwx): ORIGIN = CCFG_ADDR, LENGTH = CCFG_SIZE | ||||
#endif | ||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) | ||||
CCM (rw) : ORIGIN = CCM_ADDR, LENGTH = CCM_SIZE | ||||
#endif | ||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) | ||||
ITCM (rw) : ORIGIN = ITCM_ADDR, LENGTH = ITCM_SIZE | ||||
#endif | ||||
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) | ||||
DTCM (rw) : ORIGIN = DTCM_ADDR, LENGTH = DTCM_SIZE | ||||
#endif | ||||
SRAM (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE | ||||
#ifdef CONFIG_BT_STM32_IPM | ||||
SRAM1 (rw) : ORIGIN = RAM1_ADDR, LENGTH = RAM1_SIZE | ||||
SRAM2 (rw) : ORIGIN = RAM2_ADDR, LENGTH = RAM2_SIZE | ||||
#endif | ||||
#ifdef CONFIG_MEMC_STM32_SDRAM | ||||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay) | ||||
SDRAM1 (rw) : ORIGIN = DT_REG_ADDR(DT_NODELABEL(sdram1)), LENGTH = DT_REG_SIZE(DT_NODELABEL(sdram1)) | ||||
#endif | ||||
#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay) | ||||
SDRAM2 (rw) : ORIGIN = DT_REG_ADDR(DT_NODELABEL(sdram2)), LENGTH = DT_REG_SIZE(DT_NODELABEL(sdram2)) | ||||
#endif | ||||
#endif | ||||
#ifdef CONFIG_STM32_BACKUP_SRAM | ||||
BACKUP_SRAM (rw) : ORIGIN = DT_REG_ADDR(DT_NODELABEL(backup_sram)), LENGTH = DT_REG_SIZE(DT_NODELABEL(backup_sram)) | ||||
#endif | ||||
|
||||
/* Add custom memory regions specified by devicetree partitions */ | ||||
DT_REGIONS_FROM_CHOSEN_FLASH(zephyr_flash) | ||||
|
||||
/* Used by and documented in include/linker/intlist.ld */ | ||||
IDT_LIST (wx) : ORIGIN = (RAM_ADDR + RAM_SIZE), LENGTH = 2K | ||||
|
||||
DT_REGION_FROM_NODE(DT_NODELABEL(sdram1)) | ||||
DT_REGION_FROM_NODE(DT_NODELABEL(sdram2)) | ||||
DT_REGION_FROM_NODE(DT_NODELABEL(backup_sram)) | ||||
|
||||
DT_REGION_FROM_NODE(DT_CHOSEN(zephyr_ccm)) | ||||
DT_REGION_FROM_NODE(DT_CHOSEN(zephyr_itcm)) | ||||
DT_REGION_FROM_NODE(DT_CHOSEN(zephyr_dtcm)) | ||||
} | ||||
|
||||
ENTRY(CONFIG_KERNEL_ENTRY) | ||||
|
@@ -162,7 +120,7 @@ SECTIONS | |||
|
||||
GROUP_START(ROMABLE_REGION) | ||||
|
||||
_image_rom_start = ROM_ADDR; | ||||
_image_rom_start = .; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is changing the value of This means that code that refers to This also results in:
being calculated wrongly. As example, building hello world for
but with this PR:
so any code relying on those two symbols will fail. |
||||
|
||||
SECTION_PROLOGUE(rom_start,,) | ||||
{ | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2021, Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Generate memory regions from devicetree partitions. | ||
* Partitions are only considered if they exist under chosen/zephyr,flash. | ||
*/ | ||
|
||
/* Partitions under chosen/zephyr,flash */ | ||
#define _CHOSEN_PARTITIONS(p) UTIL_CAT(DT_CHOSEN(p), _S_partitions) | ||
|
||
/* Declare a memory region */ | ||
#define _REGION_DECLARE(node) DT_LABEL(node) (rx) : \ | ||
ORIGIN = DT_REG_ADDR(node), \ | ||
LENGTH = DT_REG_SIZE(node) | ||
|
||
/* Apply a macro to a partition list, if it exists */ | ||
#define _FLASH_PARITIONS_APPLY(p, f) \ | ||
COND_CODE_1(DT_NODE_EXISTS(p), (DT_FOREACH_CHILD(p, f)), ()) | ||
|
||
/* Apply a macro to a node, if it is 'okay' */ | ||
#define _OKAY_NODE_APPLY(n, f) \ | ||
COND_CODE_1(DT_NODE_HAS_STATUS(n, okay), (f(n)), ()) | ||
|
||
/* Execution partition */ | ||
#define DT_CODE_PARITION() DT_LABEL(DT_CHOSEN(zephyr_code_partition)) | ||
|
||
/** | ||
* @brief Generate region definitions for all devicetree linker regions | ||
*/ | ||
#define DT_REGIONS_FROM_CHOSEN_FLASH(chosen_flash) \ | ||
_FLASH_PARITIONS_APPLY(_CHOSEN_PARTITIONS(chosen_flash), \ | ||
_REGION_DECLARE) | ||
|
||
/** | ||
* @brief Generate a region definition from an enabled devicetree node | ||
*/ | ||
#define DT_REGION_FROM_NODE(node) \ | ||
COND_CODE_1(DT_NODE_EXISTS(node), \ | ||
(_OKAY_NODE_APPLY(node, _REGION_DECLARE)), \ | ||
()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CCFG_ADDR
is still being used in the code below:causing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be corrected in: #34185
So assume this is now pending a rebase after #34185 is merged.