Switchtec Userspace  PROJECT_NUMBER = PROJECT_NUMBER=PROJECT_NUMBER = 2.2
Classes | Functions
Firmware Management

Retrieve firmware information and update or retrieve images. More...

Classes

struct  switchtec_fw_footer_gen3
 
struct  switchtec_fw_metadata_gen4
 
struct  switchtec_fw_image_header_gen3
 
struct  cmd_fwdl
 
struct  switchtec_flash_info_gen4
 
struct  switchtec_boot_ro
 

Functions

int switchtec_fw_toggle_active_partition (struct switchtec_dev *dev, int toggle_bl2, int toggle_key, int toggle_fw, int toggle_cfg)
 Toggle the active firmware partition for the main or configuration images. More...
 
int switchtec_fw_setup_redundancy (struct switchtec_dev *dev, enum switchtec_fw_redundancy redund, enum switchtec_fw_type type)
 Set or clear the redundancy flag of a partition type. More...
 
int switchtec_fw_write_fd (struct switchtec_dev *dev, int img_fd, int dont_activate, int force, void(*progress_callback)(int cur, int tot))
 Write a firmware file to the switchtec device. More...
 
int switchtec_fw_write_file (struct switchtec_dev *dev, FILE *fimg, int dont_activate, int force, void(*progress_callback)(int cur, int tot))
 Write a firmware file to the switchtec device. More...
 
void switchtec_fw_perror (const char *s, int ret)
 Print an error string to stdout. More...
 
int switchtec_fw_file_info (int fd, struct switchtec_fw_image_info *info)
 Retrieve information about a firmware image file. More...
 
int switchtec_fw_file_secure_version_newer (struct switchtec_dev *dev, int img_fd)
 Check if the secure version of an image file is newer than that of the image on device. More...
 
const char * switchtec_fw_image_type (const struct switchtec_fw_image_info *info)
 Return a string describing the type of a firmware image. More...
 
static int switchtec_fw_part_info (struct switchtec_dev *dev, int nr_info, struct switchtec_fw_image_info *info)
 Return firmware information structures for a number of firmware partitions. More...
 
struct switchtec_fw_part_summaryswitchtec_fw_part_summary (struct switchtec_dev *dev)
 Return firmware summary information structure for the flash partitfons in the device. More...
 
void switchtec_fw_part_summary_free (struct switchtec_fw_part_summary *summary)
 Free a firmware part summary data structure. More...
 
int switchtec_fw_read (struct switchtec_dev *dev, unsigned long addr, size_t len, void *buf)
 Read a Switchtec device's flash data. More...
 
int switchtec_fw_read_fd (struct switchtec_dev *dev, int fd, unsigned long addr, size_t len, void(*progress_callback)(int cur, int tot))
 Read a Switchtec device's flash data into a file. More...
 
int switchtec_fw_body_read_fd (struct switchtec_dev *dev, int fd, struct switchtec_fw_image_info *info, void(*progress_callback)(int cur, int tot))
 Read a Switchtec device's flash image body into a file. More...
 
int switchtec_fw_img_write_hdr (int fd, struct switchtec_fw_image_info *info)
 Write the header for a Switchtec firmware image file. More...
 
int switchtec_fw_is_boot_ro (struct switchtec_dev *dev)
 Check if the boot partition is marked as read-only. More...
 
int switchtec_fw_set_boot_ro (struct switchtec_dev *dev, enum switchtec_fw_ro ro)
 Set or clear a boot partition's read-only flag. More...
 
int switchtec_flash_part (struct switchtec_dev *dev, struct switchtec_fw_image_info *info, enum switchtec_fw_image_part_id_gen3 part)
 Retrieve information about a flash partition. More...
 

Detailed Description

Retrieve firmware information and update or retrieve images.

switchtec_fw_write_fd() may be used to update a Switchtec firmware image. switchtec_fw_read_fd() can retrieve a firmware image into a local file. switchtec_fw_img_info() and switchtec_fw_cfg_info() may be used to query information about the currently programmed images.

