xref: /rk3399_rockchip-uboot/include/android_avb/avb_cmdline.h (revision 69fdc5969fe4d637d490fddd72ffd26ea0d356fe)
137a7bc39SJason Zhu /*
237a7bc39SJason Zhu  * Copyright (C) 2016 The Android Open Source Project
337a7bc39SJason Zhu  *
437a7bc39SJason Zhu  * Permission is hereby granted, free of charge, to any person
537a7bc39SJason Zhu  * obtaining a copy of this software and associated documentation
637a7bc39SJason Zhu  * files (the "Software"), to deal in the Software without
737a7bc39SJason Zhu  * restriction, including without limitation the rights to use, copy,
837a7bc39SJason Zhu  * modify, merge, publish, distribute, sublicense, and/or sell copies
937a7bc39SJason Zhu  * of the Software, and to permit persons to whom the Software is
1037a7bc39SJason Zhu  * furnished to do so, subject to the following conditions:
1137a7bc39SJason Zhu  *
1237a7bc39SJason Zhu  * The above copyright notice and this permission notice shall be
1337a7bc39SJason Zhu  * included in all copies or substantial portions of the Software.
1437a7bc39SJason Zhu  *
1537a7bc39SJason Zhu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1637a7bc39SJason Zhu  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1737a7bc39SJason Zhu  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1837a7bc39SJason Zhu  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1937a7bc39SJason Zhu  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2037a7bc39SJason Zhu  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2137a7bc39SJason Zhu  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2237a7bc39SJason Zhu  * SOFTWARE.
2337a7bc39SJason Zhu  */
2437a7bc39SJason Zhu 
2537a7bc39SJason Zhu /*
2637a7bc39SJason Zhu #ifdef AVB_INSIDE_LIBAVB_H
2737a7bc39SJason Zhu #error "You can't include avb_sha.h in the public header libavb.h."
2837a7bc39SJason Zhu #endif
2937a7bc39SJason Zhu */
3037a7bc39SJason Zhu 
3137a7bc39SJason Zhu /*
3237a7bc39SJason Zhu #ifndef AVB_COMPILATION
3337a7bc39SJason Zhu #error "Never include this file, it may only be used from internal avb code."
3437a7bc39SJason Zhu #endif
3537a7bc39SJason Zhu */
3637a7bc39SJason Zhu 
3737a7bc39SJason Zhu #ifndef AVB_CMDLINE_H_
3837a7bc39SJason Zhu #define AVB_CMDLINE_H_
3937a7bc39SJason Zhu 
4037a7bc39SJason Zhu #include <android_avb/avb_ops.h>
4137a7bc39SJason Zhu #include <android_avb/avb_slot_verify.h>
4237a7bc39SJason Zhu 
4337a7bc39SJason Zhu /* Maximum allow length (in bytes) of a partition name, including
4437a7bc39SJason Zhu  * ab_suffix.
4537a7bc39SJason Zhu  */
4637a7bc39SJason Zhu #define AVB_PART_NAME_MAX_SIZE 32
4737a7bc39SJason Zhu 
48ab608f80SJason Zhu #define AVB_MAX_NUM_CMDLINE_SUBST 10
49ab608f80SJason Zhu 
50ab608f80SJason Zhu /* Holds information about command-line substitutions. */
51ab608f80SJason Zhu typedef struct AvbCmdlineSubstList {
52ab608f80SJason Zhu   size_t size;
53ab608f80SJason Zhu   char* tokens[AVB_MAX_NUM_CMDLINE_SUBST];
54ab608f80SJason Zhu   char* values[AVB_MAX_NUM_CMDLINE_SUBST];
55ab608f80SJason Zhu } AvbCmdlineSubstList;
56ab608f80SJason Zhu 
5737a7bc39SJason Zhu /* Substitutes all variables (e.g. $(ANDROID_SYSTEM_PARTUUID)) with
5837a7bc39SJason Zhu  * values. Returns NULL on OOM, otherwise the cmdline with values
5937a7bc39SJason Zhu  * replaced.
6037a7bc39SJason Zhu  */
61ab608f80SJason Zhu char* avb_sub_cmdline(AvbOps* ops,
62ab608f80SJason Zhu                       const char* cmdline,
63ab608f80SJason Zhu                       const char* ab_suffix,
64ab608f80SJason Zhu                       bool using_boot_for_vbmeta,
65ab608f80SJason Zhu                       const AvbCmdlineSubstList* additional_substitutions);
6637a7bc39SJason Zhu 
6737a7bc39SJason Zhu AvbSlotVerifyResult avb_append_options(
6837a7bc39SJason Zhu     AvbOps* ops,
69*69fdc596SJason Zhu     AvbSlotVerifyFlags flags,
7037a7bc39SJason Zhu     AvbSlotVerifyData* slot_data,
7137a7bc39SJason Zhu     AvbVBMetaImageHeader* toplevel_vbmeta,
7237a7bc39SJason Zhu     AvbAlgorithmType algorithm_type,
73*69fdc596SJason Zhu     AvbHashtreeErrorMode hashtree_error_mode,
74*69fdc596SJason Zhu     AvbHashtreeErrorMode resolved_hashtree_error_mode);
7537a7bc39SJason Zhu 
76ab608f80SJason Zhu /* Allocates and initializes a new command line substitution list. Free with
77ab608f80SJason Zhu  * |avb_free_cmdline_subst_list|.
78ab608f80SJason Zhu  */
79ab608f80SJason Zhu AvbCmdlineSubstList* avb_new_cmdline_subst_list(void);
80ab608f80SJason Zhu 
81ab608f80SJason Zhu /* Use this instead of |avb_free| to deallocate a AvbCmdlineSubstList. */
82ab608f80SJason Zhu void avb_free_cmdline_subst_list(AvbCmdlineSubstList* cmdline_subst);
83ab608f80SJason Zhu 
84ab608f80SJason Zhu /* Adds a hashtree root digest to be substituted in $(AVB_*_ROOT_DIGEST)
85ab608f80SJason Zhu  * variables. The partition name differentiates the variable. For example, if
86ab608f80SJason Zhu  * |part_name| is "foo" then $(AVB_FOO_ROOT_DIGEST) will be substituted with the
87ab608f80SJason Zhu  * hex encoding of the digest. The substitution will be added to
88ab608f80SJason Zhu  * |out_cmdline_subst|. Returns AVB_SLOT_VERIFY_RESULT_OK on success.
89ab608f80SJason Zhu  */
90ab608f80SJason Zhu AvbSlotVerifyResult avb_add_root_digest_substitution(
91ab608f80SJason Zhu     const char* part_name,
92ab608f80SJason Zhu     const uint8_t* digest,
93ab608f80SJason Zhu     size_t digest_size,
94ab608f80SJason Zhu     AvbCmdlineSubstList* out_cmdline_subst);
95ab608f80SJason Zhu 
9637a7bc39SJason Zhu #endif
97