Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 2 | /* |
Simon Glass | 3196d75 | 2012-02-20 23:56:58 -0500 | [diff] [blame] | 3 | * Operating System Interface |
| 4 | * |
| 5 | * This provides access to useful OS routines for the sandbox architecture. |
| 6 | * They are kept in a separate file so we can include system headers. |
| 7 | * |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 8 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mike Frysinger | 999a579 | 2012-01-19 22:57:29 -0500 | [diff] [blame] | 11 | #ifndef __OS_H__ |
| 12 | #define __OS_H__ |
| 13 | |
Simon Glass | fb4b4e8 | 2013-05-19 16:45:35 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | |
Simon Glass | 504548f | 2015-04-20 12:37:22 -0600 | [diff] [blame] | 16 | struct rtc_time; |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 17 | struct sandbox_state; |
| 18 | |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 19 | /** |
| 20 | * Access to the OS read() system call |
| 21 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 22 | * @fd: File descriptor as returned by os_open() |
| 23 | * @buf: Buffer to place data |
| 24 | * @count: Number of bytes to read |
| 25 | * Return: number of bytes read, or -1 on error |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 26 | */ |
| 27 | ssize_t os_read(int fd, void *buf, size_t count); |
| 28 | |
| 29 | /** |
| 30 | * Access to the OS write() system call |
| 31 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 32 | * @fd: File descriptor as returned by os_open() |
| 33 | * @buf: Buffer containing data to write |
| 34 | * @count: Number of bytes to write |
| 35 | * Return: number of bytes written, or -1 on error |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 36 | */ |
| 37 | ssize_t os_write(int fd, const void *buf, size_t count); |
| 38 | |
| 39 | /** |
Mike Frysinger | 60addac | 2011-10-25 13:02:58 +0200 | [diff] [blame] | 40 | * Access to the OS lseek() system call |
| 41 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 42 | * @fd: File descriptor as returned by os_open() |
| 43 | * @offset: File offset (based on whence) |
| 44 | * @whence: Position offset is relative to (see below) |
| 45 | * Return: new file offset |
Mike Frysinger | 60addac | 2011-10-25 13:02:58 +0200 | [diff] [blame] | 46 | */ |
| 47 | off_t os_lseek(int fd, off_t offset, int whence); |
| 48 | |
| 49 | /* Defines for "whence" in os_lseek() */ |
| 50 | #define OS_SEEK_SET 0 |
| 51 | #define OS_SEEK_CUR 1 |
| 52 | #define OS_SEEK_END 2 |
| 53 | |
| 54 | /** |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 55 | * Access to the OS open() system call |
| 56 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 57 | * @pathname: Pathname of file to open |
| 58 | * @flags: Flags, like OS_O_RDONLY, OS_O_RDWR |
| 59 | * Return: file descriptor, or -1 on error |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 60 | */ |
| 61 | int os_open(const char *pathname, int flags); |
| 62 | |
Simon Glass | 3196d75 | 2012-02-20 23:56:58 -0500 | [diff] [blame] | 63 | #define OS_O_RDONLY 0 |
| 64 | #define OS_O_WRONLY 1 |
| 65 | #define OS_O_RDWR 2 |
| 66 | #define OS_O_MASK 3 /* Mask for read/write flags */ |
| 67 | #define OS_O_CREAT 0100 |
Simon Glass | ce55a11 | 2018-10-01 11:55:07 -0600 | [diff] [blame] | 68 | #define OS_O_TRUNC 01000 |
Simon Glass | 3196d75 | 2012-02-20 23:56:58 -0500 | [diff] [blame] | 69 | |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 70 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 71 | * os_close() - access to the OS close() system call |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 72 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 73 | * @fd: File descriptor to close |
| 74 | * Return: 0 on success, -1 on error |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 75 | */ |
| 76 | int os_close(int fd); |
| 77 | |
| 78 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 79 | * os_unlink() - access to the OS unlink() system call |
Stephen Warren | cd5edba | 2014-03-01 22:18:00 -0700 | [diff] [blame] | 80 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 81 | * @pathname: Path of file to delete |
| 82 | * Return: 0 for success, other for error |
Stephen Warren | cd5edba | 2014-03-01 22:18:00 -0700 | [diff] [blame] | 83 | */ |
| 84 | int os_unlink(const char *pathname); |
| 85 | |
| 86 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 87 | * os_exit() - access to the OS exit() system call |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 88 | * |
| 89 | * This exits with the supplied return code, which should be 0 to indicate |
| 90 | * success. |
| 91 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 92 | * @exit_code: exit code for U-Boot |
Simon Glass | cd0684f | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 93 | */ |
Mike Frysinger | bc036d3 | 2012-02-26 17:46:30 -0500 | [diff] [blame] | 94 | void os_exit(int exit_code) __attribute__((noreturn)); |
Mike Frysinger | a5baaee | 2011-10-26 00:21:29 +0000 | [diff] [blame] | 95 | |
| 96 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 97 | * os_tty_raw() - put tty into raw mode to mimic serial console better |
Simon Glass | 678ef47 | 2014-02-27 13:26:22 -0700 | [diff] [blame] | 98 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 99 | * @fd: File descriptor of stdin (normally 0) |
| 100 | * @allow_sigs: Allow Ctrl-C, Ctrl-Z to generate signals rather than |
| 101 | * be handled by U-Boot |
Mike Frysinger | a5baaee | 2011-10-26 00:21:29 +0000 | [diff] [blame] | 102 | */ |
Simon Glass | 678ef47 | 2014-02-27 13:26:22 -0700 | [diff] [blame] | 103 | void os_tty_raw(int fd, bool allow_sigs); |
Matthias Weisser | b5f7b47 | 2011-11-05 11:40:34 +0100 | [diff] [blame] | 104 | |
| 105 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 106 | * os_fs_restore() - restore the tty to its original mode |
Simon Glass | 9c3b7d6 | 2015-05-10 21:07:27 -0600 | [diff] [blame] | 107 | * |
| 108 | * Call this to restore the original terminal mode, after it has been changed |
| 109 | * by os_tty_raw(). This is an internal function. |
| 110 | */ |
| 111 | void os_fd_restore(void); |
| 112 | |
| 113 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 114 | * os_malloc() - aquires some memory from the underlying os. |
Matthias Weisser | b5f7b47 | 2011-11-05 11:40:34 +0100 | [diff] [blame] | 115 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 116 | * @length: Number of bytes to be allocated |
| 117 | * Return: Pointer to length bytes or NULL on error |
Matthias Weisser | b5f7b47 | 2011-11-05 11:40:34 +0100 | [diff] [blame] | 118 | */ |
| 119 | void *os_malloc(size_t length); |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 120 | |
| 121 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 122 | * os_free() - free memory previous allocated with os_malloc() |
Simon Glass | 1e6594c | 2013-11-10 10:26:57 -0700 | [diff] [blame] | 123 | * |
| 124 | * This returns the memory to the OS. |
| 125 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 126 | * @ptr: Pointer to memory block to free |
Simon Glass | 1e6594c | 2013-11-10 10:26:57 -0700 | [diff] [blame] | 127 | */ |
Masahiro Yamada | ee95728 | 2014-01-15 13:06:41 +0900 | [diff] [blame] | 128 | void os_free(void *ptr); |
Simon Glass | 1e6594c | 2013-11-10 10:26:57 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 131 | * os_usleep() - access to the usleep function of the os |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 132 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 133 | * @usec: time to sleep in micro seconds |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 134 | */ |
| 135 | void os_usleep(unsigned long usec); |
| 136 | |
| 137 | /** |
| 138 | * Gets a monotonic increasing number of nano seconds from the OS |
| 139 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 140 | * Return: a monotonic increasing time scaled in nano seconds |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 141 | */ |
Simon Glass | fb4b4e8 | 2013-05-19 16:45:35 -0700 | [diff] [blame] | 142 | uint64_t os_get_nsec(void); |
Mike Frysinger | 999a579 | 2012-01-19 22:57:29 -0500 | [diff] [blame] | 143 | |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 144 | /** |
| 145 | * Parse arguments and update sandbox state. |
| 146 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 147 | * @state: sandbox state to update |
| 148 | * @argc: argument count |
| 149 | * @argv: argument vector |
| 150 | * Return: |
| 151 | * * 0 if ok, and program should continue |
| 152 | * * 1 if ok, but program should stop |
| 153 | * * -1 on error: program should terminate |
Simon Glass | 8a3e035 | 2012-02-15 15:51:16 -0800 | [diff] [blame] | 154 | */ |
| 155 | int os_parse_args(struct sandbox_state *state, int argc, char *argv[]); |
| 156 | |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 157 | /* |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 158 | * enum os_dirent_t - type of directory entry |
| 159 | * |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 160 | * Types of directory entry that we support. See also os_dirent_typename in |
| 161 | * the C file. |
| 162 | */ |
| 163 | enum os_dirent_t { |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 164 | /** |
| 165 | * @OS_FILET_REG: regular file |
| 166 | */ |
| 167 | OS_FILET_REG, |
| 168 | /** |
| 169 | * @OS_FILET_LNK: symbolic link |
| 170 | */ |
| 171 | OS_FILET_LNK, |
| 172 | /** |
| 173 | * @OS_FILET_DIR: directory |
| 174 | */ |
| 175 | OS_FILET_DIR, |
| 176 | /** |
| 177 | * @OS_FILET_UNKNOWN: something else |
| 178 | */ |
| 179 | OS_FILET_UNKNOWN, |
| 180 | /** |
| 181 | * @OS_FILET_COUNT: number of directory entry types |
| 182 | */ |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 183 | OS_FILET_COUNT, |
| 184 | }; |
| 185 | |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 186 | /** |
| 187 | * struct os_dirent_node - directory node |
| 188 | * |
| 189 | * A directory entry node, containing information about a single dirent |
| 190 | * |
| 191 | */ |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 192 | struct os_dirent_node { |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 193 | /** |
| 194 | * @next: pointer to next node, or NULL |
| 195 | */ |
| 196 | struct os_dirent_node *next; |
| 197 | /** |
| 198 | * @size: size of file in bytes |
| 199 | */ |
| 200 | ulong size; |
| 201 | /** |
| 202 | * @type: type of entry |
| 203 | */ |
| 204 | enum os_dirent_t type; |
| 205 | /** |
| 206 | * @name: name of entry |
| 207 | */ |
| 208 | char name[0]; |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 212 | * os_dirent_ls() - get a directory listing |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 213 | * |
| 214 | * This allocates and returns a linked list containing the directory listing. |
| 215 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 216 | * @dirname: directory to examine |
| 217 | * @headp: on return pointer to head of linked list, or NULL if none |
| 218 | * Return: 0 if ok, -ve on error |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 219 | */ |
| 220 | int os_dirent_ls(const char *dirname, struct os_dirent_node **headp); |
| 221 | |
| 222 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 223 | * os_dirent_free() - free directory list |
Stefan Brüns | e058284 | 2016-10-01 20:41:38 +0200 | [diff] [blame] | 224 | * |
| 225 | * This frees a linked list containing a directory listing. |
| 226 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 227 | * @node: pointer to head of linked list |
Stefan Brüns | e058284 | 2016-10-01 20:41:38 +0200 | [diff] [blame] | 228 | */ |
| 229 | void os_dirent_free(struct os_dirent_node *node); |
| 230 | |
| 231 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 232 | * os_dirent_get_typename() - get the name of a directory entry type |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 233 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 234 | * @type: type to check |
| 235 | * Return: |
| 236 | * string containing the name of that type, |
| 237 | * or "???" if none/invalid |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 238 | */ |
| 239 | const char *os_dirent_get_typename(enum os_dirent_t type); |
| 240 | |
| 241 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 242 | * os_get_filesize() - get the size of a file |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 243 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 244 | * @fname: filename to check |
| 245 | * @size: size of file is returned if no error |
| 246 | * Return: 0 on success or -1 if an error ocurred |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 247 | */ |
Suriyan Ramasami | 378da103 | 2014-11-17 14:39:37 -0800 | [diff] [blame] | 248 | int os_get_filesize(const char *fname, loff_t *size); |
Simon Glass | f1c45c8 | 2012-12-26 09:53:34 +0000 | [diff] [blame] | 249 | |
Simon Glass | 3e9fd24 | 2013-11-10 10:27:01 -0700 | [diff] [blame] | 250 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 251 | * os_putc() - write a character to the controlling OS terminal |
Simon Glass | 29d1143 | 2017-12-04 13:48:17 -0700 | [diff] [blame] | 252 | * |
| 253 | * This bypasses the U-Boot console support and writes directly to the OS |
| 254 | * stdout file descriptor. |
| 255 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 256 | * @ch: haracter to write |
Simon Glass | 29d1143 | 2017-12-04 13:48:17 -0700 | [diff] [blame] | 257 | */ |
| 258 | void os_putc(int ch); |
| 259 | |
| 260 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 261 | * os_puts() - write a string to the controlling OS terminal |
Simon Glass | 29d1143 | 2017-12-04 13:48:17 -0700 | [diff] [blame] | 262 | * |
| 263 | * This bypasses the U-Boot console support and writes directly to the OS |
| 264 | * stdout file descriptor. |
| 265 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 266 | * @str: string to write (note that \n is not appended) |
Simon Glass | 29d1143 | 2017-12-04 13:48:17 -0700 | [diff] [blame] | 267 | */ |
| 268 | void os_puts(const char *str); |
| 269 | |
| 270 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 271 | * os_write_ram_buf() - write the sandbox RAM buffer to a existing file |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 272 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 273 | * @fname: filename to write memory to (simple binary format) |
| 274 | * Return: 0 if OK, -ve on error |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 275 | */ |
| 276 | int os_write_ram_buf(const char *fname); |
| 277 | |
| 278 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 279 | * os_read_ram_buf() - read the sandbox RAM buffer from an existing file |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 280 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 281 | * @fname: filename containing memory (simple binary format) |
| 282 | * Return: 0 if OK, -ve on error |
Simon Glass | 9dd10bf | 2013-11-10 10:27:03 -0700 | [diff] [blame] | 283 | */ |
| 284 | int os_read_ram_buf(const char *fname); |
| 285 | |
Simon Glass | 860b7d9 | 2014-02-27 13:26:15 -0700 | [diff] [blame] | 286 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 287 | * os_jump_to_image() - jump to a new executable image |
Simon Glass | 860b7d9 | 2014-02-27 13:26:15 -0700 | [diff] [blame] | 288 | * |
| 289 | * This uses exec() to run a new executable image, after putting it in a |
| 290 | * temporary file. The same arguments and environment are passed to this |
| 291 | * new image, with the addition of: |
| 292 | * |
| 293 | * -j <filename> Specifies the filename the image was written to. The |
| 294 | * calling image may want to delete this at some point. |
| 295 | * -m <filename> Specifies the file containing the sandbox memory |
| 296 | * (ram_buf) from this image, so that the new image can |
| 297 | * have access to this. It also means that the original |
| 298 | * memory filename passed to U-Boot will be left intact. |
| 299 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 300 | * @dest: buffer containing executable image |
| 301 | * @size: size of buffer |
| 302 | * Return: 0 if OK, -ve on error |
Simon Glass | 860b7d9 | 2014-02-27 13:26:15 -0700 | [diff] [blame] | 303 | */ |
| 304 | int os_jump_to_image(const void *dest, int size); |
| 305 | |
Simon Glass | 504548f | 2015-04-20 12:37:22 -0600 | [diff] [blame] | 306 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 307 | * os_find_u_boot() - determine the path to U-Boot proper |
Simon Glass | 2c931ba | 2016-07-04 11:57:45 -0600 | [diff] [blame] | 308 | * |
| 309 | * This function is intended to be called from within sandbox SPL. It uses |
| 310 | * a few heuristics to find U-Boot proper. Normally it is either in the same |
| 311 | * directory, or the directory above (since u-boot-spl is normally in an |
| 312 | * spl/ subdirectory when built). |
| 313 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 314 | * @fname: place to put full path to U-Boot |
| 315 | * @maxlen: maximum size of @fname |
| 316 | * Return: 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found |
Simon Glass | 2c931ba | 2016-07-04 11:57:45 -0600 | [diff] [blame] | 317 | */ |
| 318 | int os_find_u_boot(char *fname, int maxlen); |
| 319 | |
| 320 | /** |
| 321 | * os_spl_to_uboot() - Run U-Boot proper |
| 322 | * |
| 323 | * When called from SPL, this runs U-Boot proper. The filename is obtained by |
| 324 | * calling os_find_u_boot(). |
| 325 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 326 | * @fname: full pathname to U-Boot executable |
| 327 | * Return: 0 if OK, -ve on error |
Simon Glass | 2c931ba | 2016-07-04 11:57:45 -0600 | [diff] [blame] | 328 | */ |
| 329 | int os_spl_to_uboot(const char *fname); |
| 330 | |
| 331 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 332 | * os_localtime() - read the current system time |
Simon Glass | 504548f | 2015-04-20 12:37:22 -0600 | [diff] [blame] | 333 | * |
| 334 | * This reads the current Local Time and places it into the provided |
| 335 | * structure. |
| 336 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 337 | * @rt: place to put system time |
Simon Glass | 504548f | 2015-04-20 12:37:22 -0600 | [diff] [blame] | 338 | */ |
| 339 | void os_localtime(struct rtc_time *rt); |
| 340 | |
Simon Glass | 5dccd15 | 2018-05-16 09:42:22 -0600 | [diff] [blame] | 341 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 342 | * os_abort() - raise SIGABRT to exit sandbox (e.g. to debugger) |
Simon Glass | b7255ef | 2018-09-15 00:50:55 -0600 | [diff] [blame] | 343 | */ |
| 344 | void os_abort(void); |
Simon Glass | 4e766c2 | 2018-10-01 21:12:32 -0600 | [diff] [blame] | 345 | |
| 346 | /** |
| 347 | * os_mprotect_allow() - Remove write-protection on a region of memory |
| 348 | * |
| 349 | * The start and length will be page-aligned before use. |
| 350 | * |
| 351 | * @start: Region start |
| 352 | * @len: Region length in bytes |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 353 | * Return: 0 if OK, -1 on error from mprotect() |
Simon Glass | 4e766c2 | 2018-10-01 21:12:32 -0600 | [diff] [blame] | 354 | */ |
| 355 | int os_mprotect_allow(void *start, size_t len); |
| 356 | |
Simon Glass | cbfa845 | 2018-10-01 11:55:08 -0600 | [diff] [blame] | 357 | /** |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 358 | * os_write_file() - write a file to the host filesystem |
Simon Glass | cbfa845 | 2018-10-01 11:55:08 -0600 | [diff] [blame] | 359 | * |
| 360 | * This can be useful when debugging for writing data out of sandbox for |
| 361 | * inspection by external tools. |
| 362 | * |
| 363 | * @name: File path to write to |
| 364 | * @buf: Data to write |
| 365 | * @size: Size of data to write |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 366 | * Return: 0 if OK, -ve on error |
Simon Glass | cbfa845 | 2018-10-01 11:55:08 -0600 | [diff] [blame] | 367 | */ |
| 368 | int os_write_file(const char *name, const void *buf, int size); |
| 369 | |
Simon Glass | 8d176d8 | 2018-11-06 15:21:25 -0700 | [diff] [blame] | 370 | /** |
| 371 | * os_read_file() - Read a file from the host filesystem |
| 372 | * |
| 373 | * This can be useful when reading test data into sandbox for use by test |
| 374 | * routines. The data is allocated using os_malloc() and should be freed by |
| 375 | * the caller. |
| 376 | * |
| 377 | * @name: File path to read from |
| 378 | * @bufp: Returns buffer containing data read |
| 379 | * @sizep: Returns size of data |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 380 | * Return: 0 if OK, -ve on error |
Simon Glass | 8d176d8 | 2018-11-06 15:21:25 -0700 | [diff] [blame] | 381 | */ |
| 382 | int os_read_file(const char *name, void **bufp, int *sizep); |
| 383 | |
Simon Glass | 752707a | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 384 | /* |
| 385 | * os_find_text_base() - Find the text section in this running process |
| 386 | * |
| 387 | * This tries to find the address of the text section in this running process. |
| 388 | * It can be useful to map the address of functions to the address listed in |
| 389 | * the u-boot.map file. |
| 390 | * |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 391 | * Return: address if found, else NULL |
Simon Glass | 752707a | 2019-04-08 13:20:41 -0600 | [diff] [blame] | 392 | */ |
| 393 | void *os_find_text_base(void); |
| 394 | |
Heinrich Schuchardt | 1c67844 | 2020-10-27 20:29:25 +0100 | [diff] [blame] | 395 | /** |
| 396 | * os_relaunch() - restart the sandbox |
| 397 | * |
| 398 | * This functions is used to implement the cold reboot of the sand box. |
Heinrich Schuchardt | 1ffe004 | 2020-10-27 20:29:27 +0100 | [diff] [blame] | 399 | * @argv\[0] specifies the binary that is started while the calling process |
Heinrich Schuchardt | 1c67844 | 2020-10-27 20:29:25 +0100 | [diff] [blame] | 400 | * stops immediately. If the new binary cannot be started, the process is |
| 401 | * terminated and 1 is set as shell return code. |
| 402 | * |
| 403 | * The PID of the process stays the same. All file descriptors that have not |
| 404 | * been opened with O_CLOEXEC stay open including stdin, stdout, stderr. |
| 405 | * |
| 406 | * @argv: NULL terminated list of command line parameters |
| 407 | */ |
| 408 | void os_relaunch(char *argv[]); |
| 409 | |
Mike Frysinger | 999a579 | 2012-01-19 22:57:29 -0500 | [diff] [blame] | 410 | #endif |