blob: 96539d84bddfd0c99f417c4cfc0e213a4748b9b1 [file] [log] [blame]
Tom Rini897a1d92018-06-19 11:21:44 -04001/* SPDX-License-Identifier: MIT */
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +03002/*
3 * Copyright (C) 2016 The Android Open Source Project
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +03004 */
5
6#ifdef AVB_INSIDE_LIBAVB_H
7#error "You can't include avb_sha.h in the public header libavb.h."
8#endif
9
10#ifndef AVB_COMPILATION
11#error "Never include this file, it may only be used from internal avb code."
12#endif
13
14#ifndef AVB_CMDLINE_H_
15#define AVB_CMDLINE_H_
16
17#include "avb_ops.h"
18#include "avb_slot_verify.h"
19
20/* Maximum allow length (in bytes) of a partition name, including
21 * ab_suffix.
22 */
23#define AVB_PART_NAME_MAX_SIZE 32
24
25#define AVB_MAX_NUM_CMDLINE_SUBST 10
26
27/* Holds information about command-line substitutions. */
28typedef struct AvbCmdlineSubstList {
29 size_t size;
30 char* tokens[AVB_MAX_NUM_CMDLINE_SUBST];
31 char* values[AVB_MAX_NUM_CMDLINE_SUBST];
32} AvbCmdlineSubstList;
33
34/* Substitutes all variables (e.g. $(ANDROID_SYSTEM_PARTUUID)) with
35 * values. Returns NULL on OOM, otherwise the cmdline with values
36 * replaced.
37 */
38char* avb_sub_cmdline(AvbOps* ops,
39 const char* cmdline,
40 const char* ab_suffix,
41 bool using_boot_for_vbmeta,
42 const AvbCmdlineSubstList* additional_substitutions);
43
44AvbSlotVerifyResult avb_append_options(
45 AvbOps* ops,
Sam Protsenko4d579a42019-08-15 23:04:02 +030046 AvbSlotVerifyFlags flags,
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +030047 AvbSlotVerifyData* slot_data,
48 AvbVBMetaImageHeader* toplevel_vbmeta,
49 AvbAlgorithmType algorithm_type,
Sam Protsenko4d579a42019-08-15 23:04:02 +030050 AvbHashtreeErrorMode hashtree_error_mode,
51 AvbHashtreeErrorMode resolved_hashtree_error_mode);
Igor Opaniukd8f9d2a2018-06-03 21:56:36 +030052
53/* Allocates and initializes a new command line substitution list. Free with
54 * |avb_free_cmdline_subst_list|.
55 */
56AvbCmdlineSubstList* avb_new_cmdline_subst_list(void);
57
58/* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */
59void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst);
60
61/* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST)
62 * variables. The partition name differentiates the variable. For example, if
63 * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the
64 * hex encoding of the digest. The substitution will be added to
65 * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success.
66 */
67AvbSlotVerifyResult avb_add_root_digest_substitution(
68 const char* part_name,
69 const uint8_t* digest,
70 size_t digest_size,
71 AvbCmdlineSubstList* out_cmdline_subst);
72
73#endif