Andrzej Puzdrowski | b788c71 | 2018-04-12 12:42:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Nordic Semiconductor ASA |
| 3 | * Copyright (c) 2015 Runtime Inc |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | */ |
| 7 | |
| 8 | #include <zephyr.h> |
| 9 | #include <flash.h> |
| 10 | |
| 11 | #include "target.h" |
| 12 | |
| 13 | #include <flash_map_backend/flash_map_backend.h> |
| 14 | #include <hal/hal_flash.h> |
| 15 | #include <sysflash/sysflash.h> |
| 16 | |
| 17 | #include "bootutil/bootutil_log.h" |
| 18 | |
| 19 | /* |
| 20 | * For now, we only support one flash device. |
| 21 | * |
| 22 | * Pick the SoC Flash driver ID. |
| 23 | */ |
| 24 | #define FLASH_DEVICE_ID SOC_FLASH_0_ID |
| 25 | #define FLASH_DEVICE_BASE CONFIG_FLASH_BASE_ADDRESS |
| 26 | |
| 27 | int flash_device_base(uint8_t fd_id, uintptr_t *ret) |
| 28 | { |
| 29 | if (fd_id != FLASH_DEVICE_ID) { |
| 30 | BOOT_LOG_ERR("invalid flash ID %d; expected %d", |
| 31 | fd_id, FLASH_DEVICE_ID); |
| 32 | return -EINVAL; |
| 33 | } |
| 34 | *ret = FLASH_DEVICE_BASE; |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * This depends on the mappings defined in sysflash.h, and assumes |
| 40 | * that slot 0, slot 1, and the scratch areas are contiguous. |
| 41 | */ |
| 42 | int flash_area_id_from_image_slot(int slot) |
| 43 | { |
| 44 | return slot + FLASH_AREA_IMAGE_0; |
| 45 | } |