Re: Flash configuration in dts file


Laurence Pasteau
 

Thank you for your answer.


However when I did like you (see below first case) the configuration is not good.

Indeed the application starts correctly but CONFIG_FLASH_LOAD_SIZE is set to 0 :


First case


Same flash_map_default.c as you)

dts file :


&flash0 {
    /*
     * For more information, see:
     * http://docs.zephyrproject.org/devices/dts/flash_partitions.html
     */
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

#if defined(CONFIG_BOOTLOADER_MCUBOOT)
/* .... */
 #else
        slot0_partition: partition@4 {
            label = "code-partition";
            reg = <0x00000004 0x40000>;
        };
#if defined(CONFIG_FS_FLASH_STORAGE_PARTITION)
        storage_partition: partition@40004 {
            label = "storage";
            reg = <0x00040004 0x0003FFFC>;
        };
#endif
#endif
    };
};


file build/zephyr/include/generated/generated_dts_board.h :

/* flash@0 */
#define CONFIG_FLASH_BASE_ADDRESS        0x0
#define CONFIG_FLASH_LOAD_OFFSET        0
#define CONFIG_FLASH_LOAD_SIZE            0
#define CONFIG_FLASH_SIZE            512
#define FLASH_LABEL                "NRF_FLASH"
#define FLASH_NRF_FLASH_LABEL            "NRF_FLASH"
#define FLASH_NRF_FLASH_WRITE_BLOCK_SIZE    4
#define FLASH_WRITE_BLOCK_SIZE            4


Second case :


I add in dts file :

 
chosen {
#if !defined(CONFIG_BOOTLOADER_MCUBOOT)
        zephyr,code-partition = &slot0_partition;
#endif
    };

the application does NOT start but the configuration is good :


file build/zephyr/include/generated/generated_dts_board.h :

/* flash@0 */
#define CONFIG_FLASH_BASE_ADDRESS        0x0
#define CONFIG_FLASH_LOAD_OFFSET        0x4
#define CONFIG_FLASH_LOAD_SIZE            262144
#define CONFIG_FLASH_SIZE            512
#define FLASH_LABEL                "NRF_FLASH"
#define FLASH_NRF_FLASH_LABEL            "NRF_FLASH"
#define FLASH_NRF_FLASH_WRITE_BLOCK_SIZE    4
#define FLASH_WRITE_BLOCK_SIZE            4


My need is to have CONFIG_FLASH_LOAD_SIZE set to the max firmware size in order to know if the size of the firmware is small enough during compilation time :

First case :
Memory region         Used Size  Region Size  %age Used
           FLASH:      205416 B       512 KB     39.18%
            SRAM:       46888 B        64 KB     71.55%
        IDT_LIST:         180 B         2 KB      8.79%


Second case :
Memory region         Used Size  Region Size  %age Used
           FLASH:      205476 B       256 KB     78.38%
            SRAM:       46888 B        64 KB     71.55%
        IDT_LIST:         180 B         2 KB      8.79%

Thanks in advance for any help.
Regards,
Laurence


De : David Leach <david.leach@...>
Envoyé : vendredi 17 août 2018 18:04
À : Laurence Pasteau; zephyr-devel@...
Objet : RE: [Zephyr-devel] Flash configuration in dts file
 

In some work that I’m doing I had to do the same thing. I haven’t posted a PR for this work so I’m not sure how the community will react but here is what I did to add the file system partition with a single slot partition:

 

 

In my DTS file I have the following:

 

&flash0 {

                /*

                * For more information, see:

                * http://docs.zephyrproject.org/devices/dts/flash_partitions.html

                */

                partitions {

                                compatible = "fixed-partitions";

                                #address-cells = <1>;

                                #size-cells = <1>;

                               

#if defined(CONFIG_FS_FLASH_STORAGE_PARTITION)

                                slot0_partition: partition@c000 {

                                                label = "image-0";

                                                reg = <0x00000000 0x7d000>;

                                };

 

                                storage_partition: partition@7a000 {

                                                label = "storage";

                                                reg = <0x0007d000 0x00003000>;

                                };

#else

                                slot0_partition: partition@c000 {

                                                label = "image-0";

                                                reg = <0x00000000 0x80000>;

                                };

#endif

                };

};

 

