blob: 7da2dd90531c5bc23257a23a83f7e816b3031604 [file] [log] [blame]
Che-Liang Chiou305e9e52011-02-17 17:56:16 +08001/*
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
18typedef 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
28typedef 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 */
39const 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. */
44int FmapAreaIndex(const FmapHeader* fh, const FmapAreaHeader* ah,
45 const char* name);
46
47#endif /* __FMAP_H__ */