DT_CHOSEN is not working.

I am trying to work with my flash deivce in my code.
for some reason:

const static struct device *int_flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash));

doesnt work, but this does: 

const static struct device *int_flash_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(my_partition)));

where the my_partition node is coming from my overlay file:



&flash0 {
partitions {
/* 0xf0000 to 0xf7fff reserved for TF-M partitions */
my_partition: partition@0 {
label = "my_storage";
reg = <0x0 0x1>;
};
};
};


The error message I am getting is:

undefined reference to `__device_dts_ord_94'
collect2: error: ld returned 1 exit status

the chosen node on my device tree looks like this:
chosen {
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
.
.
.
}


shouldn't both of those evaluate to the same device? 

thanks in advance,
shlomo



Parents
  • Hi,
    if you take a look at your zephyr.dts in your build folder, you can see that flash0 is actually not a device. It's just a layout/partition node. The actual hardware/device node is flash_controller. This is a common pattern for internal flash across various SoC (for external flash, oftentimes flash0 is the actual device)


    So, you can use 

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_PARENT(DT_CHOSEN(zephyr_flash)));

    or

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_NODELABEL(flash_controller));

    or just keep your 

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(my_partition)));

    You can also filter for "soc_nv_flash" compatibility as this is for layout/partition

    #if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_flash), soc_nv_flash)
    #  define FLASH_DEV_NODE DT_PARENT(DT_CHOSEN(zephyr_flash))
    #else
    #  define FLASH_DEV_NODE DT_CHOSEN(zephyr_flash)
    #endif
Reply
  • Hi,
    if you take a look at your zephyr.dts in your build folder, you can see that flash0 is actually not a device. It's just a layout/partition node. The actual hardware/device node is flash_controller. This is a common pattern for internal flash across various SoC (for external flash, oftentimes flash0 is the actual device)


    So, you can use 

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_PARENT(DT_CHOSEN(zephyr_flash)));

    or

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_NODELABEL(flash_controller));

    or just keep your 

    const static struct device *int_flash_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(my_partition)));

    You can also filter for "soc_nv_flash" compatibility as this is for layout/partition

    #if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_flash), soc_nv_flash)
    #  define FLASH_DEV_NODE DT_PARENT(DT_CHOSEN(zephyr_flash))
    #else
    #  define FLASH_DEV_NODE DT_CHOSEN(zephyr_flash)
    #endif
Children
Related