TT Zephyr Platforms 18.11.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
fwupdate.c File Reference
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <tenstorrent/fwupdate.h>
#include <tenstorrent/tt_boot_fs.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/sys/util.h>
#include <tenstorrent/bh_chip.h>

Macros

#define IMAGE_MAGIC   0x96f3b83d
#define AS_U32(a, b, c, d)
#define FLASH0_NODE   DT_NODELABEL(flash) /* "flash" (NOT "flash0") is internal flash */
#define ERASE_BLOCK_SIZE   DT_PROP(DT_NODELABEL(flash0), erase_block_size)
#define WRITE_BLOCK_SIZE   DT_PROP(DT_NODELABEL(flash0), write_block_size)
#define TT_BOOT_FS_OFFSET   0

Functions

 LOG_MODULE_REGISTER (tt_fwupdate, CONFIG_TT_FWUPDATE_LOG_LEVEL)
int tt_fwupdate_init (const struct device *dev, struct gpio_dt_spec mux)
 Set the external flash device and set the passed spi mux (if not null) to allow communication with the spi.
int tt_fwupdate_complete (void)
 Called on the completion of the fwupdate operation, disables the spi mux if initialized in tt_fwupdate_init
static int z_tt_boot_fs_read (uint32_t addr, uint32_t size, uint8_t *dst)
static int z_tt_boot_fs_write (uint32_t addr, uint32_t size, const uint8_t *src)
static int z_tt_boot_fs_erase (uint32_t addr, uint32_t size)
static void tt_fwupdate_dump_fd (const char *msg, const tt_boot_fs_fd *fd, bool verified)
int tt_fwupdate (const char *tag, bool dry_run, bool reboot)
 Search for, verify, and apply firmware updates.
int tt_fwupdate_confirm (void)
 Confirm that the current firmware has booted successfully.
int tt_fwupdate_flash_image (const tt_boot_fs_fd *fd)
 Flash the image described by the provided boot filesystem file descriptor.
int tt_fwupdate_is_confirmed (void)
 Check if the currently running firmware has been confirmed.
int tt_fwupdate_validate_fd (const tt_boot_fs_fd *fd)
 Validate the provided boot filesystem file descriptor.
int tt_fwupdate_validate_image (const tt_boot_fs_fd *fd)
 Validate the image described by the provided boot filesystem file descriptor.

Variables

static tt_boot_fs boot_fs
static const struct deviceflash1_dev
static struct gpio_dt_spec spi_mux
static const struct device *const flash0_dev = DEVICE_DT_GET( DT_NODELABEL(flash) )

Macro Definition Documentation

◆ AS_U32

#define AS_U32 ( a,
b,
c,
d )
Value:
(((uint32_t)(a) << 24) | ((uint32_t)(b) << 16) | ((uint32_t)(c) << 8) | \
((uint32_t)(d) << 0))
irp nz macro MOVR cc d
__UINT32_TYPE__ uint32_t

◆ ERASE_BLOCK_SIZE

#define ERASE_BLOCK_SIZE   DT_PROP(DT_NODELABEL(flash0), erase_block_size)

◆ FLASH0_NODE

#define FLASH0_NODE   DT_NODELABEL(flash) /* "flash" (NOT "flash0") is internal flash */

◆ IMAGE_MAGIC

#define IMAGE_MAGIC   0x96f3b83d

◆ TT_BOOT_FS_OFFSET

#define TT_BOOT_FS_OFFSET   0

◆ WRITE_BLOCK_SIZE

#define WRITE_BLOCK_SIZE   DT_PROP(DT_NODELABEL(flash0), write_block_size)

Function Documentation

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( tt_fwupdate ,
CONFIG_TT_FWUPDATE_LOG_LEVEL  )

◆ tt_fwupdate()

int tt_fwupdate ( const char * tag,
bool dry_run,
bool reboot )

Search for, verify, and apply firmware updates.