Function Documentation

int switchtec_flash_part ( struct switchtec_dev *  dev,
struct switchtec_fw_image_info info,
enum switchtec_fw_image_part_id_gen3  part 
)

Retrieve information about a flash partition.

Parameters
[in]devSwitchtec device handle
[out]infoStructure to place the result in
[in]partWhich partition to retrieve
Returns
0 on success, negative on failure

Definition at line 251 of file platform.c.

int switchtec_fw_body_read_fd ( struct switchtec_dev *  dev,
int  fd,
struct switchtec_fw_image_info info,
void(*)(int cur, int tot)  progress_callback 
)

Read a Switchtec device's flash image body into a file.

Parameters
[in]devSwitchtec device handle
[in]fdFile descriptor for image file to write
[in]infoPartition information structure
[in]progress_callbackThis function is called periodically to indicate the progress of the read. May be NULL.
Returns
number of bytes written on success, error code on failure

Definition at line 1393 of file fw.c.

int switchtec_fw_file_info ( int  fd,
struct switchtec_fw_image_info info 
)

Retrieve information about a firmware image file.

Parameters
[in]fdFile descriptor for the image file to inspect
[out]infoStructure populated with information about the file
Returns
0 on success, error code on failure

Definition at line 683 of file fw.c.

int switchtec_fw_file_secure_version_newer ( struct switchtec_dev *  dev,
int  img_fd 
)

Check if the secure version of an image file is newer than that of the image on device.

Parameters
[in]devSwitchtec device handle
[in]img_fdImage file descriptor
Returns
1 if image file secure version > device secure version 0 if image file secure version <= device secure version, or error

Definition at line 716 of file fw.c.

const char* switchtec_fw_image_type ( const struct switchtec_fw_image_info info)

Return a string describing the type of a firmware image.

Parameters
[out]infoInformation structure to return the type string for
Returns
Type string

Definition at line 765 of file fw.c.

int switchtec_fw_img_write_hdr ( int  fd,
struct switchtec_fw_image_info info 
)

Write the header for a Switchtec firmware image file.

Parameters
[in]fdFile descriptor for image file to write
[in]infoPartition information structure
Returns
number of bytes written on success, error code on failure

The offset of image body in the image file is greater than or equal to the image header length. This function also repositions the read/write file offset of fd to the offset of image body in the image file if needed. This will facilitate the switchtec_fw_read_fd() function which is usually called following this function to complete a firmware image read.

Definition at line 1452 of file fw.c.

int switchtec_fw_is_boot_ro ( struct switchtec_dev *  dev)

Check if the boot partition is marked as read-only.

Parameters
[in]devSwitchtec device handle
Returns
1 if the partition is read-only, 0 if it's not or a negative value if an error occurred

Definition at line 1476 of file fw.c.

static int switchtec_fw_part_info ( struct switchtec_dev *  dev,
int  nr_info,
struct switchtec_fw_image_info info 
)
static

Return firmware information structures for a number of firmware partitions.

Parameters
[in]devSwitchtec device handle
[in]nr_infoNumber of partitions to retrieve the info for
[out]infoPointer to a list of info structs of at least nr_info entries
Returns
number of part info on success, negative on failure

Definition at line 1036 of file fw.c.

struct switchtec_fw_part_summary* switchtec_fw_part_summary ( struct switchtec_dev *  dev)

Return firmware summary information structure for the flash partitfons in the device.

Parameters
[in]devSwitchtec device handle nr_info entries
Returns
pointer to the structure on success, NULL on error. Free the the structure with switchtec_fw_part_summary_free.

Definition at line 1203 of file fw.c.

void switchtec_fw_part_summary_free ( struct switchtec_fw_part_summary summary)

Free a firmware part summary data structure.

Parameters
[in]summaryThe data structure to free.

Definition at line 1282 of file fw.c.

