blob: c0c948956f1f286b06b9c06b5a699a548e7af591 [file] [log] [blame]
David Brown5153bd62017-01-06 11:16:53 -07001/*
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
24extern "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
46struct 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
54extern const struct flash_area *flash_map;
55extern int flash_map_entries;
56
57/*
58 * Initializes flash map. Memory will be referenced by flash_map code
59 * from this on.
60 */
61void flash_map_init(void);
62
63/*
64 * Start using flash area.
65 */
66int flash_area_open(uint8_t id, const struct flash_area **);
67
68void flash_area_close(const struct flash_area *);
69
70/*
71 * Read/write/erase. Offset is relative from beginning of flash area.
72 */
73int flash_area_read(const struct flash_area *, uint32_t off, void *dst,
74 uint32_t len);
75int flash_area_write(const struct flash_area *, uint32_t off, const void *src,
76 uint32_t len);
77int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
78
79/*
80 * Alignment restriction for flash writes.
81 */
82uint8_t flash_area_align(const struct flash_area *);
83
84/*
85 * Given flash map index, return info about sectors within the area.
86 */
87int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);
88
89int flash_area_id_from_image_slot(int slot);
90int flash_area_id_to_image_slot(int area_id);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* H_UTIL_FLASH_MAP_ */