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