1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 #ifdef AVB_INSIDE_LIBAVB_H 26 #error "You can't include avb_sha.h in the public header libavb.h." 27 #endif 28 29 #ifndef AVB_COMPILATION 30 #error "Never include this file, it may only be used from internal avb code." 31 #endif 32 33 #ifndef AVB_CMDLINE_H_ 34 #define AVB_CMDLINE_H_ 35 36 #include "avb_ops.h" 37 #include "avb_slot_verify.h" 38 39 /* Maximum allow length (in bytes) of a partition name, including 40 * ab_suffix. 41 */ 42 #define AVB_PART_NAME_MAX_SIZE 32 43 44 #define AVB_MAX_NUM_CMDLINE_SUBST 10 45 46 /* Holds information about command-line substitutions. */ 47 typedef struct AvbCmdlineSubstList { 48 size_t size; 49 char* tokens[AVB_MAX_NUM_CMDLINE_SUBST]; 50 char* values[AVB_MAX_NUM_CMDLINE_SUBST]; 51 } AvbCmdlineSubstList; 52 53 /* Substitutes all variables (e.g. $(ANDROID_SYSTEM_PARTUUID)) with 54 * values. Returns NULL on OOM, otherwise the cmdline with values 55 * replaced. 56 */ 57 char* avb_sub_cmdline(AvbOps* ops, 58 const char* cmdline, 59 const char* ab_suffix, 60 bool using_boot_for_vbmeta, 61 const AvbCmdlineSubstList* additional_substitutions); 62 63 AvbSlotVerifyResult avb_append_options( 64 AvbOps* ops, 65 AvbSlotVerifyFlags flags, 66 AvbSlotVerifyData* slot_data, 67 AvbVBMetaImageHeader* toplevel_vbmeta, 68 AvbAlgorithmType algorithm_type, 69 AvbHashtreeErrorMode hashtree_error_mode, 70 AvbHashtreeErrorMode resolved_hashtree_error_mode); 71 72 /* Allocates and initializes a new command line substitution list. Free with 73 * |avb_free_cmdline_subst_list|. 74 */ 75 AvbCmdlineSubstList* avb_new_cmdline_subst_list(void); 76 77 /* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */ 78 void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst); 79 80 /* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST) 81 * variables. The partition name differentiates the variable. For example, if 82 * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the 83 * hex encoding of the digest. The substitution will be added to 84 * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success. 85 */ 86 AvbSlotVerifyResult avb_add_root_digest_substitution( 87 const char* part_name, 88 const uint8_t* digest, 89 size_t digest_size, 90 AvbCmdlineSubstList* out_cmdline_subst); 91 92 #endif 93