xref: /rk3399_rockchip-uboot/include/android_avb/avb_sysdeps.h (revision 5b69db0720b90f33ecb7fb666b196bfc90404185)
1*5b69db07SJason Zhu /*
2*5b69db07SJason Zhu  * Copyright (C) 2016 The Android Open Source Project
3*5b69db07SJason Zhu  *
4*5b69db07SJason Zhu  * Permission is hereby granted, free of charge, to any person
5*5b69db07SJason Zhu  * obtaining a copy of this software and associated documentation
6*5b69db07SJason Zhu  * files (the "Software"), to deal in the Software without
7*5b69db07SJason Zhu  * restriction, including without limitation the rights to use, copy,
8*5b69db07SJason Zhu  * modify, merge, publish, distribute, sublicense, and/or sell copies
9*5b69db07SJason Zhu  * of the Software, and to permit persons to whom the Software is
10*5b69db07SJason Zhu  * furnished to do so, subject to the following conditions:
11*5b69db07SJason Zhu  *
12*5b69db07SJason Zhu  * The above copyright notice and this permission notice shall be
13*5b69db07SJason Zhu  * included in all copies or substantial portions of the Software.
14*5b69db07SJason Zhu  *
15*5b69db07SJason Zhu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*5b69db07SJason Zhu  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*5b69db07SJason Zhu  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*5b69db07SJason Zhu  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19*5b69db07SJason Zhu  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20*5b69db07SJason Zhu  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21*5b69db07SJason Zhu  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*5b69db07SJason Zhu  * SOFTWARE.
23*5b69db07SJason Zhu  */
24*5b69db07SJason Zhu 
25*5b69db07SJason Zhu /*
26*5b69db07SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
27*5b69db07SJason Zhu #error "Never include this file directly, include libavb.h instead."
28*5b69db07SJason Zhu #endif
29*5b69db07SJason Zhu */
30*5b69db07SJason Zhu 
31*5b69db07SJason Zhu #ifndef AVB_SYSDEPS_H_
32*5b69db07SJason Zhu #define AVB_SYSDEPS_H_
33*5b69db07SJason Zhu 
34*5b69db07SJason Zhu #ifdef __cplusplus
35*5b69db07SJason Zhu extern "C" {
36*5b69db07SJason Zhu #endif
37*5b69db07SJason Zhu 
38*5b69db07SJason Zhu /* Change these includes to match your platform to bring in the
39*5b69db07SJason Zhu  * equivalent types available in a normal C runtime. At least things
40*5b69db07SJason Zhu  * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
41*5b69db07SJason Zhu  * must be present.
42*5b69db07SJason Zhu  */
43*5b69db07SJason Zhu #include <inttypes.h>
44*5b69db07SJason Zhu #include <stdbool.h>
45*5b69db07SJason Zhu #include <stddef.h>
46*5b69db07SJason Zhu #ifdef CONFIG_USE_STDINT
47*5b69db07SJason Zhu /* Provided by gcc. */
48*5b69db07SJason Zhu #include <stdint.h>
49*5b69db07SJason Zhu #else
50*5b69db07SJason Zhu /* Type for `void *' pointers. */
51*5b69db07SJason Zhu typedef unsigned long int uintptr_t;
52*5b69db07SJason Zhu #endif
53*5b69db07SJason Zhu 
54*5b69db07SJason Zhu /* If you don't have gcc or clang, these attribute macros may need to
55*5b69db07SJason Zhu  * be adjusted.
56*5b69db07SJason Zhu  */
57*5b69db07SJason Zhu #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
58*5b69db07SJason Zhu #define AVB_ATTR_PACKED __attribute__((packed))
59*5b69db07SJason Zhu #define AVB_ATTR_NO_RETURN __attribute__((noreturn))
60*5b69db07SJason Zhu #define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
61*5b69db07SJason Zhu 
62*5b69db07SJason Zhu /* Size in bytes used for alignment. */
63*5b69db07SJason Zhu #ifdef __LP64__
64*5b69db07SJason Zhu #define AVB_ALIGNMENT_SIZE 8
65*5b69db07SJason Zhu #else
66*5b69db07SJason Zhu #define AVB_ALIGNMENT_SIZE 4
67*5b69db07SJason Zhu #endif
68*5b69db07SJason Zhu 
69*5b69db07SJason Zhu /* Compare |n| bytes in |src1| and |src2|.
70*5b69db07SJason Zhu  *
71*5b69db07SJason Zhu  * Returns an integer less than, equal to, or greater than zero if the
72*5b69db07SJason Zhu  * first |n| bytes of |src1| is found, respectively, to be less than,
73*5b69db07SJason Zhu  * to match, or be greater than the first |n| bytes of |src2|. */
74*5b69db07SJason Zhu int avb_memcmp(const void* src1,
75*5b69db07SJason Zhu                const void* src2,
76*5b69db07SJason Zhu                size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
77*5b69db07SJason Zhu 
78*5b69db07SJason Zhu /* Compare two strings.
79*5b69db07SJason Zhu  *
80*5b69db07SJason Zhu  * Return an integer less than, equal to, or greater than zero if |s1|
81*5b69db07SJason Zhu  * is found, respectively, to be less than, to match, or be greater
82*5b69db07SJason Zhu  * than |s2|.
83*5b69db07SJason Zhu  */
84*5b69db07SJason Zhu int avb_strcmp(const char* s1, const char* s2);
85*5b69db07SJason Zhu 
86*5b69db07SJason Zhu /* Copy |n| bytes from |src| to |dest|. */
87*5b69db07SJason Zhu void* avb_memcpy(void* dest, const void* src, size_t n);
88*5b69db07SJason Zhu 
89*5b69db07SJason Zhu /* Set |n| bytes starting at |s| to |c|.  Returns |dest|. */
90*5b69db07SJason Zhu void* avb_memset(void* dest, const int c, size_t n);
91*5b69db07SJason Zhu 
92*5b69db07SJason Zhu /* Prints out a message. The string passed must be a NUL-terminated
93*5b69db07SJason Zhu  * UTF-8 string.
94*5b69db07SJason Zhu  */
95*5b69db07SJason Zhu void avb_print(const char* message);
96*5b69db07SJason Zhu 
97*5b69db07SJason Zhu /* Prints out a vector of strings. Each argument must point to a
98*5b69db07SJason Zhu  * NUL-terminated UTF-8 string and NULL should be the last argument.
99*5b69db07SJason Zhu  */
100*5b69db07SJason Zhu void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
101*5b69db07SJason Zhu 
102*5b69db07SJason Zhu /* Aborts the program or reboots the device. */
103*5b69db07SJason Zhu void avb_abort(void) AVB_ATTR_NO_RETURN;
104*5b69db07SJason Zhu 
105*5b69db07SJason Zhu /* Allocates |size| bytes. Returns NULL if no memory is available,
106*5b69db07SJason Zhu  * otherwise a pointer to the allocated memory.
107*5b69db07SJason Zhu  *
108*5b69db07SJason Zhu  * The memory is not initialized.
109*5b69db07SJason Zhu  *
110*5b69db07SJason Zhu  * The pointer returned is guaranteed to be word-aligned.
111*5b69db07SJason Zhu  *
112*5b69db07SJason Zhu  * The memory should be freed with avb_free() when you are done with it.
113*5b69db07SJason Zhu  */
114*5b69db07SJason Zhu void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
115*5b69db07SJason Zhu 
116*5b69db07SJason Zhu /* Frees memory previously allocated with avb_malloc(). */
117*5b69db07SJason Zhu void avb_free(void* ptr);
118*5b69db07SJason Zhu 
119*5b69db07SJason Zhu /* Returns the lenght of |str|, excluding the terminating NUL-byte. */
120*5b69db07SJason Zhu size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
121*5b69db07SJason Zhu 
122*5b69db07SJason Zhu #ifdef __cplusplus
123*5b69db07SJason Zhu }
124*5b69db07SJason Zhu #endif
125*5b69db07SJason Zhu 
126*5b69db07SJason Zhu #endif /* AVB_SYSDEPS_H_ */
127