Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 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 _COMMONLIB_CBFS_H_ |
| 17 | #define _COMMONLIB_CBFS_H_ |
| 18 | |
| 19 | #include <commonlib/cbfs_serialized.h> |
| 20 | #include <commonlib/region.h> |
Aaron Durbin | cbb6c75 | 2015-12-15 15:57:11 -0600 | [diff] [blame] | 21 | /* TODO: remove me! This is for vboot_handoff.c's benefit. */ |
| 22 | #define NEED_VB20_INTERNALS |
| 23 | #include <vb2_api.h> |
Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 24 | |
| 25 | /* Object representing cbfs files. */ |
| 26 | struct cbfsf { |
| 27 | struct region_device metadata; |
| 28 | struct region_device data; |
| 29 | }; |
| 30 | |
| 31 | /* Locate file by name and optional type. Returns 0 on succcess else < 0 on |
| 32 | * error.*/ |
| 33 | int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, |
| 34 | const char *name, uint32_t *type); |
| 35 | |
| 36 | static inline void cbfs_file_data(struct region_device *data, |
| 37 | const struct cbfsf *file) |
| 38 | { |
| 39 | rdev_chain(data, &file->data, 0, region_device_sz(&file->data)); |
| 40 | } |
| 41 | |
| 42 | static inline void cbfs_file_metadata(struct region_device *metadata, |
| 43 | const struct cbfsf *file) |
| 44 | { |
| 45 | rdev_chain(metadata, &file->metadata, 0, |
| 46 | region_device_sz(&file->metadata)); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Provide a handle to each cbfs file within a cbfs. The prev pointer represents |
| 51 | * the previous file (NULL on first invocation). The next object gets filled |
| 52 | * out with the next file. This returns < 0 on error, 0 on finding the next |
| 53 | * file, and > 0 at end of cbfs. |
| 54 | */ |
| 55 | int cbfs_for_each_file(const struct region_device *cbfs, |
| 56 | const struct cbfsf *prev, struct cbfsf *fh); |
| 57 | |
Aaron Durbin | cbb6c75 | 2015-12-15 15:57:11 -0600 | [diff] [blame] | 58 | /* |
| 59 | * Perform the vb2 hash over the CBFS region skipping empty file contents. |
| 60 | * Caller is responsible for providing the hash algorithm as well as storage |
| 61 | * for the final digest. Return 0 on success or non-zero on error. |
| 62 | */ |
| 63 | int cbfs_vb2_hash_contents(const struct region_device *cbfs, |
| 64 | enum vb2_hash_algorithm hash_alg, void *digest, |
| 65 | size_t digest_sz); |
| 66 | |
Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 67 | #endif |