Aaron Durbin | cd0bc98 | 2016-11-19 12:36:09 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2016 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef REGION_FILE_H |
| 17 | #define REGION_FILE_H |
| 18 | |
| 19 | #include <commonlib/region.h> |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | /* |
| 23 | * A region file is an abstraction to allow appending updates in a |
| 24 | * region_device where the data returned is the most recently written |
| 25 | * data. It is block based with a 16 byte granularity. So if you write |
| 26 | * 2 bytes into the file the data returned in the region_device would |
| 27 | * have 16 bytes allocated for the latest update. Additionally, the |
| 28 | * current maximum file size allowed is 1MiB - 48 bytes. See comments |
| 29 | * in C implementation file for further details. |
| 30 | */ |
| 31 | |
| 32 | struct region_file; |
| 33 | |
| 34 | /* |
| 35 | * Initialize a region file associated with a provided region device. |
| 36 | * Returns < 0 on error, 0 on success. |
| 37 | */ |
| 38 | int region_file_init(struct region_file *f, const struct region_device *p); |
| 39 | |
| 40 | /* |
| 41 | * Initialize region device object associated with latest update of file data. |
| 42 | * Returns < 0 on error, 0 on success. |
| 43 | */ |
| 44 | int region_file_data(const struct region_file *f, struct region_device *rdev); |
| 45 | |
| 46 | /* Update region file with latest data. Returns < 0 on error, 0 on success. */ |
| 47 | int region_file_update_data(struct region_file *f, const void *buf, |
| 48 | size_t size); |
| 49 | |
| 50 | /* Declared here for easy object allocation. */ |
| 51 | struct region_file { |
| 52 | /* Region device covering file */ |
| 53 | struct region_device rdev; |
| 54 | /* Metadata containing blocks of the data stream. */ |
| 55 | struct region_device metadata; |
| 56 | /* Blocks forming data. */ |
| 57 | uint16_t data_blocks[2]; |
| 58 | /* Current slot in metadata marking end of data. */ |
| 59 | int slot; |
| 60 | }; |
| 61 | |
| 62 | #endif /* REGION_FILE_H */ |