Home | History | Annotate | Download | only in futility
      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 
     11 /* What are we trying to accomplish? */
     12 enum futil_op_type {
     13 	FUTIL_OP_SHOW,
     14 	FUTIL_OP_SIGN,
     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,
     35 	CB_KERN_PREAMBLE,
     36 	CB_RAW_FIRMWARE,
     37 	CB_RAW_KERNEL,
     38 	CB_PRIVKEY,
     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 {
     53 	/* These two should be initialized by the caller as needed */
     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 
     68 
     69 /*
     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);
     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);
     79 int futil_cb_show_pubkey(struct futil_traverse_state_s *state);
     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);
     84 int futil_cb_show_kernel_preamble(struct futil_traverse_state_s *state);
     85 int futil_cb_show_privkey(struct futil_traverse_state_s *state);
     86 
     87 int futil_cb_sign_pubkey(struct futil_traverse_state_s *state);
     88 int futil_cb_sign_fw_main(struct futil_traverse_state_s *state);
     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);
     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 
     97 #endif /* VBOOT_REFERENCE_FUTILITY_TRAVERSAL_H_ */
     98