137a7bc39SJason Zhu /* 237a7bc39SJason Zhu * Copyright (C) 2016 The Android Open Source Project 337a7bc39SJason Zhu * 437a7bc39SJason Zhu * Permission is hereby granted, free of charge, to any person 537a7bc39SJason Zhu * obtaining a copy of this software and associated documentation 637a7bc39SJason Zhu * files (the "Software"), to deal in the Software without 737a7bc39SJason Zhu * restriction, including without limitation the rights to use, copy, 837a7bc39SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 937a7bc39SJason Zhu * of the Software, and to permit persons to whom the Software is 1037a7bc39SJason Zhu * furnished to do so, subject to the following conditions: 1137a7bc39SJason Zhu * 1237a7bc39SJason Zhu * The above copyright notice and this permission notice shall be 1337a7bc39SJason Zhu * included in all copies or substantial portions of the Software. 1437a7bc39SJason Zhu * 1537a7bc39SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1637a7bc39SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1737a7bc39SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1837a7bc39SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 1937a7bc39SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 2037a7bc39SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2137a7bc39SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2237a7bc39SJason Zhu * SOFTWARE. 2337a7bc39SJason Zhu */ 2437a7bc39SJason Zhu 2537a7bc39SJason Zhu /* 2637a7bc39SJason Zhu #ifdef AVB_INSIDE_LIBAVB_H 2737a7bc39SJason Zhu #error "You can't include avb_sha.h in the public header libavb.h." 2837a7bc39SJason Zhu #endif 2937a7bc39SJason Zhu */ 3037a7bc39SJason Zhu 3137a7bc39SJason Zhu /* 3237a7bc39SJason Zhu #ifndef AVB_COMPILATION 3337a7bc39SJason Zhu #error "Never include this file, it may only be used from internal avb code." 3437a7bc39SJason Zhu #endif 3537a7bc39SJason Zhu */ 3637a7bc39SJason Zhu 3737a7bc39SJason Zhu #ifndef AVB_CMDLINE_H_ 3837a7bc39SJason Zhu #define AVB_CMDLINE_H_ 3937a7bc39SJason Zhu 4037a7bc39SJason Zhu #include <android_avb/avb_ops.h> 4137a7bc39SJason Zhu #include <android_avb/avb_slot_verify.h> 4237a7bc39SJason Zhu 4337a7bc39SJason Zhu /* Maximum allow length (in bytes) of a partition name, including 4437a7bc39SJason Zhu * ab_suffix. 4537a7bc39SJason Zhu */ 4637a7bc39SJason Zhu #define AVB_PART_NAME_MAX_SIZE 32 4737a7bc39SJason Zhu 48*ab608f80SJason Zhu #define AVB_MAX_NUM_CMDLINE_SUBST 10 49*ab608f80SJason Zhu 50*ab608f80SJason Zhu /* Holds information about command-line substitutions. */ 51*ab608f80SJason Zhu typedef struct AvbCmdlineSubstList { 52*ab608f80SJason Zhu size_t size; 53*ab608f80SJason Zhu char* tokens[AVB_MAX_NUM_CMDLINE_SUBST]; 54*ab608f80SJason Zhu char* values[AVB_MAX_NUM_CMDLINE_SUBST]; 55*ab608f80SJason Zhu } AvbCmdlineSubstList; 56*ab608f80SJason Zhu 5737a7bc39SJason Zhu /* Substitutes all variables (e.g. $(ANDROID_SYSTEM_PARTUUID)) with 5837a7bc39SJason Zhu * values. Returns NULL on OOM, otherwise the cmdline with values 5937a7bc39SJason Zhu * replaced. 6037a7bc39SJason Zhu */ 61*ab608f80SJason Zhu char* avb_sub_cmdline(AvbOps* ops, 62*ab608f80SJason Zhu const char* cmdline, 63*ab608f80SJason Zhu const char* ab_suffix, 64*ab608f80SJason Zhu bool using_boot_for_vbmeta, 65*ab608f80SJason Zhu const AvbCmdlineSubstList* additional_substitutions); 6637a7bc39SJason Zhu 6737a7bc39SJason Zhu AvbSlotVerifyResult avb_append_options( 6837a7bc39SJason Zhu AvbOps* ops, 6937a7bc39SJason Zhu AvbSlotVerifyData* slot_data, 7037a7bc39SJason Zhu AvbVBMetaImageHeader* toplevel_vbmeta, 7137a7bc39SJason Zhu AvbAlgorithmType algorithm_type, 7237a7bc39SJason Zhu AvbHashtreeErrorMode hashtree_error_mode); 7337a7bc39SJason Zhu 74*ab608f80SJason Zhu /* Allocates and initializes a new command line substitution list. Free with 75*ab608f80SJason Zhu * |avb_free_cmdline_subst_list|. 76*ab608f80SJason Zhu */ 77*ab608f80SJason Zhu AvbCmdlineSubstList* avb_new_cmdline_subst_list(void); 78*ab608f80SJason Zhu 79*ab608f80SJason Zhu /* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */ 80*ab608f80SJason Zhu void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst); 81*ab608f80SJason Zhu 82*ab608f80SJason Zhu /* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST) 83*ab608f80SJason Zhu * variables. The partition name differentiates the variable. For example, if 84*ab608f80SJason Zhu * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the 85*ab608f80SJason Zhu * hex encoding of the digest. The substitution will be added to 86*ab608f80SJason Zhu * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success. 87*ab608f80SJason Zhu */ 88*ab608f80SJason Zhu AvbSlotVerifyResult avb_add_root_digest_substitution( 89*ab608f80SJason Zhu const char* part_name, 90*ab608f80SJason Zhu const uint8_t* digest, 91*ab608f80SJason Zhu size_t digest_size, 92*ab608f80SJason Zhu AvbCmdlineSubstList* out_cmdline_subst); 93*ab608f80SJason Zhu 9437a7bc39SJason Zhu #endif 95