Commit 419a4753 authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by Carles Cufí
Browse files

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: default avatarAndrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
parent 23e3853c
Loading
Loading
Loading
Loading
+11 −3
Changes for boot/zephyr/flash_map_extended.c: 11 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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)
+5 −3
Changes for boot/zephyr/include/sysflash/sysflash.h: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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__ */
+16
Changes for sim/mcuboot-sys/csupport/generated_dts_board.h: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * 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__*/