xref: /OK3568_Linux_fs/u-boot/include/android_avb/avb_cmdline.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 /*
26 #ifdef AVB_INSIDE_LIBAVB_H
27 #error "You can't include avb_sha.h in the public header libavb.h."
28 #endif
29 */
30 
31 /*
32 #ifndef AVB_COMPILATION
33 #error "Never include this file, it may only be used from internal avb code."
34 #endif
35 */
36 
37 #ifndef AVB_CMDLINE_H_
38 #define AVB_CMDLINE_H_
39 
40 #include <android_avb/avb_ops.h>
41 #include <android_avb/avb_slot_verify.h>
42 
43 /* Maximum allow length (in bytes) of a partition name, including
44  * ab_suffix.
45  */
46 #define AVB_PART_NAME_MAX_SIZE 32
47 
48 #define AVB_MAX_NUM_CMDLINE_SUBST 10
49 
50 /* Holds information about command-line substitutions. */
51 typedef struct AvbCmdlineSubstList {
52   size_t size;
53   char* tokens[AVB_MAX_NUM_CMDLINE_SUBST];
54   char* values[AVB_MAX_NUM_CMDLINE_SUBST];
55 } AvbCmdlineSubstList;
56 
57 /* Substitutes all variables (e.g. $(ANDROID_SYSTEM_PARTUUID)) with
58  * values. Returns NULL on OOM, otherwise the cmdline with values
59  * replaced.
60  */
61 char* avb_sub_cmdline(AvbOps* ops,
62                       const char* cmdline,
63                       const char* ab_suffix,
64                       bool using_boot_for_vbmeta,
65                       const AvbCmdlineSubstList* additional_substitutions);
66 
67 AvbSlotVerifyResult avb_append_options(
68     AvbOps* ops,
69     AvbSlotVerifyFlags flags,
70     AvbSlotVerifyData* slot_data,
71     AvbVBMetaImageHeader* toplevel_vbmeta,
72     AvbAlgorithmType algorithm_type,
73     AvbHashtreeErrorMode hashtree_error_mode,
74     AvbHashtreeErrorMode resolved_hashtree_error_mode);
75 
76 /* Allocates and initializes a new command line substitution list. Free with
77  * |avb_free_cmdline_subst_list|.
78  */
79 AvbCmdlineSubstList* avb_new_cmdline_subst_list(void);
80 
81 /* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */
82 void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst);
83 
84 /* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST)
85  * variables. The partition name differentiates the variable. For example, if
86  * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the
87  * hex encoding of the digest. The substitution will be added to
88  * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success.
89  */
90 AvbSlotVerifyResult avb_add_root_digest_substitution(
91     const char* part_name,
92     const uint8_t* digest,
93     size_t digest_size,
94     AvbCmdlineSubstList* out_cmdline_subst);
95 
96 #endif
97