Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | #ifndef VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ |
| 7 | #define VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 11 | /* What are we trying to accomplish? */ |
| 12 | enum futil_op_type { |
| 13 | FUTIL_OP_SHOW, |
Bill Richardson | 15dc6fc | 2014-09-02 14:45:44 -0700 | [diff] [blame] | 14 | FUTIL_OP_SIGN, |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 15 | |
| 16 | NUM_FUTIL_OPS |
| 17 | }; |
| 18 | |
| 19 | /* What component are we currently handling in the callback routine? */ |
| 20 | enum futil_cb_component { |
| 21 | /* entire input buffer */ |
| 22 | CB_BEGIN_TRAVERSAL, |
| 23 | CB_END_TRAVERSAL, |
| 24 | /* fmap areas within a bios image */ |
| 25 | CB_FMAP_GBB, |
| 26 | CB_FMAP_VBLOCK_A, |
| 27 | CB_FMAP_VBLOCK_B, |
| 28 | CB_FMAP_FW_MAIN_A, |
| 29 | CB_FMAP_FW_MAIN_B, |
| 30 | /* individual files (extracted from a bios, for example) */ |
| 31 | CB_PUBKEY, |
| 32 | CB_KEYBLOCK, |
| 33 | CB_GBB, |
| 34 | CB_FW_PREAMBLE, |
Bill Richardson | 6f72ffa | 2014-09-23 14:40:20 -0700 | [diff] [blame] | 35 | CB_KERN_PREAMBLE, |
| 36 | CB_RAW_FIRMWARE, |
| 37 | CB_RAW_KERNEL, |
Bill Richardson | 4805f18 | 2015-01-30 22:21:10 -0800 | [diff] [blame] | 38 | CB_PRIVKEY, |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 39 | |
| 40 | NUM_CB_COMPONENTS |
| 41 | }; |
| 42 | |
| 43 | /* Where is the component we're poking at? */ |
| 44 | struct cb_area_s { |
| 45 | uint32_t offset; /* to avoid pointer math */ |
| 46 | uint8_t *buf; |
| 47 | uint32_t len; |
| 48 | uint32_t _flags; /* for callback use */ |
| 49 | }; |
| 50 | |
| 51 | /* What do we know at this point in time? */ |
| 52 | struct futil_traverse_state_s { |
Bill Richardson | 779796f | 2014-09-23 11:47:40 -0700 | [diff] [blame] | 53 | /* These two should be initialized by the caller as needed */ |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 54 | const char *in_filename; |
| 55 | enum futil_op_type op; |
| 56 | /* Current activity during traversal */ |
| 57 | enum futil_cb_component component; |
| 58 | struct cb_area_s *my_area; |
| 59 | const char *name; |
| 60 | /* Other activites, possibly before or after the current one */ |
| 61 | struct cb_area_s cb_area[NUM_CB_COMPONENTS]; |
| 62 | struct cb_area_s recovery_key; |
| 63 | struct cb_area_s rootkey; |
| 64 | enum futil_file_type in_type; |
| 65 | int errors; |
| 66 | }; |
| 67 | |
Bill Richardson | b0f1cc5 | 2014-09-24 00:23:56 -0700 | [diff] [blame] | 68 | |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 69 | /* |
Bill Richardson | b0f1cc5 | 2014-09-24 00:23:56 -0700 | [diff] [blame] | 70 | * Traverse the buffer using the provided state, which should be initialized |
| 71 | * before calling. Returns nonzero (but no details) if there were any errors. |
| 72 | */ |
| 73 | int futil_traverse(uint8_t *buf, uint32_t len, |
| 74 | struct futil_traverse_state_s *state, |
| 75 | enum futil_file_type type_hint); |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 76 | |
| 77 | /* These are invoked by the traversal. They also return nonzero on error. */ |
| 78 | int futil_cb_show_begin(struct futil_traverse_state_s *state); |
Bill Richardson | 4805f18 | 2015-01-30 22:21:10 -0800 | [diff] [blame] | 79 | int futil_cb_show_pubkey(struct futil_traverse_state_s *state); |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 80 | int futil_cb_show_gbb(struct futil_traverse_state_s *state); |
| 81 | int futil_cb_show_keyblock(struct futil_traverse_state_s *state); |
| 82 | int futil_cb_show_fw_main(struct futil_traverse_state_s *state); |
| 83 | int futil_cb_show_fw_preamble(struct futil_traverse_state_s *state); |
Bill Richardson | 5f2696d | 2014-09-23 22:03:56 -0700 | [diff] [blame] | 84 | int futil_cb_show_kernel_preamble(struct futil_traverse_state_s *state); |
Bill Richardson | 4805f18 | 2015-01-30 22:21:10 -0800 | [diff] [blame] | 85 | int futil_cb_show_privkey(struct futil_traverse_state_s *state); |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 86 | |
Bill Richardson | 5f2696d | 2014-09-23 22:03:56 -0700 | [diff] [blame] | 87 | int futil_cb_sign_pubkey(struct futil_traverse_state_s *state); |
Bill Richardson | 15dc6fc | 2014-09-02 14:45:44 -0700 | [diff] [blame] | 88 | int futil_cb_sign_fw_main(struct futil_traverse_state_s *state); |
Bill Richardson | 5f2696d | 2014-09-23 22:03:56 -0700 | [diff] [blame] | 89 | int futil_cb_sign_fw_vblock(struct futil_traverse_state_s *state); |
| 90 | int futil_cb_sign_raw_firmware(struct futil_traverse_state_s *state); |
| 91 | int futil_cb_resign_kernel_part(struct futil_traverse_state_s *state); |
| 92 | int futil_cb_create_kernel_part(struct futil_traverse_state_s *state); |
Bill Richardson | 15dc6fc | 2014-09-02 14:45:44 -0700 | [diff] [blame] | 93 | int futil_cb_sign_begin(struct futil_traverse_state_s *state); |
| 94 | int futil_cb_sign_end(struct futil_traverse_state_s *state); |
| 95 | |
| 96 | |
Bill Richardson | cf6e78d | 2014-08-27 15:50:25 -0700 | [diff] [blame] | 97 | #endif /* VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ */ |