2018-05-07 05:58:06 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2011-10-04 03:26:44 +08:00
|
|
|
/*
|
2012-02-21 12:56:58 +08:00
|
|
|
* Operating System Interface
|
|
|
|
*
|
|
|
|
* This provides access to useful OS routines for the sandbox architecture.
|
|
|
|
* They are kept in a separate file so we can include system headers.
|
|
|
|
*
|
2011-10-04 03:26:44 +08:00
|
|
|
* Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
*/
|
|
|
|
|
2012-01-20 11:57:29 +08:00
|
|
|
#ifndef __OS_H__
|
|
|
|
#define __OS_H__
|
|
|
|
|
2013-05-20 07:45:35 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2015-04-21 02:37:22 +08:00
|
|
|
struct rtc_time;
|
2012-02-16 07:51:16 +08:00
|
|
|
struct sandbox_state;
|
|
|
|
|
2011-10-04 03:26:44 +08:00
|
|
|
/**
|
|
|
|
* Access to the OS read() system call
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fd: File descriptor as returned by os_open()
|
|
|
|
* @buf: Buffer to place data
|
|
|
|
* @count: Number of bytes to read
|
|
|
|
* Return: number of bytes read, or -1 on error
|
2011-10-04 03:26:44 +08:00
|
|
|
*/
|
|
|
|
ssize_t os_read(int fd, void *buf, size_t count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access to the OS write() system call
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fd: File descriptor as returned by os_open()
|
|
|
|
* @buf: Buffer containing data to write
|
|
|
|
* @count: Number of bytes to write
|
|
|
|
* Return: number of bytes written, or -1 on error
|
2011-10-04 03:26:44 +08:00
|
|
|
*/
|
|
|
|
ssize_t os_write(int fd, const void *buf, size_t count);
|
|
|
|
|
2011-10-25 19:02:58 +08:00
|
|
|
/**
|
|
|
|
* Access to the OS lseek() system call
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fd: File descriptor as returned by os_open()
|
|
|
|
* @offset: File offset (based on whence)
|
|
|
|
* @whence: Position offset is relative to (see below)
|
|
|
|
* Return: new file offset
|
2011-10-25 19:02:58 +08:00
|
|
|
*/
|
|
|
|
off_t os_lseek(int fd, off_t offset, int whence);
|
|
|
|
|
|
|
|
/* Defines for "whence" in os_lseek() */
|
|
|
|
#define OS_SEEK_SET 0
|
|
|
|
#define OS_SEEK_CUR 1
|
|
|
|
#define OS_SEEK_END 2
|
|
|
|
|
2021-08-19 11:40:30 +08:00
|
|
|
/**
|
|
|
|
* os_filesize() - Calculate the size of a file
|
|
|
|
*
|
|
|
|
* @fd: File descriptor as returned by os_open()
|
|
|
|
* Return: file size or negative error code
|
|
|
|
*/
|
|
|
|
int os_filesize(int fd);
|
|
|
|
|
2011-10-04 03:26:44 +08:00
|
|
|
/**
|
|
|
|
* Access to the OS open() system call
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @pathname: Pathname of file to open
|
|
|
|
* @flags: Flags, like OS_O_RDONLY, OS_O_RDWR
|
|
|
|
* Return: file descriptor, or -1 on error
|
2011-10-04 03:26:44 +08:00
|
|
|
*/
|
|
|
|
int os_open(const char *pathname, int flags);
|
|
|
|
|
2012-02-21 12:56:58 +08:00
|
|
|
#define OS_O_RDONLY 0
|
|
|
|
#define OS_O_WRONLY 1
|
|
|
|
#define OS_O_RDWR 2
|
|
|
|
#define OS_O_MASK 3 /* Mask for read/write flags */
|
|
|
|
#define OS_O_CREAT 0100
|
2018-10-02 01:55:07 +08:00
|
|
|
#define OS_O_TRUNC 01000
|
2012-02-21 12:56:58 +08:00
|
|
|
|
2011-10-04 03:26:44 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_close() - access to the OS close() system call
|
2011-10-04 03:26:44 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fd: File descriptor to close
|
|
|
|
* Return: 0 on success, -1 on error
|
2011-10-04 03:26:44 +08:00
|
|
|
*/
|
|
|
|
int os_close(int fd);
|
|
|
|
|
2014-03-02 13:18:00 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_unlink() - access to the OS unlink() system call
|
2014-03-02 13:18:00 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @pathname: Path of file to delete
|
|
|
|
* Return: 0 for success, other for error
|
2014-03-02 13:18:00 +08:00
|
|
|
*/
|
|
|
|
int os_unlink(const char *pathname);
|
|
|
|
|
2011-10-04 03:26:44 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_exit() - access to the OS exit() system call
|
2011-10-04 03:26:44 +08:00
|
|
|
*
|
|
|
|
* This exits with the supplied return code, which should be 0 to indicate
|
|
|
|
* success.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @exit_code: exit code for U-Boot
|
2011-10-04 03:26:44 +08:00
|
|
|
*/
|
2012-02-27 06:46:30 +08:00
|
|
|
void os_exit(int exit_code) __attribute__((noreturn));
|
2011-10-26 08:21:29 +08:00
|
|
|
|
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_tty_raw() - put tty into raw mode to mimic serial console better
|
2014-02-28 04:26:22 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fd: File descriptor of stdin (normally 0)
|
|
|
|
* @allow_sigs: Allow Ctrl-C, Ctrl-Z to generate signals rather than
|
|
|
|
* be handled by U-Boot
|
2011-10-26 08:21:29 +08:00
|
|
|
*/
|
2014-02-28 04:26:22 +08:00
|
|
|
void os_tty_raw(int fd, bool allow_sigs);
|
2011-11-05 18:40:34 +08:00
|
|
|
|
2015-05-11 11:07:27 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_fs_restore() - restore the tty to its original mode
|
2015-05-11 11:07:27 +08:00
|
|
|
*
|
|
|
|
* Call this to restore the original terminal mode, after it has been changed
|
|
|
|
* by os_tty_raw(). This is an internal function.
|
|
|
|
*/
|
|
|
|
void os_fd_restore(void);
|
|
|
|
|
2011-11-05 18:40:34 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_malloc() - aquires some memory from the underlying os.
|
2011-11-05 18:40:34 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @length: Number of bytes to be allocated
|
2021-02-07 00:57:32 +08:00
|
|
|
* Return: Pointer to length bytes or NULL if @length is 0 or on error
|
2011-11-05 18:40:34 +08:00
|
|
|
*/
|
|
|
|
void *os_malloc(size_t length);
|
2011-11-29 19:16:40 +08:00
|
|
|
|
2013-11-11 01:26:57 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_free() - free memory previous allocated with os_malloc()
|
2013-11-11 01:26:57 +08:00
|
|
|
*
|
|
|
|
* This returns the memory to the OS.
|
|
|
|
*
|
2021-02-07 00:57:33 +08:00
|
|
|
* @ptr: Pointer to memory block to free. If this is NULL then this
|
|
|
|
* function does nothing
|
2013-11-11 01:26:57 +08:00
|
|
|
*/
|
2014-01-15 12:06:41 +08:00
|
|
|
void os_free(void *ptr);
|
2013-11-11 01:26:57 +08:00
|
|
|
|
2021-02-07 00:57:32 +08:00
|
|
|
/**
|
|
|
|
* os_realloc() - reallocate memory
|
|
|
|
*
|
|
|
|
* This follows the semantics of realloc(), so can perform an os_malloc() or
|
|
|
|
* os_free() depending on @ptr and @length.
|
|
|
|
*
|
2021-03-28 17:05:00 +08:00
|
|
|
* @ptr: pointer to previously allocated memory of NULL
|
|
|
|
* @length: number of bytes to allocate
|
|
|
|
* Return: pointer to reallocated memory or NULL if @length is 0
|
2021-02-07 00:57:32 +08:00
|
|
|
*/
|
|
|
|
void *os_realloc(void *ptr, size_t length);
|
|
|
|
|
2011-11-29 19:16:40 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_usleep() - access to the usleep function of the os
|
2011-11-29 19:16:40 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @usec: time to sleep in micro seconds
|
2011-11-29 19:16:40 +08:00
|
|
|
*/
|
|
|
|
void os_usleep(unsigned long usec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a monotonic increasing number of nano seconds from the OS
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: a monotonic increasing time scaled in nano seconds
|
2011-11-29 19:16:40 +08:00
|
|
|
*/
|
2013-05-20 07:45:35 +08:00
|
|
|
uint64_t os_get_nsec(void);
|
2012-01-20 11:57:29 +08:00
|
|
|
|
2012-02-16 07:51:16 +08:00
|
|
|
/**
|
|
|
|
* Parse arguments and update sandbox state.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @state: sandbox state to update
|
|
|
|
* @argc: argument count
|
|
|
|
* @argv: argument vector
|
|
|
|
* Return:
|
|
|
|
* * 0 if ok, and program should continue
|
|
|
|
* * 1 if ok, but program should stop
|
|
|
|
* * -1 on error: program should terminate
|
2012-02-16 07:51:16 +08:00
|
|
|
*/
|
|
|
|
int os_parse_args(struct sandbox_state *state, int argc, char *argv[]);
|
|
|
|
|
2012-12-26 17:53:34 +08:00
|
|
|
/*
|
2020-10-28 03:29:27 +08:00
|
|
|
* enum os_dirent_t - type of directory entry
|
|
|
|
*
|
2012-12-26 17:53:34 +08:00
|
|
|
* Types of directory entry that we support. See also os_dirent_typename in
|
|
|
|
* the C file.
|
|
|
|
*/
|
|
|
|
enum os_dirent_t {
|
2020-10-28 03:29:27 +08:00
|
|
|
/**
|
|
|
|
* @OS_FILET_REG: regular file
|
|
|
|
*/
|
|
|
|
OS_FILET_REG,
|
|
|
|
/**
|
|
|
|
* @OS_FILET_LNK: symbolic link
|
|
|
|
*/
|
|
|
|
OS_FILET_LNK,
|
|
|
|
/**
|
|
|
|
* @OS_FILET_DIR: directory
|
|
|
|
*/
|
|
|
|
OS_FILET_DIR,
|
|
|
|
/**
|
|
|
|
* @OS_FILET_UNKNOWN: something else
|
|
|
|
*/
|
|
|
|
OS_FILET_UNKNOWN,
|
|
|
|
/**
|
|
|
|
* @OS_FILET_COUNT: number of directory entry types
|
|
|
|
*/
|
2012-12-26 17:53:34 +08:00
|
|
|
OS_FILET_COUNT,
|
|
|
|
};
|
|
|
|
|
2020-10-28 03:29:27 +08:00
|
|
|
/**
|
|
|
|
* struct os_dirent_node - directory node
|
|
|
|
*
|
|
|
|
* A directory entry node, containing information about a single dirent
|
|
|
|
*
|
|
|
|
*/
|
2012-12-26 17:53:34 +08:00
|
|
|
struct os_dirent_node {
|
2020-10-28 03:29:27 +08:00
|
|
|
/**
|
|
|
|
* @next: pointer to next node, or NULL
|
|
|
|
*/
|
|
|
|
struct os_dirent_node *next;
|
|
|
|
/**
|
|
|
|
* @size: size of file in bytes
|
|
|
|
*/
|
|
|
|
ulong size;
|
|
|
|
/**
|
|
|
|
* @type: type of entry
|
|
|
|
*/
|
|
|
|
enum os_dirent_t type;
|
|
|
|
/**
|
|
|
|
* @name: name of entry
|
|
|
|
*/
|
|
|
|
char name[0];
|
2012-12-26 17:53:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_dirent_ls() - get a directory listing
|
2012-12-26 17:53:34 +08:00
|
|
|
*
|
|
|
|
* This allocates and returns a linked list containing the directory listing.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @dirname: directory to examine
|
|
|
|
* @headp: on return pointer to head of linked list, or NULL if none
|
|
|
|
* Return: 0 if ok, -ve on error
|
2012-12-26 17:53:34 +08:00
|
|
|
*/
|
|
|
|
int os_dirent_ls(const char *dirname, struct os_dirent_node **headp);
|
|
|
|
|
2016-10-02 02:41:38 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_dirent_free() - free directory list
|
2016-10-02 02:41:38 +08:00
|
|
|
*
|
|
|
|
* This frees a linked list containing a directory listing.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @node: pointer to head of linked list
|
2016-10-02 02:41:38 +08:00
|
|
|
*/
|
|
|
|
void os_dirent_free(struct os_dirent_node *node);
|
|
|
|
|
2012-12-26 17:53:34 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_dirent_get_typename() - get the name of a directory entry type
|
2012-12-26 17:53:34 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @type: type to check
|
|
|
|
* Return:
|
|
|
|
* string containing the name of that type,
|
|
|
|
* or "???" if none/invalid
|
2012-12-26 17:53:34 +08:00
|
|
|
*/
|
|
|
|
const char *os_dirent_get_typename(enum os_dirent_t type);
|
|
|
|
|
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_get_filesize() - get the size of a file
|
2012-12-26 17:53:34 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fname: filename to check
|
|
|
|
* @size: size of file is returned if no error
|
|
|
|
* Return: 0 on success or -1 if an error ocurred
|
2012-12-26 17:53:34 +08:00
|
|
|
*/
|
2014-11-18 06:39:37 +08:00
|
|
|
int os_get_filesize(const char *fname, loff_t *size);
|
2012-12-26 17:53:34 +08:00
|
|
|
|
2017-12-05 04:48:17 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_putc() - write a character to the controlling OS terminal
|
2017-12-05 04:48:17 +08:00
|
|
|
*
|
|
|
|
* This bypasses the U-Boot console support and writes directly to the OS
|
|
|
|
* stdout file descriptor.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @ch: haracter to write
|
2017-12-05 04:48:17 +08:00
|
|
|
*/
|
|
|
|
void os_putc(int ch);
|
|
|
|
|
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_puts() - write a string to the controlling OS terminal
|
2017-12-05 04:48:17 +08:00
|
|
|
*
|
|
|
|
* This bypasses the U-Boot console support and writes directly to the OS
|
|
|
|
* stdout file descriptor.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @str: string to write (note that \n is not appended)
|
2017-12-05 04:48:17 +08:00
|
|
|
*/
|
|
|
|
void os_puts(const char *str);
|
|
|
|
|
2013-11-11 01:27:03 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_write_ram_buf() - write the sandbox RAM buffer to a existing file
|
2013-11-11 01:27:03 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fname: filename to write memory to (simple binary format)
|
|
|
|
* Return: 0 if OK, -ve on error
|
2013-11-11 01:27:03 +08:00
|
|
|
*/
|
|
|
|
int os_write_ram_buf(const char *fname);
|
|
|
|
|
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_read_ram_buf() - read the sandbox RAM buffer from an existing file
|
2013-11-11 01:27:03 +08:00
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fname: filename containing memory (simple binary format)
|
|
|
|
* Return: 0 if OK, -ve on error
|
2013-11-11 01:27:03 +08:00
|
|
|
*/
|
|
|
|
int os_read_ram_buf(const char *fname);
|
|
|
|
|
2014-02-28 04:26:15 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_jump_to_image() - jump to a new executable image
|
2014-02-28 04:26:15 +08:00
|
|
|
*
|
|
|
|
* This uses exec() to run a new executable image, after putting it in a
|
|
|
|
* temporary file. The same arguments and environment are passed to this
|
|
|
|
* new image, with the addition of:
|
|
|
|
*
|
|
|
|
* -j <filename> Specifies the filename the image was written to. The
|
|
|
|
* calling image may want to delete this at some point.
|
|
|
|
* -m <filename> Specifies the file containing the sandbox memory
|
|
|
|
* (ram_buf) from this image, so that the new image can
|
|
|
|
* have access to this. It also means that the original
|
|
|
|
* memory filename passed to U-Boot will be left intact.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @dest: buffer containing executable image
|
|
|
|
* @size: size of buffer
|
|
|
|
* Return: 0 if OK, -ve on error
|
2014-02-28 04:26:15 +08:00
|
|
|
*/
|
|
|
|
int os_jump_to_image(const void *dest, int size);
|
|
|
|
|
2016-07-05 01:57:45 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_find_u_boot() - determine the path to U-Boot proper
|
2016-07-05 01:57:45 +08:00
|
|
|
*
|
|
|
|
* This function is intended to be called from within sandbox SPL. It uses
|
|
|
|
* a few heuristics to find U-Boot proper. Normally it is either in the same
|
|
|
|
* directory, or the directory above (since u-boot-spl is normally in an
|
|
|
|
* spl/ subdirectory when built).
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fname: place to put full path to U-Boot
|
|
|
|
* @maxlen: maximum size of @fname
|
2021-03-08 08:35:13 +08:00
|
|
|
* @use_img: select the 'u-boot.img' file instead of the 'u-boot' ELF file
|
2021-07-06 06:32:45 +08:00
|
|
|
* @cur_prefix: prefix of current executable, e.g. "spl" or "tpl"
|
|
|
|
* @next_prefix: prefix of executable to find, e.g. "spl" or ""
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found
|
2016-07-05 01:57:45 +08:00
|
|
|
*/
|
2021-07-06 06:32:45 +08:00
|
|
|
int os_find_u_boot(char *fname, int maxlen, bool use_img,
|
|
|
|
const char *cur_prefix, const char *next_prefix);
|
2016-07-05 01:57:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* os_spl_to_uboot() - Run U-Boot proper
|
|
|
|
*
|
|
|
|
* When called from SPL, this runs U-Boot proper. The filename is obtained by
|
|
|
|
* calling os_find_u_boot().
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @fname: full pathname to U-Boot executable
|
|
|
|
* Return: 0 if OK, -ve on error
|
2016-07-05 01:57:45 +08:00
|
|
|
*/
|
|
|
|
int os_spl_to_uboot(const char *fname);
|
|
|
|
|
2015-04-21 02:37:22 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_localtime() - read the current system time
|
2015-04-21 02:37:22 +08:00
|
|
|
*
|
|
|
|
* This reads the current Local Time and places it into the provided
|
|
|
|
* structure.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* @rt: place to put system time
|
2015-04-21 02:37:22 +08:00
|
|
|
*/
|
|
|
|
void os_localtime(struct rtc_time *rt);
|
|
|
|
|
2018-09-15 14:50:55 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_abort() - raise SIGABRT to exit sandbox (e.g. to debugger)
|
2018-09-15 14:50:55 +08:00
|
|
|
*/
|
2021-02-01 08:24:10 +08:00
|
|
|
void os_abort(void) __attribute__((noreturn));
|
2018-10-02 11:12:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* os_mprotect_allow() - Remove write-protection on a region of memory
|
|
|
|
*
|
|
|
|
* The start and length will be page-aligned before use.
|
|
|
|
*
|
|
|
|
* @start: Region start
|
|
|
|
* @len: Region length in bytes
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: 0 if OK, -1 on error from mprotect()
|
2018-10-02 11:12:32 +08:00
|
|
|
*/
|
|
|
|
int os_mprotect_allow(void *start, size_t len);
|
|
|
|
|
2018-10-02 01:55:08 +08:00
|
|
|
/**
|
2020-10-28 03:29:27 +08:00
|
|
|
* os_write_file() - write a file to the host filesystem
|
2018-10-02 01:55:08 +08:00
|
|
|
*
|
|
|
|
* This can be useful when debugging for writing data out of sandbox for
|
|
|
|
* inspection by external tools.
|
|
|
|
*
|
|
|
|
* @name: File path to write to
|
|
|
|
* @buf: Data to write
|
|
|
|
* @size: Size of data to write
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-10-02 01:55:08 +08:00
|
|
|
*/
|
|
|
|
int os_write_file(const char *name, const void *buf, int size);
|
|
|
|
|
2018-11-07 06:21:25 +08:00
|
|
|
/**
|
|
|
|
* os_read_file() - Read a file from the host filesystem
|
|
|
|
*
|
|
|
|
* This can be useful when reading test data into sandbox for use by test
|
|
|
|
* routines. The data is allocated using os_malloc() and should be freed by
|
|
|
|
* the caller.
|
|
|
|
*
|
|
|
|
* @name: File path to read from
|
|
|
|
* @bufp: Returns buffer containing data read
|
|
|
|
* @sizep: Returns size of data
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-11-07 06:21:25 +08:00
|
|
|
*/
|
|
|
|
int os_read_file(const char *name, void **bufp, int *sizep);
|
|
|
|
|
2021-08-19 11:40:31 +08:00
|
|
|
/**
|
|
|
|
* os_map_file() - Map a file from the host filesystem into memory
|
|
|
|
*
|
|
|
|
* This can be useful when to provide a backing store for an emulated device
|
|
|
|
*
|
|
|
|
* @pathname: File pathname to map
|
|
|
|
* @os_flags: Flags, like OS_O_RDONLY, OS_O_RDWR
|
|
|
|
* @bufp: Returns buffer containing the file
|
|
|
|
* @sizep: Returns size of data
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep);
|
|
|
|
|
2021-10-24 07:25:58 +08:00
|
|
|
/**
|
|
|
|
* os_unmap() - Unmap a file previously mapped
|
|
|
|
*
|
|
|
|
* @buf: Mapped address
|
|
|
|
* @size: Size in bytes
|
|
|
|
* Return: 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int os_unmap(void *buf, int size);
|
|
|
|
|
2019-04-09 03:20:41 +08:00
|
|
|
/*
|
|
|
|
* os_find_text_base() - Find the text section in this running process
|
|
|
|
*
|
|
|
|
* This tries to find the address of the text section in this running process.
|
|
|
|
* It can be useful to map the address of functions to the address listed in
|
|
|
|
* the u-boot.map file.
|
|
|
|
*
|
2020-10-28 03:29:27 +08:00
|
|
|
* Return: address if found, else NULL
|
2019-04-09 03:20:41 +08:00
|
|
|
*/
|
|
|
|
void *os_find_text_base(void);
|
|
|
|
|
2020-10-28 03:29:25 +08:00
|
|
|
/**
|
|
|
|
* os_relaunch() - restart the sandbox
|
|
|
|
*
|
|
|
|
* This functions is used to implement the cold reboot of the sand box.
|
2020-10-28 03:29:27 +08:00
|
|
|
* @argv\[0] specifies the binary that is started while the calling process
|
2020-10-28 03:29:25 +08:00
|
|
|
* stops immediately. If the new binary cannot be started, the process is
|
|
|
|
* terminated and 1 is set as shell return code.
|
|
|
|
*
|
|
|
|
* The PID of the process stays the same. All file descriptors that have not
|
|
|
|
* been opened with O_CLOEXEC stay open including stdin, stdout, stderr.
|
|
|
|
*
|
|
|
|
* @argv: NULL terminated list of command line parameters
|
|
|
|
*/
|
|
|
|
void os_relaunch(char *argv[]);
|
|
|
|
|
2020-11-12 07:29:56 +08:00
|
|
|
/**
|
|
|
|
* os_setup_signal_handlers() - setup signal handlers
|
|
|
|
*
|
|
|
|
* Install signal handlers for SIGBUS and SIGSEGV.
|
|
|
|
*
|
|
|
|
* Return: 0 for success
|
|
|
|
*/
|
|
|
|
int os_setup_signal_handlers(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* os_signal_action() - handle a signal
|
|
|
|
*
|
|
|
|
* @sig: signal
|
|
|
|
* @pc: program counter
|
|
|
|
*/
|
|
|
|
void os_signal_action(int sig, unsigned long pc);
|
|
|
|
|
2020-12-31 01:07:48 +08:00
|
|
|
/**
|
|
|
|
* os_get_time_offset() - get time offset
|
|
|
|
*
|
|
|
|
* Get the time offset from environment variable UBOOT_SB_TIME_OFFSET.
|
|
|
|
*
|
|
|
|
* Return: offset in seconds
|
|
|
|
*/
|
|
|
|
long os_get_time_offset(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* os_set_time_offset() - set time offset
|
|
|
|
*
|
|
|
|
* Save the time offset in environment variable UBOOT_SB_TIME_OFFSET.
|
|
|
|
*
|
|
|
|
* @offset: offset in seconds
|
|
|
|
*/
|
|
|
|
void os_set_time_offset(long offset);
|
|
|
|
|
2012-01-20 11:57:29 +08:00
|
|
|
#endif
|