xref: /rk3399_rockchip-uboot/include/android_avb/avb_sysdeps.h (revision 331c2375688d79920fb06b8f0c4c52a7df56fb29)
1 /*
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 /*
26 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
27 #error "Never include this file directly, include libavb.h instead."
28 #endif
29 */
30 
31 #ifndef AVB_SYSDEPS_H_
32 #define AVB_SYSDEPS_H_
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Change these includes to match your platform to bring in the
39  * equivalent types available in a normal C runtime. At least things
40  * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
41  * must be present.
42  */
43 #include <inttypes.h>
44 #include <stdbool.h>
45 #include <stddef.h>
46 #ifdef CONFIG_USE_STDINT
47 /* Provided by gcc. */
48 #include <stdint.h>
49 #else
50 /* Type for `void *' pointers. */
51 typedef unsigned long int uintptr_t;
52 #endif
53 
54 /* If you don't have gcc or clang, these attribute macros may need to
55  * be adjusted.
56  */
57 #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
58 #define AVB_ATTR_PACKED __attribute__((packed))
59 #define AVB_ATTR_NO_RETURN __attribute__((noreturn))
60 #define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
61 
62 /* Size in bytes used for alignment. */
63 #ifdef __LP64__
64 #define AVB_ALIGNMENT_SIZE 8
65 #else
66 #define AVB_ALIGNMENT_SIZE 4
67 #endif
68 
69 /* Compare |n| bytes in |src1| and |src2|.
70  *
71  * Returns an integer less than, equal to, or greater than zero if the
72  * first |n| bytes of |src1| is found, respectively, to be less than,
73  * to match, or be greater than the first |n| bytes of |src2|. */
74 int avb_memcmp(const void* src1,
75                const void* src2,
76                size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
77 
78 /* Compare two strings.
79  *
80  * Return an integer less than, equal to, or greater than zero if |s1|
81  * is found, respectively, to be less than, to match, or be greater
82  * than |s2|.
83  */
84 int avb_strcmp(const char* s1, const char* s2);
85 
86 /* Copy |n| bytes from |src| to |dest|. */
87 void* avb_memcpy(void* dest, const void* src, size_t n);
88 
89 /* Set |n| bytes starting at |s| to |c|.  Returns |dest|. */
90 void* avb_memset(void* dest, const int c, size_t n);
91 
92 /* Prints out a message. The string passed must be a NUL-terminated
93  * UTF-8 string.
94  */
95 void avb_print(const char* message);
96 
97 /* Prints out a vector of strings. Each argument must point to a
98  * NUL-terminated UTF-8 string and NULL should be the last argument.
99  */
100 void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
101 
102 /* Aborts the program or reboots the device. */
103 void avb_abort(void);
104 
105 /* Allocates |size| bytes. Returns NULL if no memory is available,
106  * otherwise a pointer to the allocated memory.
107  *
108  * The memory is not initialized.
109  *
110  * The pointer returned is guaranteed to be word-aligned.
111  *
112  * The memory should be freed with avb_free() when you are done with it.
113  */
114 void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
115 
116 /* Frees memory previously allocated with avb_malloc(). */
117 void avb_free(void* ptr);
118 
119 /* Returns the lenght of |str|, excluding the terminating NUL-byte. */
120 size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
121 
122 /* Divide the |dividend| by 10 and saves back to the pointer. Return the
123  * remainder. */
124 uint32_t avb_div_by_10(uint64_t* dividend);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif /* AVB_SYSDEPS_H_ */
131