This is the implementation of libubootenv library.
More...
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <pthread.h>
#include <signal.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <zlib.h>
#include <linux/stat.h>
#include <mtd/mtd-user.h>
#include <mtd/ubi-user.h>
#include "uboot_private.h"
|
#define | LIST_FOREACH_SAFE(var, head, field, tvar) |
|
#define | LINE_LENGTH 1024 |
|
This is the implementation of libubootenv library.
◆ LIST_FOREACH_SAFE
#define LIST_FOREACH_SAFE |
( |
|
var, |
|
|
|
head, |
|
|
|
field, |
|
|
|
tvar |
|
) |
| |
Value:for ((var) = LIST_FIRST((head)); \
(var) != NULL && \
((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
◆ libuboot_close()
void libuboot_close |
( |
struct uboot_ctx * |
ctx | ) |
|
Release an environment.
Release allocated recource for the environment, but maintain the context. This allows to call libuboot_open() again.
- Parameters
-
- Returns
- 0 in case of success
◆ libuboot_configure()
Read U-Boot environment configuration from structure.
- Parameters
-
- Returns
- 0 in case of success, else negative value
◆ libuboot_env_store()
int libuboot_env_store |
( |
struct uboot_ctx * |
ctx | ) |
|
Flush environment to the storage.
Write the environment back to the storage and handle redundant devices.
- Parameters
-
- Returns
- 0 in case of success, else negative value
◆ libuboot_exit()
Release all resources and exit the library.
- Parameters
-
◆ libuboot_get_env()
char* libuboot_get_env |
( |
struct uboot_ctx * |
ctx, |
|
|
const char * |
varname |
|
) |
| |
Get a variable.
Return value of a variable as string or NULL if variable is not present in the database. The returned string must be freed by the caller when not used anymore.
- Parameters
-
[in] | ctx | libuboot context |
[in] | variable | name |
- Returns
- value in case of success, NULL in case of error
◆ libuboot_getname()
const char* libuboot_getname |
( |
void * |
entry | ) |
|
Accessor to get variable name from DB entry.
- Parameters
-
[in] | entry | element in the database |
- Returns
- pointer to name or NULL
◆ libuboot_getvalue()
const char* libuboot_getvalue |
( |
void * |
entry | ) |
|
Accessor to get variable value from DB entry.
- Parameters
-
[in] | entry | element in the database |
- Returns
- pointer to name or NULL
◆ libuboot_initialize()
Initialize the library.
Initialize the library and get the context structure
- Parameters
-
- Returns
- 0 in case of success, else negative value
◆ libuboot_iterator()
void* libuboot_iterator |
( |
struct uboot_ctx * |
ctx, |
|
|
void * |
next |
|
) |
| |
Iterator.
Return a pointer to an entry in the database Used to iterate all variables in the database.
- Parameters
-
[in] | ctx | libuboot context |
[in] | next | |
- Returns
- pointer to next entry or NULL
◆ libuboot_load_file()
int libuboot_load_file |
( |
struct uboot_ctx * |
ctx, |
|
|
const char * |
filename |
|
) |
| |
Import environment from file.
Read and parses variable from a file in the same way as U-Boot does with "env import -t" The file has the format: <variable name>="">=
Comments starting with "#" are allowed.
- Parameters
-
[in] | ctx | libuboot context |
[in] | filename | path to the file to be imported |
- Returns
- 0 in case of success, else negative value
◆ libuboot_open()
Load an environment.
- Parameters
-
- Returns
- 0 in case of success
◆ libuboot_read_config()
int libuboot_read_config |
( |
struct uboot_ctx * |
ctx, |
|
|
const char * |
config |
|
) |
| |
Read U-Boot environment configuration from a file.
- Parameters
-
[in] | ctx | libuboot context |
[in] | config | path to the configuration file |
- Returns
- 0 in case of success, else negative value
◆ libuboot_set_env()
int libuboot_set_env |
( |
struct uboot_ctx * |
ctx, |
|
|
const char * |
varname, |
|
|
const char * |
value |
|
) |
| |
Set a variable.
Set a variable. It creates a new variable if not present in the database, changes it or drops if value is NULL
- Parameters
-
[in] | ctx | libuboot context |
[in] | variable | name |
[in] | value. | In case this is NULL, the variable is dropped |
- Returns
- 0 in case of success