|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef H_UTIL_FLASH_MAP_ |
| 21 | +#define H_UTIL_FLASH_MAP_ |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" { |
| 25 | +#endif |
| 26 | + |
| 27 | +/** |
| 28 | + * |
| 29 | + * Provides abstraction of flash regions for type of use. |
| 30 | + * I.e. dude where's my image? |
| 31 | + * |
| 32 | + * System will contain a map which contains flash areas. Every |
| 33 | + * region will contain flash identifier, offset within flash and length. |
| 34 | + * |
| 35 | + * 1. This system map could be in a file within filesystem (Initializer |
| 36 | + * must know/figure out where the filesystem is at). |
| 37 | + * 2. Map could be at fixed location for project (compiled to code) |
| 38 | + * 3. Map could be at specific place in flash (put in place at mfg time). |
| 39 | + * |
| 40 | + * Note that the map you use must be valid for BSP it's for, |
| 41 | + * match the linker scripts when platform executes from flash, |
| 42 | + * and match the target offset specified in download script. |
| 43 | + */ |
| 44 | +#include <inttypes.h> |
| 45 | + |
| 46 | +struct flash_area { |
| 47 | + uint8_t fa_id; |
| 48 | + uint8_t fa_device_id; |
| 49 | + uint16_t pad16; |
| 50 | + uint32_t fa_off; |
| 51 | + uint32_t fa_size; |
| 52 | +}; |
| 53 | + |
| 54 | +extern const struct flash_area *flash_map; |
| 55 | +extern int flash_map_entries; |
| 56 | + |
| 57 | +/* |
| 58 | + * Initializes flash map. Memory will be referenced by flash_map code |
| 59 | + * from this on. |
| 60 | + */ |
| 61 | +void flash_map_init(void); |
| 62 | + |
| 63 | +/* |
| 64 | + * Start using flash area. |
| 65 | + */ |
| 66 | +int flash_area_open(uint8_t id, const struct flash_area **); |
| 67 | + |
| 68 | +void flash_area_close(const struct flash_area *); |
| 69 | + |
| 70 | +/* |
| 71 | + * Read/write/erase. Offset is relative from beginning of flash area. |
| 72 | + */ |
| 73 | +int flash_area_read(const struct flash_area *, uint32_t off, void *dst, |
| 74 | + uint32_t len); |
| 75 | +int flash_area_write(const struct flash_area *, uint32_t off, const void *src, |
| 76 | + uint32_t len); |
| 77 | +int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len); |
| 78 | + |
| 79 | +/* |
| 80 | + * Alignment restriction for flash writes. |
| 81 | + */ |
| 82 | +uint8_t flash_area_align(const struct flash_area *); |
| 83 | + |
| 84 | +/* |
| 85 | + * Given flash map index, return info about sectors within the area. |
| 86 | + */ |
| 87 | +int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret); |
| 88 | + |
| 89 | +int flash_area_id_from_image_slot(int slot); |
| 90 | +int flash_area_id_to_image_slot(int area_id); |
| 91 | + |
| 92 | +#ifdef __cplusplus |
| 93 | +} |
| 94 | +#endif |
| 95 | + |
| 96 | +#endif /* H_UTIL_FLASH_MAP_ */ |
0 commit comments