blob: 53088d5b7f923268c1f08cc74454d5e4c6da47f4 [file] [log] [blame]
Bill Richardsoncf6e78d2014-08-27 15:50:25 -07001/*
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 Richardsoncf6e78d2014-08-27 15:50:25 -070011/* What are we trying to accomplish? */
12enum futil_op_type {
13 FUTIL_OP_SHOW,
Bill Richardson15dc6fc2014-09-02 14:45:44 -070014 FUTIL_OP_SIGN,
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070015
16 NUM_FUTIL_OPS
17};
18
19/* What component are we currently handling in the callback routine? */
20enum 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 Richardson6f72ffa2014-09-23 14:40:20 -070035 CB_KERN_PREAMBLE,
36 CB_RAW_FIRMWARE,
37 CB_RAW_KERNEL,
Bill Richardson4805f182015-01-30 22:21:10 -080038 CB_PRIVKEY,
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070039
40 NUM_CB_COMPONENTS
41};
42
43/* Where is the component we're poking at? */
44struct 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? */
52struct futil_traverse_state_s {
Bill Richardson779796f2014-09-23 11:47:40 -070053 /* These two should be initialized by the caller as needed */
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070054 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 Richardsonb0f1cc52014-09-24 00:23:56 -070068
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070069/*
Bill Richardsonb0f1cc52014-09-24 00:23:56 -070070 * 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 */
73int futil_traverse(uint8_t *buf, uint32_t len,
74 struct futil_traverse_state_s *state,
75 enum futil_file_type type_hint);
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070076
77/* These are invoked by the traversal. They also return nonzero on error. */
78int futil_cb_show_begin(struct futil_traverse_state_s *state);
Bill Richardson4805f182015-01-30 22:21:10 -080079int futil_cb_show_pubkey(struct futil_traverse_state_s *state);
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070080int futil_cb_show_gbb(struct futil_traverse_state_s *state);
81int futil_cb_show_keyblock(struct futil_traverse_state_s *state);
82int futil_cb_show_fw_main(struct futil_traverse_state_s *state);
83int futil_cb_show_fw_preamble(struct futil_traverse_state_s *state);
Bill Richardson5f2696d2014-09-23 22:03:56 -070084int futil_cb_show_kernel_preamble(struct futil_traverse_state_s *state);
Bill Richardson4805f182015-01-30 22:21:10 -080085int futil_cb_show_privkey(struct futil_traverse_state_s *state);
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070086
Bill Richardson5f2696d2014-09-23 22:03:56 -070087int futil_cb_sign_pubkey(struct futil_traverse_state_s *state);
Bill Richardson15dc6fc2014-09-02 14:45:44 -070088int futil_cb_sign_fw_main(struct futil_traverse_state_s *state);
Bill Richardson5f2696d2014-09-23 22:03:56 -070089int futil_cb_sign_fw_vblock(struct futil_traverse_state_s *state);
90int futil_cb_sign_raw_firmware(struct futil_traverse_state_s *state);
91int futil_cb_resign_kernel_part(struct futil_traverse_state_s *state);
92int futil_cb_create_kernel_part(struct futil_traverse_state_s *state);
Bill Richardson15dc6fc2014-09-02 14:45:44 -070093int futil_cb_sign_begin(struct futil_traverse_state_s *state);
94int futil_cb_sign_end(struct futil_traverse_state_s *state);
95
96
Bill Richardsoncf6e78d2014-08-27 15:50:25 -070097#endif /* VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ */