]> Git Repo - u-boot.git/blame - include/os.h
board/BuR/common: fix netconsole
[u-boot.git] / include / os.h
CommitLineData
7a9219c1 1/*
d9165153
SG
2 * Operating System Interface
3 *
4 * This provides access to useful OS routines for the sandbox architecture.
5 * They are kept in a separate file so we can include system headers.
6 *
7a9219c1 7 * Copyright (c) 2011 The Chromium OS Authors.
1a459660 8 * SPDX-License-Identifier: GPL-2.0+
7a9219c1
SG
9 */
10
4f345d56
MF
11#ifndef __OS_H__
12#define __OS_H__
13
2a54d159
SG
14#include <linux/types.h>
15
94eefdee 16struct rtc_time;
70db4212
SG
17struct sandbox_state;
18
7a9219c1
SG
19/**
20 * Access to the OS read() system call
21 *
22 * \param fd File descriptor as returned by os_open()
23 * \param buf Buffer to place data
24 * \param count Number of bytes to read
25 * \return number of bytes read, or -1 on error
26 */
27ssize_t os_read(int fd, void *buf, size_t count);
28
e101550a
TH
29/**
30 * Access to the OS read() system call with non-blocking access
31 *
32 * \param fd File descriptor as returned by os_open()
33 * \param buf Buffer to place data
34 * \param count Number of bytes to read
35 * \return number of bytes read, or -1 on error
36 */
37ssize_t os_read_no_block(int fd, void *buf, size_t count);
38
7a9219c1
SG
39/**
40 * Access to the OS write() system call
41 *
42 * \param fd File descriptor as returned by os_open()
43 * \param buf Buffer containing data to write
44 * \param count Number of bytes to write
45 * \return number of bytes written, or -1 on error
46 */
47ssize_t os_write(int fd, const void *buf, size_t count);
48
e2dcefcb
MF
49/**
50 * Access to the OS lseek() system call
51 *
52 * \param fd File descriptor as returned by os_open()
53 * \param offset File offset (based on whence)
54 * \param whence Position offset is relative to (see below)
55 * \return new file offset
56 */
57off_t os_lseek(int fd, off_t offset, int whence);
58
59/* Defines for "whence" in os_lseek() */
60#define OS_SEEK_SET 0
61#define OS_SEEK_CUR 1
62#define OS_SEEK_END 2
63
7a9219c1
SG
64/**
65 * Access to the OS open() system call
66 *
67 * \param pathname Pathname of file to open
887bd416 68 * \param flags Flags, like OS_O_RDONLY, OS_O_RDWR
7a9219c1
SG
69 * \return file descriptor, or -1 on error
70 */
71int os_open(const char *pathname, int flags);
72
d9165153
SG
73#define OS_O_RDONLY 0
74#define OS_O_WRONLY 1
75#define OS_O_RDWR 2
76#define OS_O_MASK 3 /* Mask for read/write flags */
77#define OS_O_CREAT 0100
78
7a9219c1
SG
79/**
80 * Access to the OS close() system call
81 *
82 * \param fd File descriptor to close
83 * \return 0 on success, -1 on error
84 */
85int os_close(int fd);
86
cfd13e8d
SW
87/**
88 * Access to the OS unlink() system call
89 *
90 * \param pathname Path of file to delete
91 * \return 0 for success, other for error
92 */
93int os_unlink(const char *pathname);
94
7a9219c1
SG
95/**
96 * Access to the OS exit() system call
97 *
98 * This exits with the supplied return code, which should be 0 to indicate
99 * success.
100 *
101 * @param exit_code exit code for U-Boot
102 */
9d72e67b 103void os_exit(int exit_code) __attribute__((noreturn));
ab06a758
MF
104
105/**
106 * Put tty into raw mode to mimic serial console better
ffb87905
SG
107 *
108 * @param fd File descriptor of stdin (normally 0)
109 * @param allow_sigs Allow Ctrl-C, Ctrl-Z to generate signals rather than
110 * be handled by U-Boot
ab06a758 111 */
ffb87905 112void os_tty_raw(int fd, bool allow_sigs);
21899b10
MW
113
114/**
115 * Acquires some memory from the underlying os.
116 *
117 * \param length Number of bytes to be allocated
118 * \return Pointer to length bytes or NULL on error
119 */
120void *os_malloc(size_t length);
d99a6874 121
77595c6d
SG
122/**
123 * Free memory previous allocated with os_malloc()/os_realloc()
124 *
125 * This returns the memory to the OS.
126 *
127 * \param ptr Pointer to memory block to free
128 */
347d06de 129void os_free(void *ptr);
77595c6d
SG
130
131/**
132 * Reallocate previously-allocated memory to increase/decrease space
133 *
134 * This works in a similar way to the C library realloc() function. If
135 * length is 0, then ptr is freed. Otherwise the space used by ptr is
136 * expanded or reduced depending on whether length is larger or smaller
137 * than before.
138 *
139 * If ptr is NULL, then this is similar to calling os_malloc().
140 *
141 * This function may need to move the memory block to make room for any
142 * extra space, in which case the new pointer is returned.
143 *
144 * \param ptr Pointer to memory block to reallocate
145 * \param length New length for memory block
146 * \return pointer to new memory block, or NULL on failure or if length
147 * is 0.
148 */
149void *os_realloc(void *ptr, size_t length);
150
d99a6874
MW
151/**
152 * Access to the usleep function of the os
153 *
154 * \param usec Time to sleep in micro seconds
155 */
156void os_usleep(unsigned long usec);
157
158/**
159 * Gets a monotonic increasing number of nano seconds from the OS
160 *
161 * \return A monotonic increasing time scaled in nano seconds
162 */
2a54d159 163uint64_t os_get_nsec(void);
4f345d56 164
70db4212
SG
165/**
166 * Parse arguments and update sandbox state.
167 *
168 * @param state Sandbox state to update
169 * @param argc Argument count
170 * @param argv Argument vector
171 * @return 0 if ok, and program should continue;
172 * 1 if ok, but program should stop;
173 * -1 on error: program should terminate.
174 */
175int os_parse_args(struct sandbox_state *state, int argc, char *argv[]);
176
62584db1
SG
177/*
178 * Types of directory entry that we support. See also os_dirent_typename in
179 * the C file.
180 */
181enum os_dirent_t {
182 OS_FILET_REG, /* Regular file */
183 OS_FILET_LNK, /* Symbolic link */
184 OS_FILET_DIR, /* Directory */
185 OS_FILET_UNKNOWN, /* Something else */
186
187 OS_FILET_COUNT,
188};
189
190/** A directory entry node, containing information about a single dirent */
191struct os_dirent_node {
192 struct os_dirent_node *next; /* Pointer to next node, or NULL */
193 ulong size; /* Size of file in bytes */
194 enum os_dirent_t type; /* Type of entry */
195 char name[0]; /* Name of entry */
196};
197
198/**
199 * Get a directionry listing
200 *
201 * This allocates and returns a linked list containing the directory listing.
202 *
203 * @param dirname Directory to examine
204 * @param headp Returns pointer to head of linked list, or NULL if none
205 * @return 0 if ok, -ve on error
206 */
207int os_dirent_ls(const char *dirname, struct os_dirent_node **headp);
208
209/**
210 * Get the name of a directory entry type
211 *
212 * @param type Type to cehck
213 * @return string containing the name of that type, or "???" if none/invalid
214 */
215const char *os_dirent_get_typename(enum os_dirent_t type);
216
217/**
218 * Get the size of a file
219 *
220 * @param fname Filename to check
96b1046d
SR
221 * @param size size of file is returned if no error
222 * @return 0 on success or -1 if an error ocurred
62584db1 223 */
96b1046d 224int os_get_filesize(const char *fname, loff_t *size);
62584db1 225
91b136c7
SG
226/**
227 * Write a character to the controlling OS terminal
228 *
229 * This bypasses the U-Boot console support and writes directly to the OS
230 * stdout file descriptor.
231 *
232 * @param ch Character to write
233 */
234void os_putc(int ch);
235
236/**
237 * Write a string to the controlling OS terminal
238 *
239 * This bypasses the U-Boot console support and writes directly to the OS
240 * stdout file descriptor.
241 *
242 * @param str String to write (note that \n is not appended)
243 */
244void os_puts(const char *str);
245
5c2859cd
SG
246/**
247 * Write the sandbox RAM buffer to a existing file
248 *
249 * @param fname Filename to write memory to (simple binary format)
250 * @return 0 if OK, -ve on error
251 */
252int os_write_ram_buf(const char *fname);
253
254/**
255 * Read the sandbox RAM buffer from an existing file
256 *
257 * @param fname Filename containing memory (simple binary format)
258 * @return 0 if OK, -ve on error
259 */
260int os_read_ram_buf(const char *fname);
261
47f5fcfb
SG
262/**
263 * Jump to a new executable image
264 *
265 * This uses exec() to run a new executable image, after putting it in a
266 * temporary file. The same arguments and environment are passed to this
267 * new image, with the addition of:
268 *
269 * -j <filename> Specifies the filename the image was written to. The
270 * calling image may want to delete this at some point.
271 * -m <filename> Specifies the file containing the sandbox memory
272 * (ram_buf) from this image, so that the new image can
273 * have access to this. It also means that the original
274 * memory filename passed to U-Boot will be left intact.
275 *
276 * @param dest Buffer containing executable image
277 * @param size Size of buffer
278 */
279int os_jump_to_image(const void *dest, int size);
280
94eefdee
SG
281/**
282 * Read the current system time
283 *
284 * This reads the current Local Time and places it into the provided
285 * structure.
286 *
287 * @param rt Place to put system time
288 */
289void os_localtime(struct rtc_time *rt);
290
4f345d56 291#endif
This page took 0.280594 seconds and 4 git commands to generate.