Che-Liang Chiou | 305e9e5 | 2011-02-17 17:56:16 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __FMAP_H__ |
| 8 | #define __FMAP_H__ |
| 9 | |
| 10 | #include <inttypes.h> |
| 11 | #include <stddef.h> |
| 12 | |
| 13 | /* FMAP structs. See http://code.google.com/p/flashmap/wiki/FmapSpec */ |
| 14 | #define FMAP_NAMELEN 32 |
| 15 | #define FMAP_SIGNATURE "__FMAP__" |
| 16 | #define FMAP_SIGNATURE_SIZE 8 |
| 17 | #define FMAP_SEARCH_STRIDE 4 |
| 18 | typedef struct _FmapHeader { |
| 19 | char fmap_signature[FMAP_SIGNATURE_SIZE]; /* avoiding endian issues */ |
| 20 | uint8_t fmap_ver_major; |
| 21 | uint8_t fmap_ver_minor; |
| 22 | uint64_t fmap_base; |
| 23 | uint32_t fmap_size; |
| 24 | char fmap_name[FMAP_NAMELEN]; |
| 25 | uint16_t fmap_nareas; |
| 26 | } __attribute__((packed)) FmapHeader; |
| 27 | |
| 28 | typedef struct _FmapAreaHeader { |
| 29 | uint32_t area_offset; |
| 30 | uint32_t area_size; |
| 31 | char area_name[FMAP_NAMELEN]; |
| 32 | uint16_t area_flags; |
| 33 | } __attribute__((packed)) FmapAreaHeader; |
| 34 | |
| 35 | |
| 36 | /* Scan firmware image, pointed by [ptr] with length [size], for fmap header. |
| 37 | * Return pointer to fmap header, or NULL if not found. |
| 38 | */ |
| 39 | const char* FmapFind(const char *ptr, size_t size); |
| 40 | |
| 41 | /* Look up fmap area by name, that is, strcmp(fh->fmap_name, name) == 0. |
| 42 | * Return index of fmap area, that is, ah[returned_index], |
| 43 | * or -1 if not found. */ |
| 44 | int FmapAreaIndex(const FmapHeader* fh, const FmapAreaHeader* ah, |
| 45 | const char* name); |
| 46 | |
| 47 | #endif /* __FMAP_H__ */ |