U-Boot APIs

This topic provides details for the U-Boot APIs.

FDT Interfaces

The Flattened Device Tree (FDT) interfaces are used to include part of the device information structure in the device tree file.

Table 1. fdt_getprop
Synopsis
const void *fdt_getprop(const void *fdt, int nodeoffset, const char *name, int *lenp)
Description Retrieves the value of a given property.
Parameter
  • fdt: The pointer to the DTB file
  • nodeoffset: The offset of the node to get property from
  • name: The name of the property
  • lenp: The pointer to an integer variable (will be overwritten) or NULL
Return
  • Success: The pointer to the property's value.

    If lenp is not NULL, *lenp will contain the length of the property value (>= 0).

  • Failure: NULL.If lenp is not NULL, *lenp will contain an error code (< 0):
    • FDT_ERR_NOTFOUND: The target property is not found.
    • FDT_ERR_BADOFFSET: The node offset is invalid. The node offset does not point to the FDT_BEGIN_NODE tag.
    • FDT_ERR_BADMAGIC: The magic field is invalid.
    • FDT_ERR_BADVERSION: The version is invalid.
    • FDT_ERR_BADSTATE: The state is invalid.
    • FDT_ERR_BADSTRUCTURE: The file structure is invalid.
    • FDT_ERR_TRUNCATED, standard meanings.
Table 2. fdt_set_node_status
Synopsis
int fdt_set_node_status(void *fdt, int nodeoffset, enum fdt_status sta-tus, unsigned int error_code)
Description Sets the status of a node.
Parameter
  • fdt: The pointer to the DTB file.
  • status: The following statuses are available.
    • FDT_STATUS_OKAY -
    • FDT_STATUS_DISABLED -
    • FDT_STATUS_FAIL -
    • FDT_STATUS_FAIL_ERROR_CODE -
  • error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE
Return
  • Success: 0.
  • Failure: Any value other than 0.
Table 3. fdt_path_offset
Synopsis
int fdt_path_offset(const void *fdt, const char *path);
Description Finds a tree node by its full path.
Parameter
  • fdt: The pointer to the DTB file.
  • path: The full path to the node.
  • error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE.
Return
  • Success: The structure block offset of the node with the requested path (>= 0).
  • Failure: Any value < 0.

ENV Interfaces

The environment (ENV) interfaces are used to provide U-Boot with the capabilities of dynamic configuration during program operation. U-Boot defines a set of default environment variables in file include/env_default.h.

Table 4. int env_set
Synopsis
int env_set(const char *varname, const char *value);
Description Sets an environment variable.
Parameter
  • varname: The environment variable you want to change.
  • varvalue: The new value of the environment variable.
Return
  • Success: 0.
  • Failure: 1.
Table 5. env_get
Synopsis
char *env_get(const char *varname);
Description Gets the value of an environment variable.
Parameter
  • varname: The environment variable you want to get value from.
Return
  • Success: Value of the target environment variable, or "NULL" if the environment variable is not found.
  • Failure: Any other values.
Table 6. env_set
Synopsis
int env_save(void);
Description Saves the environment variables to storage.
Parameter None
Return
  • Success: 0.
  • Failure: Any value other than 0.

U-Boot Commands

The U-Boot command line interfaces are used to create a minimum valid command line interface. So, after you start up U-Boot, you can have access to a lot of command lines, including tftp, bootm, and booti.

Table 7. run_command_list
Synopsis
int run_command_list(const char *cmd, int len, int flag)
Description Executes the U-Boot command line.
Parameter
  • cmd: The pointer to the command.
  • len: The length of the command line. To load the length automatically, set this value to “-1”.
  • flag: Not used.
Return
  • Success: 0.
  • Failure: Any value other than 0.
Table 8. do_bootm
Synopsis
int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Description Runs the bootm command, and boots the application from the image in memory.
Parameter
  • cmdtp: The command information for the bootm command
  • flag: The command flags
  • argc: The number of arguments
  • agrv: The list of arguments
Return
  • Success: 0.
  • Failure: Any value other than 0.
Table 9. do_booti
Synopsis
int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Description Runs the booti command, and boots the Linux kernel "Image" format from memory.
Parameter
  • cmdtp: The command information for the booti command
  • flag: The command flags
  • argc: The number of arguments
  • agrv: The list of arguments
Return
  • Success: 0.
  • Failure: Any value other than 0.
Table 10. do_tftpb
Synopsis
int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
Description Runs the tftpboot command, and boots the image via network using TFTP protocol.
Parameter
  • cmdtp: The command information for the tftpboot command
  • flag: The command flags
  • argc: The number of arguments
  • agrv: The list of arguments
Return
  • Success: 0.
  • Failure: Any value other than 0.
Table 11. do_mmcinfo
Synopsis
static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Description Runs the mmcinfo command, and displays the information of the current MMC device.
Parameter
  • cmdtp: The command information for the mmcinfo command
  • flag: The command flags
  • argc: The number of arguments
  • agrv: The list of arguments
Return
  • Success: 0.
  • Failure: 1

Flash Read and Write

The flash read and write interfaces are used to read data from and write data to the SPI flash. This can be used to flash images to the SPI flash via serial interfaces under U-Boot mode.

Table 12. spi_flash_read
Synopsis
static inline int spi_flash_read(struct spi_flash *flash, u32 offset, size_t len, void *buf)
Description Reads data from the SPI flash.
Parameter
  • flash: The SPI flash device
  • offset: The address offset of the above device in bytes
  • len: The length of bytes to read
  • buf: The buffer to store the read data
Return
  • Success: 0.
  • Failure: Any value other than 0
Table 13. spi_flash_write
Synopsis
static inline int spi_flash_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
Description Writes data into the SPI flash.
Parameter
  • flash: The SPI flash device
  • offset: The address offset of the above device in bytes
  • len: The length of bytes to write
  • buf: The buffer to store the data to write
Return
  • Success: 0.
  • Failure: Any value other than 0

Partition

The partition information interface is used to find a partition by partition name in all registered partitions and get its partition information.

Table 14. part_get_info_by_name
Synopsis
int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, struct disk_partition *info);
Description Finds a partition by partition name in all registered partitions and get its partition information.
Parameter
  • dev_desc: The device descriptor
  • name: The name of the specific partition table entry
  • info: The partition information to query
Return
  • Success: The target partition information
  • Failure: -1.

GPIO Operations

The GPIO operation interfaces are used to get and set GPIO levels to read the input and output status and alter the GPIO from an output to an output.

Table 15. gpio_get_value
Synopsis
int gpio_get_value(unsigned gpio)
Description Gets the level from a target GPIO interface. The level is used to define whether the GPIO is an input or an output.
Parameter
  • gpio: The GPIO index number
Return
  • Success: The level of the target GPIO interface: 0 as low level, 1 as high level
  • Failure: -1.
Table 16. gpio_set_value
Synopsis
void gpio_set_value(unsigned gpio, int value)
Description Sets the level to a target GPIO interface. The level can be used to alter the GPIO from an output to an output.
Parameter
  • gpio: The GPIO index number
  • value: The expected level: 0 as low level, 1 as high level
Return None