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 https://github.com/zephyrproject-rtos/zephyr/pull/8837 Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
23e3853c0a
commit
419a47531b
|
@ -49,12 +49,20 @@ int flash_device_base(uint8_t fd_id, uintptr_t *ret)
|
|||
}
|
||||
|
||||
/*
|
||||
* This depends on the mappings defined in sysflash.h, and assumes
|
||||
* that slot 0, slot 1, and the scratch areas are contiguous.
|
||||
* This depends on the mappings defined in sysflash.h.
|
||||
* MCUBoot uses continuous numbering for slot 0, slot 1, and the scratch
|
||||
* while zephyr might number it differently.
|
||||
*/
|
||||
int flash_area_id_from_image_slot(int slot)
|
||||
{
|
||||
return slot + FLASH_AREA_IMAGE_0;
|
||||
static const int area_id_tab[] = {FLASH_AREA_IMAGE_0, FLASH_AREA_IMAGE_1,
|
||||
FLASH_AREA_IMAGE_SCRATCH};
|
||||
|
||||
if (slot >= 0 && slot < ARRAY_SIZE(area_id_tab)) {
|
||||
return area_id_tab[slot];
|
||||
}
|
||||
|
||||
return -EINVAL; /* flash_area_open will fail on that */
|
||||
}
|
||||
|
||||
int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
#ifndef __SYSFLASH_H__
|
||||
#define __SYSFLASH_H__
|
||||
|
||||
#define FLASH_AREA_IMAGE_0 1
|
||||
#define FLASH_AREA_IMAGE_1 2
|
||||
#define FLASH_AREA_IMAGE_SCRATCH 3
|
||||
#include <generated_dts_board.h>
|
||||
|
||||
#define FLASH_AREA_IMAGE_0 DT_FLASH_AREA_IMAGE_0_ID
|
||||
#define FLASH_AREA_IMAGE_1 DT_FLASH_AREA_IMAGE_1_ID
|
||||
#define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID
|
||||
|
||||
#endif /* __SYSFLASH_H__ */
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* This file mocks zephyr's autogenerated DT output header file */
|
||||
|
||||
#ifndef __GENERATED_DTS_BOARD_H__
|
||||
#define __GENERATED_DTS_BOARD_H__
|
||||
|
||||
#define DT_FLASH_AREA_IMAGE_0_ID 1
|
||||
#define DT_FLASH_AREA_IMAGE_1_ID 2
|
||||
#define DT_FLASH_AREA_IMAGE_SCRATCH_ID 3
|
||||
|
||||
#endif /*__GENERATED_DTS_BOARD_H__*/
|
Loading…
Reference in New Issue