Then I needed to change subsys/storage/flash_map/flash_map_default.c to conditionally include partitions based on whether that partition’s SIZE define is defined:

 

 

const struct flash_area default_flash_map[] = {

#ifdef FLASH_AREA_MCUBOOT_SIZE

                /* FLASH_AREA_BOOTLOADER */

                {

                                .fa_id = 0,

                                .fa_device_id = SOC_FLASH_0_ID,

                                .fa_off = FLASH_AREA_MCUBOOT_OFFSET,

                                .fa_size = FLASH_AREA_MCUBOOT_SIZE,

                },

#endif

                /* FLASH_AREA_IMAGE_0 */

                {

                                .fa_id = 1,

                                .fa_device_id = SOC_FLASH_0_ID,

                                .fa_off = FLASH_AREA_IMAGE_0_OFFSET,

                                .fa_size = FLASH_AREA_IMAGE_0_SIZE,

                },

#ifdef FLASH_AREA_IMAGE_1_SIZE

                /* FLASH_AREA_IMAGE_1 */

                {

                                .fa_id = 2,

                                .fa_device_id = SOC_FLASH_0_ID,

                                .fa_off = FLASH_AREA_IMAGE_1_OFFSET,

                                .fa_size = FLASH_AREA_IMAGE_1_SIZE,

                },

#endif

#ifdef FLASH_AREA_IMAGE_SCRATCH_SIZE

                /* FLASH_AREA_IMAGE_SCRATCH */

                {

                                .fa_id = 3,

                                .fa_device_id = SOC_FLASH_0_ID,

                                .fa_off = FLASH_AREA_IMAGE_SCRATCH_OFFSET,

                                .fa_size = FLASH_AREA_IMAGE_SCRATCH_SIZE,

                },

#endif

#ifdef CONFIG_FS_FLASH_STORAGE_PARTITION

                /* FLASH_AREA_STORAGE */

                {

                                .fa_id = 4,

                                .fa_device_id = SOC_FLASH_0_ID,

                                .fa_off = FLASH_AREA_STORAGE_OFFSET,

                                .fa_size = FLASH_AREA_STORAGE_SIZE,

                },

#endif

};

 

 

From: devel@... <devel@...> On Behalf Of Laurence Pasteau
Sent: Friday, August 17, 2018 10:35 AM
To: zephyr-devel@...
Subject: Re: [Zephyr-devel] Flash configuration in dts file

 

The solution below is not available since I need to start the fimrware at 0x0 without bootloader.

 

So I would really appreciate if someone could help me.

I compile with a nrf52_pca10040 board.

 

Regards,

Laurence

 


De : devel@... <devel@...> de la part de Laurence Pasteau <laurence.pasteau@...>
Envoyé : vendredi 17 août 2018 16:51
À : zephyr-devel@...
Objet : [Zephyr-devel] Flash configuration in dts file

 

Hi everybody,

 

I have a question regarding dts file, and more specifically the flash partition.

I would like to have a project without bootloader, but with a partition for the code and another for the file system.

 

At compilation time I would like to be warned if the code partition is overlapping the flash partition.

 

First I tried to set CONFIG_FLASH_LOAD_SIZE. As I have no bootloader, I still need CONFIG_FLASH_LOAD_OFFSET to 0.

Unfortunately as CONFIG_HAS_DTS is set in this project, these values are not taken into account.

 

However in the script that generates the generated_dts_board files from dts, it seems that :

if CONFIG_FLASH_LOAD_OFFSET is set to 0

then

CONFIG_FLASH_LOAD_SIZE is set to 0.

 

The only successfull but not pretty solution I found was this one :

 

        boot_partition: partition@0 {
            label = "noboot";
            reg = <0x00000000 0x4>;
        };
        code_partition: partition@4 {
            label = "code-partition";
            reg = <0x00000004 0x40000>;
        };
#if defined(CONFIG_FS_FLASH_STORAGE_PARTITION)
        storage_partition: partition@40004 {
            label = "storage";
            reg = <0x00040004 0x0003FFFC>;
        };
#endif

 

Is there a better way to solve this issue ?

 

Thanks in advance,

Regards,

Laurence

 

Join devel@lists.zephyrproject.org to automatically receive all group messages.