blob: 9af3a9999423f06c7114c03c923a7dd4b97628b6 [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,
46 AvbSlotVerifyData* slot_data,
47 AvbVBMetaImageHeader* toplevel_vbmeta,
48 AvbAlgorithmType algorithm_type,
49 AvbHashtreeErrorMode hashtree_error_mode);
50
51/* Allocates and initializes a new command line substitution list. Free with
52 * |avb_free_cmdline_subst_list|.
53 */
54AvbCmdlineSubstList* avb_new_cmdline_subst_list(void);
55
56/* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */
57void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst);
58
59/* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST)
60 * variables. The partition name differentiates the variable. For example, if
61 * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the
62 * hex encoding of the digest. The substitution will be added to
63 * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success.
64 */
65AvbSlotVerifyResult avb_add_root_digest_substitution(
66 const char* part_name,
67 const uint8_t* digest,
68 size_t digest_size,
69 AvbCmdlineSubstList* out_cmdline_subst);
70
71#endif