/* flash_map.h * * Copyright (C) 2018 wolfSSL Inc. * * This file is part of wolfBoot. * * wolfBoot is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * wolfBoot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #ifndef H_UTIL_FLASH_MAP_ #define H_UTIL_FLASH_MAP_ /** * * System will contain a map which contains flash areas. Every * region will contain flash identifier, offset within flash and length. * * 1. This system map could be in a file within filesystem (Initializer * must know/figure out where the filesystem is at). * 2. Map could be at fixed location for project (compiled to code) * 3. Map could be at specific place in flash (put in place at mfg time). * * Note that the map you use must be valid for BSP it's for, * match the linker scripts when platform executes from flash, * and match the target offset specified in download script. */ #include /** * @brief Structure describing an area on a flash device. * * Multiple flash devices may be available in the system, each of * which may have its own areas. For this reason, flash areas track * which flash device they are part of. */ struct flash_area { /** * This flash area's ID; unique in the system. */ uint8_t fa_id; /** * ID of the flash device this area is a part of. */ uint8_t fa_device_id; uint16_t pad16; /** * This area's offset, relative to the beginning of its flash * device's storage. */ uint32_t fa_off; /** * This area's size, in bytes. */ uint32_t fa_size; }; /** * @brief Structure describing a sector within a flash area. * * Each sector has an offset relative to the start of its flash area * (NOT relative to the start of its flash device), and a size. A * flash area may contain sectors with different sizes. */ struct flash_sector { /** * Offset of this sector, from the start of its flash area (not device). */ uint32_t fs_off; /** * Size of this sector, in bytes. */ uint32_t fs_size; }; /* * Retrieve a memory-mapped flash device's base address. * * On success, the address will be stored in the value pointed to by * ret. * * Returns 0 on success, or an error code on failure. */ int flash_device_base(uint8_t fd_id, uintptr_t *ret); /* * Start using flash area. */ int flash_area_open(uint8_t id, const struct flash_area **); void flash_area_close(const struct flash_area *); /* * Read/write/erase. Offset is relative from beginning of flash area. */ int flash_area_read(const struct flash_area *, uint32_t off, void *dst, uint32_t len); int flash_area_write(const struct flash_area *, uint32_t off, const void *src, uint32_t len); int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len); /* * Alignment restriction for flash writes. */ uint8_t flash_area_align(const struct flash_area *); /* * Given flash area ID, return info about sectors within the area. */ int flash_area_get_sectors(int fa_id, uint32_t *count, struct flash_sector *sectors); int flash_area_id_from_image_slot(int slot); int flash_area_id_to_image_slot(int area_id); #endif /* H_UTIL_FLASH_MAP_ */