Skip to content

Commit

Permalink
Added bi_get_device() method
Browse files Browse the repository at this point in the history
For use of boot_info in user threads it is required to allow
access to the device from this thread. To achieve this access
to the backend device is needed.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
  • Loading branch information
Laczen committed Aug 21, 2023
1 parent d817eb2 commit e97dfa2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/zephyr/boot_info/boot_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ extern "C" {
*
*/

/**
* @brief boot_info_get_device: Get the device that is used as backend for
* the boot_info area.
*
* @param _node: nodelabel of the boot_info area (e.g. DT_NODELABEL(boot_info)).
* @retval size of the boot_info area.
*/
#define boot_info_get_device(_node) _CONCAT(bi_get_device_, _node)()

/**
* @brief boot_info_get_size: Get the size of the boot_info area.
*
Expand Down Expand Up @@ -102,6 +111,7 @@ extern "C" {
*/

#define DEFINE_BOOT_INFO_PROTO(inst) \
const struct device *bi_get_device_##inst(void); \
size_t bi_get_size_##inst(void); \
int bi_get_##inst(void *data); \
int bi_set_##inst(const void *data);
Expand Down
12 changes: 12 additions & 0 deletions subsys/boot_info/boot_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#define BBRAM_BACKEND_FCNTS(inst) \
const struct device *const bi_dev_##inst = \
DEVICE_DT_GET(BACKEND_PHANDLE(inst)); \
const struct device *bi_get_device_##inst(void) \
{ \
return bi_dev_##inst; \
} \
size_t bi_get_size_##inst(void) \
{ \
if (!device_is_ready(bi_dev_##inst)) { \
Expand Down Expand Up @@ -60,6 +64,10 @@ DT_FOREACH_STATUS_OKAY(zephyr_boot_info_bbram, BBRAM_BACKEND_FCNTS)
#define FLASH_BACKEND_FCNTS(inst) \
const struct device *const bi_dev_##inst = DEVICE_DT_GET( \
DT_MTD_FROM_FIXED_PARTITION(BACKEND_PHANDLE(inst))); \
const struct device *bi_get_device_##inst(void) \
{ \
return bi_dev_##inst; \
} \
size_t bi_get_size_##inst(void) \
{ \
if (!device_is_ready(bi_dev_##inst)) { \
Expand Down Expand Up @@ -120,6 +128,10 @@ DT_FOREACH_STATUS_OKAY(zephyr_boot_info_flash, FLASH_BACKEND_FCNTS)
#define EEPROM_BACKEND_FCNTS(inst) \
const struct device *const bi_dev_##inst = \
DEVICE_DT_GET(BACKEND_PHANDLE(inst)); \
const struct device *bi_get_device_##inst(void) \
{ \
return bi_dev_##inst; \
} \
size_t bi_get_size_##inst(void) \
{ \
if (!device_is_ready(bi_dev_##inst)) { \
Expand Down
1 change: 1 addition & 0 deletions tests/subsys/boot_info/boards/qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2023 Laczen
# SPDX-License-Identifier: Apache-2.0
CONFIG_USERSPACE=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ZTEST_STACK_SIZE=4196
Expand Down
12 changes: 11 additions & 1 deletion tests/subsys/boot_info/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
#define BOOT_INFO DT_NODELABEL(boot_info)
#define BOOT_INFO_ALIAS DT_ALIAS(bi)

static void *boot_info_api_setup(void)
{
if (IS_ENABLED(CONFIG_USERSPACE)) {
k_object_access_grant(boot_info_get_device(BOOT_INFO),
k_current_get());
}

return NULL;
}

ZTEST_USER(boot_info_api, test_get_size)
{
size_t bi_size = boot_info_get_size(BOOT_INFO);
Expand Down Expand Up @@ -41,4 +51,4 @@ ZTEST_USER(boot_info_api, test_get_set)
zassert_equal(memcmp(rd, wr, sizeof(wr)), 0, "data mismatch");
}

ZTEST_SUITE(boot_info_api, NULL, NULL, NULL, NULL, NULL);
ZTEST_SUITE(boot_info_api, NULL, boot_info_api_setup, NULL, NULL, NULL);

0 comments on commit e97dfa2

Please sign in to comment.