void switchtec_fw_perror ( const char *  s,
int  ret 
)

Print an error string to stdout.

Parameters
[in]sString that will be prefixed to the error message
[in]retThe value returned by the firmware function

This can be called after Switchtec firmware function returned an error to find out what caused the problem.

Definition at line 493 of file fw.c.

int switchtec_fw_read ( struct switchtec_dev *  dev,
unsigned long  addr,
size_t  len,
void *  buf 
)

Read a Switchtec device's flash data.

Parameters
[in]devSwitchtec device handle
[in]addrAddress to read from
[in]lenNumber of bytes to read
[out]bufDestination buffer to read the data to
Returns
0 on success, error code on failure

Definition at line 1300 of file fw.c.

int switchtec_fw_read_fd ( struct switchtec_dev *  dev,
int  fd,
unsigned long  addr,
size_t  len,
void(*)(int cur, int tot)  progress_callback 
)

Read a Switchtec device's flash data into a file.

Parameters
[in]devSwitchtec device handle
[in]fdFile descriptor of the file to save the firmware data to
[in]addrAddress to read from
[in]lenNumber of bytes to read
[in]progress_callbackThis function is called periodically to indicate the progress of the read. May be NULL.
Returns
0 on success, error code on failure

Definition at line 1344 of file fw.c.

int switchtec_fw_set_boot_ro ( struct switchtec_dev *  dev,
enum switchtec_fw_ro  ro 
)

Set or clear a boot partition's read-only flag.

Parameters
[in]devSwitchtec device handle
[in]roWhether to set or clear the read-only flag
Returns
0 on success, error code on failure

Definition at line 1515 of file fw.c.

int switchtec_fw_setup_redundancy ( struct switchtec_dev *  dev,
enum switchtec_fw_redundancy  redund,
enum switchtec_fw_type  type 
)

Set or clear the redundancy flag of a partition type.

Parameters
[in]devSwitchtec device handle
[in]redundWhether to set or clear the redundancy flag
[in]typeSwitchtec fw partition type
Returns
0 on success, error code on failure

This function does not support Gen3 switch.

Definition at line 249 of file fw.c.

int switchtec_fw_toggle_active_partition ( struct switchtec_dev *  dev,
int  toggle_bl2,
int  toggle_key,
int  toggle_fw,
int  toggle_cfg 
)

Toggle the active firmware partition for the main or configuration images.

Parameters
[in]devSwitchtec device handle
[in]toggle_bl2Set to 1 to toggle the BL2 FW image
[in]toggle_keySet to 1 to toggle the key manifest FW image
[in]toggle_fwSet to 1 to toggle the main FW image
[in]toggle_cfgSet to 1 to toggle the config FW image
Returns
0 on success, error code on failure

Definition at line 187 of file fw.c.

int switchtec_fw_write_fd ( struct switchtec_dev *  dev,
int  img_fd,
int  dont_activate,
int  force,
void(*)(int cur, int tot)  progress_callback 
)

Write a firmware file to the switchtec device.

Parameters
[in]devSwitchtec device handle
[in]img_fdFile descriptor for the image file to write
[in]forceIf 1, ignore if another download command is already in progress.
[in]dont_activateIf 1, the new image will not be activated
[in]progress_callbackIf not NULL, this function will be called to indicate the progress.
Returns
0 on success, error code on failure

Definition at line 299 of file fw.c.

int switchtec_fw_write_file ( struct switchtec_dev *  dev,
FILE *  fimg,
int  dont_activate,
int  force,
void(*)(int cur, int tot)  progress_callback 
)

Write a firmware file to the switchtec device.

Parameters
[in]devSwitchtec device handle
[in]fimgFILE pointer for the image file to write
[in]dont_activateIf 1, the new image will not be activated
[in]forceIf 1, ignore if another download command is already in progress.
[in]progress_callbackIf not NULL, this function will be called to indicate the progress.
Returns
0 on success, error code on failure

Definition at line 397 of file fw.c.