Skip to content

Commit 419a475

Browse files
nvlsianpucarlescufi
authored andcommitted
zephyr: allow dynamic numeration of flash_areas
Zephyr flash_map reworks caused that areas id exact number are assigned dynamically. This patch i counterpart to zephyrproject-rtos/zephyr#8837 Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 23e3853 commit 419a475

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

boot/zephyr/flash_map_extended.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,20 @@ int flash_device_base(uint8_t fd_id, uintptr_t *ret)
4949
}
5050

5151
/*
52-
* This depends on the mappings defined in sysflash.h, and assumes
53-
* that slot 0, slot 1, and the scratch areas are contiguous.
52+
* This depends on the mappings defined in sysflash.h.
53+
* MCUBoot uses continuous numbering for slot 0, slot 1, and the scratch
54+
* while zephyr might number it differently.
5455
*/
5556
int flash_area_id_from_image_slot(int slot)
5657
{
57-
return slot + FLASH_AREA_IMAGE_0;
58+
static const int area_id_tab[] = {FLASH_AREA_IMAGE_0, FLASH_AREA_IMAGE_1,
59+
FLASH_AREA_IMAGE_SCRATCH};
60+
61+
if (slot >= 0 && slot < ARRAY_SIZE(area_id_tab)) {
62+
return area_id_tab[slot];
63+
}
64+
65+
return -EINVAL; /* flash_area_open will fail on that */
5866
}
5967

6068
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)

boot/zephyr/include/sysflash/sysflash.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#ifndef __SYSFLASH_H__
44
#define __SYSFLASH_H__
55

6-
#define FLASH_AREA_IMAGE_0 1
7-
#define FLASH_AREA_IMAGE_1 2
8-
#define FLASH_AREA_IMAGE_SCRATCH 3
6+
#include <generated_dts_board.h>
7+
8+
#define FLASH_AREA_IMAGE_0 DT_FLASH_AREA_IMAGE_0_ID
9+
#define FLASH_AREA_IMAGE_1 DT_FLASH_AREA_IMAGE_1_ID
10+
#define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID
911

1012
#endif /* __SYSFLASH_H__ */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* This file mocks zephyr's autogenerated DT output header file */
8+
9+
#ifndef __GENERATED_DTS_BOARD_H__
10+
#define __GENERATED_DTS_BOARD_H__
11+
12+
#define DT_FLASH_AREA_IMAGE_0_ID 1
13+
#define DT_FLASH_AREA_IMAGE_1_ID 2
14+
#define DT_FLASH_AREA_IMAGE_SCRATCH_ID 3
15+
16+
#endif /*__GENERATED_DTS_BOARD_H__*/

0 commit comments

Comments
 (0)