Flash configuration in dts file


Laurence Pasteau
 

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


Laurence Pasteau
 

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


David Leach
 

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

 


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

 


David Leach
 

I’m not deeply familiar with FLASH configurations but it looks like CONFIG_FLASH_LOAD_SIZE is only really used in the cortex_m/scripts/linker.ld where it sets the ROM_SIZE to CONFIG_LOAD_SIZE if the LOAD_SIZE is >0 otherwise it sets ROM_SIZE to CONFIG_FLASH_SIZE*1K – CONFIG_FLASH_LOAD_OFFSET. So it seems like what is important is that CONFIG_FLASH_SIZE gets the right value.

 

I’ll note that the generated value on the KW41 builds has this set to 0 before I did the change below (and still has it set to zero now) so I suspect a zero value is generally okay as long as the ROM_SIZE has the right value.

 

David

 

From: Laurence Pasteau <laurence.pasteau@...>
Sent: Monday, August 20, 2018 10:33 AM
To: David Leach <david.leach@...>; zephyr-devel@...
Subject: RE: [Zephyr-devel] Flash configuration in dts file

 

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

 


David Brown
 

On Fri, Aug 17, 2018 at 02:51:54PM +0000, Laurence Pasteau wrote:

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.
I wonder if you are running into the same bug I've found in the
extraction script, which assumes the partition reg values are absolute
rather than relative. I've included the patch below if you want to
try it, and I'll be pushing it into the Zephyr tree soon.

From 656a2b6a78698c1173d9b5537c25eff8f01e2aba Mon Sep 17 00:00:00 2001
From: David Brown <david.brown@linaro.org>
Date: Tue, 21 Aug 2018 11:40:51 -0600
Subject: [PATCH] scripts: dts: Fix flash load offset

The flash load offset is being computed assuming that the reg property
in the partition table is an absolute address. Since this is a relative
address, this causes the offset to effectively subtract the flash base
twice. Since most flash devices start at zero, this hasn't been noticed
until now.

Change this so that the load-offset is just the offset of the code
partition.

Signed-off-by: David Brown <david.brown@linaro.org>
---
scripts/dts/extract/flash.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/scripts/dts/extract/flash.py b/scripts/dts/extract/flash.py
index fb5d42981..98fb8422d 100644
--- a/scripts/dts/extract/flash.py
+++ b/scripts/dts/extract/flash.py
@@ -95,8 +95,7 @@ class DTFlash(DTDirective):
if node and node is not self._flash_node:
# only compute the load offset if the code partition
# is not the same as the flash base address
- load_offset = str(int(node['props']['reg'][0]) \
- - int(self._flash_node['props']['reg'][0]))
+ load_offset = node['props']['reg'][0]
load_defs['CONFIG_FLASH_LOAD_OFFSET'] = load_offset
load_size = node['props']['reg'][1]
load_defs['CONFIG_FLASH_LOAD_SIZE'] = load_size
--
2.16.4


Laurence Pasteau
 

Thanks David.


However since I had this issue, I change the board definition to have a board out of zephyr scope, since it is a board created here in the compagny for a specific custom. Before I used pca10040 board and a dts.overlay file with all custom components but it is less clean.


It seems that what I needed to do works when the dts file is out of zephyr scope. I don't really undestand why but my issue is resolved in this way.


I have in dts file :
        zephyr ,code-partition = &slot_partition;
Then :
        slot_partition: partition@0 {
            label = "code-partition";
            reg = <0x00000000 0x40000>;
        };

and CONFIG_FLASH_LOAD_SIZE  is correclty setted to 262kB.

Regards,
Laurence

De : David Brown <david.brown@...>
Envoyé : mardi 21 août 2018 19:46
À : Laurence Pasteau
Cc : zephyr-devel@...
Objet : Re: [Zephyr-devel] Flash configuration in dts file
 

On Fri, Aug 17, 2018 at 02:51:54PM +0000, Laurence Pasteau wrote:

>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.

I wonder if you are running into the same bug I've found in the
extraction script, which assumes the partition reg values are absolute
rather than relative.  I've included the patch below if you want to
try it, and I'll be pushing it into the Zephyr tree soon.

From 656a2b6a78698c1173d9b5537c25eff8f01e2aba Mon Sep 17 00:00:00 2001
From: David Brown <david.brown@...>
Date: Tue, 21 Aug 2018 11:40:51 -0600
Subject: [PATCH] scripts: dts: Fix flash load offset

The flash load offset is being computed assuming that the reg property
in the partition table is an absolute address.  Since this is a relative
address, this causes the offset to effectively subtract the flash base
twice.  Since most flash devices start at zero, this hasn't been noticed
until now.

Change this so that the load-offset is just the offset of the code
partition.

Signed-off-by: David Brown <david.brown@...>
---
 scripts/dts/extract/flash.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/scripts/dts/extract/flash.py b/scripts/dts/extract/flash.py
index fb5d42981..98fb8422d 100644
--- a/scripts/dts/extract/flash.py
+++ b/scripts/dts/extract/flash.py
@@ -95,8 +95,7 @@ class DTFlash(DTDirective):
         if node and node is not self._flash_node:
             # only compute the load offset if the code partition
             # is not the same as the flash base address
-            load_offset = str(int(node['props']['reg'][0]) \
-                              - int(self._flash_node['props']['reg'][0]))
+            load_offset = node['props']['reg'][0]
             load_defs['CONFIG_FLASH_LOAD_OFFSET'] = load_offset
             load_size = node['props']['reg'][1]
             load_defs['CONFIG_FLASH_LOAD_SIZE'] = load_size
--
2.16.4