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