samples: reserved_memory: Introduce sample application
Introduce sample application to test reserved-memory helpers. Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
parent
ae2be2db8a
commit
a168454814
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(reserved_memory)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/ {
|
||||
reserved-memory {
|
||||
compatible = "reserved-memory";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
status = "okay";
|
||||
ranges;
|
||||
|
||||
res0: res0@42000000 {
|
||||
reg = <0x42000000 0x1000>;
|
||||
label = "res0";
|
||||
};
|
||||
|
||||
res1: res1@43000000 {
|
||||
reg = <0x43000000 0x2000>;
|
||||
compatible = "sample_driver";
|
||||
label = "res1";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
sample_driver_outer: sample_driver {
|
||||
compatible = "sample_driver";
|
||||
label = "sample_driver_outer";
|
||||
memory-region = <&res0>;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
description: Sample Driver
|
||||
|
||||
compatible: "sample_driver"
|
||||
|
||||
include:
|
||||
- name: base.yaml
|
||||
property-allowlist: ['reg', 'label']
|
||||
|
||||
properties:
|
||||
memory-region:
|
||||
type: phandle
|
||||
required: false
|
||||
description: phandle to the reserved memory child node
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) Carlo Caione <ccaione@baylibre.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <autoconf.h>
|
||||
#include <linker/sections.h>
|
||||
#include <devicetree.h>
|
||||
|
||||
#include <linker/linker-defs.h>
|
||||
#include <linker/linker-tool.h>
|
||||
|
||||
MEMORY
|
||||
{
|
||||
DT_RESERVED_MEM_REGIONS()
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
DT_RESERVED_MEM_SECTIONS()
|
||||
}
|
||||
|
||||
#include <arch/arm64/scripts/linker.ld>
|
2
samples/boards/qemu_cortex_a53/reserved_memory/prj.conf
Normal file
2
samples/boards/qemu_cortex_a53/reserved_memory/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
|
||||
CONFIG_CUSTOM_LINKER_SCRIPT="linker_arm64_reserved.ld"
|
|
@ -0,0 +1,8 @@
|
|||
sample:
|
||||
description: Reserved memory sample application
|
||||
name: reserved memory
|
||||
tests:
|
||||
sample.board.qemu_cortex_a53.reserved_memory:
|
||||
platform_allow: qemu_cortex_a53
|
||||
tags: sample board reserved_memory
|
||||
build_only: true
|
38
samples/boards/qemu_cortex_a53/reserved_memory/src/main.c
Normal file
38
samples/boards/qemu_cortex_a53/reserved_memory/src/main.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <devicetree/memory.h>
|
||||
#include <linker/linker-defs.h>
|
||||
|
||||
/* Variables placed in reserved sections */
|
||||
uint32_t var_in_res0 __attribute((__section__(".res0"))) = 0xaabbccdd;
|
||||
uint32_t var_in_res1 __attribute((__section__(".res1"))) = 0xddccbbaa;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
uint8_t *res_ptr_outer, *res_ptr_inner;
|
||||
uint32_t res_size_outer, res_size_inner;
|
||||
|
||||
res_ptr_outer =
|
||||
DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
|
||||
memory_region);
|
||||
res_size_outer =
|
||||
DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
|
||||
memory_region);
|
||||
|
||||
printk("Reserved memory address for the outer driver: %p\n", res_ptr_outer);
|
||||
printk("Reserved memory size for the outer driver: %d\n", res_size_outer);
|
||||
|
||||
res_ptr_inner = DT_RESERVED_MEM_GET_PTR(DT_NODELABEL(res1));
|
||||
res_size_inner = DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(res1));
|
||||
|
||||
printk("Reserved memory address for the inner driver: %p\n", res_ptr_inner);
|
||||
printk("Reserved memory size for the inner driver: %d\n", res_size_inner);
|
||||
|
||||
printk("Address of var_in_res0: %p\n", &var_in_res0);
|
||||
printk("Address of var_in_res1: %p\n", &var_in_res1);
|
||||
}
|
Loading…
Reference in a new issue