blob: 5db9cf9491c85f6c8a98dbf472a52d522ba61695 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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. */
47typedef 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 */
57char *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
63AvbSlotVerifyResult avb_append_options(
64 AvbOps *ops,
65 AvbSlotVerifyData *slot_data,
66 AvbVBMetaImageHeader *toplevel_vbmeta,
67 AvbAlgorithmType algorithm_type,
68 AvbHashtreeErrorMode hashtree_error_mode);
69
70/* Allocates and initializes a new command line substitution list. Free with
71 * |avb_free_cmdline_subst_list|.
72 */
73AvbCmdlineSubstList *avb_new_cmdline_subst_list(void);
74
75/* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */
76void avb_free_cmdline_subst_list(AvbCmdlineSubstList *cmdline_subst);
77
78/* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST)
79 * variables. The partition name differentiates the variable. For example, if
80 * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the
81 * hex encoding of the digest. The substitution will be added to
82 * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success.
83 */
84AvbSlotVerifyResult avb_add_root_digest_substitution(
85 const char *part_name,
86 const uint8_t *digest,
87 size_t digest_size,
88 AvbCmdlineSubstList *out_cmdline_subst);
89
90#endif