Note
if a firmware update is applied successfully and reboot is true, then this function does not return.
Parameters
tagThe tag (name) of the update image in the flash filesystem.
dry_runOnly verify data and operations. Do not write to flash or reboot.
rebootIf true, reboot after the update has been successfully written.
Return values
0on success, if no firmware update is needed.
1on success, if a firmware update was applied and a reboot is required.
-EINVALif an argument is invalid.
-EIOif an I/O error occurs.
-ENOENTif the image is invalid an image named tag cannot be found.
-ENODEVif the current slot cannot be determined or a device is not ready.

◆ tt_fwupdate_complete()

int tt_fwupdate_complete ( void )

Called on the completion of the fwupdate operation, disables the spi mux if initialized in tt_fwupdate_init

Return values
0on success, if the spi mux was able to be set

◆ tt_fwupdate_confirm()

int tt_fwupdate_confirm ( void )

Confirm that the current firmware has booted successfully.

Return values
0on success.
-EIOif an I/O erorr occurs.

◆ tt_fwupdate_dump_fd()

void tt_fwupdate_dump_fd ( const char * msg,
const tt_boot_fs_fd * fd,
bool verified )
static

◆ tt_fwupdate_flash_image()

int tt_fwupdate_flash_image ( const tt_boot_fs_fd * fd)

Flash the image described by the provided boot filesystem file descriptor.

Note
This function does not validate the image. Please use tt_fwupdate_validate_image first.
Parameters
fdA pointer to the file descriptor for the desired image.
Returns
0 if the image described by fd is valid.
Return values
-EINVALif fd is NULL.
-ENOENTif the image is invalid.
-EIOif an I/O error occurs.
-EFBIGif the image is too large to fit in the slot.

◆ tt_fwupdate_init()

int tt_fwupdate_init ( const struct device * dev,
struct gpio_dt_spec mux )

Set the external flash device and set the passed spi mux (if not null) to allow communication with the spi.

Parameters
devThe pointer to the external flash device to use.
muxThe spi mux to set and disable on start and completion of the fw update operations.
Return values
0on success, if the spi mux was able to be set

◆ tt_fwupdate_is_confirmed()

int tt_fwupdate_is_confirmed ( void )

Check if the currently running firmware has been confirmed.

Return values
0if the currently running firmware has not been confirmed.
1if the currently running firmware has been confirmed.
-EIOif an I/O erorr occurs.

◆ tt_fwupdate_validate_fd()

int tt_fwupdate_validate_fd ( const tt_boot_fs_fd * fd)

Validate the provided boot filesystem file descriptor.

Parameters
fdA pointer to the file descriptor to validate.
Return values
0if fd is valid.
-EINVALif fd is NULL.
-ENOENTif fd is invalid.
-EIOif an I/O error occurs.

◆ tt_fwupdate_validate_image()

int tt_fwupdate_validate_image ( const tt_boot_fs_fd * fd)

Validate the image described by the provided boot filesystem file descriptor.

Parameters
fdA pointer to the file descriptor for the desired image.
Returns
0 if the image described by fd is valid.
Return values
-EINVALif fd is NULL.
-ENOENTif the image is invalid.
-EIOif an I/O error occurs.

◆ z_tt_boot_fs_erase()

int z_tt_boot_fs_erase ( uint32_t addr,
uint32_t size )
static

◆ z_tt_boot_fs_read()

int z_tt_boot_fs_read ( uint32_t addr,
uint32_t size,
uint8_t * dst )
static

◆ z_tt_boot_fs_write()

int z_tt_boot_fs_write ( uint32_t addr,
uint32_t size,
const uint8_t * src )
static

Variable Documentation

◆ boot_fs

tt_boot_fs boot_fs
static

◆ flash0_dev

const struct device* const flash0_dev = DEVICE_DT_GET( DT_NODELABEL(flash) )
static

◆ flash1_dev

const struct device* flash1_dev
static

◆ spi_mux

struct gpio_dt_spec spi_mux
static