Skip to content

Commit a168454

Browse files
carlocaionegalak
authored andcommitted
samples: reserved_memory: Introduce sample application
Introduce sample application to test reserved-memory helpers. Signed-off-by: Carlo Caione <ccaione@baylibre.com>
1 parent ae2be2d commit a168454

File tree

7 files changed

+126
-0
lines changed

7 files changed

+126
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(reserved_memory)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
reserved-memory {
9+
compatible = "reserved-memory";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
status = "okay";
13+
ranges;
14+
15+
res0: res0@42000000 {
16+
reg = <0x42000000 0x1000>;
17+
label = "res0";
18+
};
19+
20+
res1: res1@43000000 {
21+
reg = <0x43000000 0x2000>;
22+
compatible = "sample_driver";
23+
label = "res1";
24+
};
25+
};
26+
27+
28+
sample_driver_outer: sample_driver {
29+
compatible = "sample_driver";
30+
label = "sample_driver_outer";
31+
memory-region = <&res0>;
32+
};
33+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: Sample Driver
2+
3+
compatible: "sample_driver"
4+
5+
include:
6+
- name: base.yaml
7+
property-allowlist: ['reg', 'label']
8+
9+
properties:
10+
memory-region:
11+
type: phandle
12+
required: false
13+
description: phandle to the reserved memory child node
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Carlo Caione <ccaione@baylibre.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <autoconf.h>
8+
#include <linker/sections.h>
9+
#include <devicetree.h>
10+
11+
#include <linker/linker-defs.h>
12+
#include <linker/linker-tool.h>
13+
14+
MEMORY
15+
{
16+
DT_RESERVED_MEM_REGIONS()
17+
}
18+
19+
SECTIONS
20+
{
21+
DT_RESERVED_MEM_SECTIONS()
22+
}
23+
24+
#include <arch/arm64/scripts/linker.ld>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
2+
CONFIG_CUSTOM_LINKER_SCRIPT="linker_arm64_reserved.ld"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sample:
2+
description: Reserved memory sample application
3+
name: reserved memory
4+
tests:
5+
sample.board.qemu_cortex_a53.reserved_memory:
6+
platform_allow: qemu_cortex_a53
7+
tags: sample board reserved_memory
8+
build_only: true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <devicetree/memory.h>
9+
#include <linker/linker-defs.h>
10+
11+
/* Variables placed in reserved sections */
12+
uint32_t var_in_res0 __attribute((__section__(".res0"))) = 0xaabbccdd;
13+
uint32_t var_in_res1 __attribute((__section__(".res1"))) = 0xddccbbaa;
14+
15+
void main(void)
16+
{
17+
uint8_t *res_ptr_outer, *res_ptr_inner;
18+
uint32_t res_size_outer, res_size_inner;
19+
20+
res_ptr_outer =
21+
DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
22+
memory_region);
23+
res_size_outer =
24+
DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
25+
memory_region);
26+
27+
printk("Reserved memory address for the outer driver: %p\n", res_ptr_outer);
28+
printk("Reserved memory size for the outer driver: %d\n", res_size_outer);
29+
30+
res_ptr_inner = DT_RESERVED_MEM_GET_PTR(DT_NODELABEL(res1));
31+
res_size_inner = DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(res1));
32+
33+
printk("Reserved memory address for the inner driver: %p\n", res_ptr_inner);
34+
printk("Reserved memory size for the inner driver: %d\n", res_size_inner);
35+
36+
printk("Address of var_in_res0: %p\n", &var_in_res0);
37+
printk("Address of var_in_res1: %p\n", &var_in_res1);
38+
}

0 commit comments

Comments
 (0)