main_ubi_sdk v 0.1.3
This is UBI4 documentation
update_fw.c File Reference
#include "utils/update_fw.h"
#include "utils/while_sheduller.h"
#include "utils/base_soft_timer.h"
#include "HAL_DRIVERS.h"
#include "stdlib.h"
Include dependency graph for update_fw.c:

Data Structures

struct  temp_write_to_flash_from_while_struct
 
struct  temp_clear_flash_from_while_struct
 
union  Update_FW_temp_union_structs
 

Functions

static void Get_Run_Program_Type (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 The "Get_Run_Program_Type" function is needed to determine which program the device is currently in. In the loader program or the main program.
 
static void Jump_To_Bootloader (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 A function for switching to the loader program.
 
static void Check_New_FW (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 A function that verifies the firmware that will be transferred from the master.
 
void clear_flash_from_while (temp_clear_flash_from_while_struct *args)
 
static void Preload_Info (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 The function of preparing the device for firmware.
 
void write_to_flash_from_while (temp_write_to_flash_from_while_struct *args)
 
static void Load_New_FW (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 This function loads the firmware into flash.
 
static void Get_Bootloader_Status (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 This function sends a Process_boot.
 
void calculate_crc_from_while (void *args)
 
static void Enable_Calculate_CRC (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 A function for calculating CRC.
 
void start_program_from_while (void *soft_timer_obj, int instance, void *args)
 
static void Get_CRC (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 A function for determining the correctness of the calculated CRC.
 
static void Get_Bootloader_Info (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 The function sends data about the loader program to the wizard.
 
static void Get_Up_Load_Atribute (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 The function sends the chunck size to the master.
 
void JumpToProgramCommand (uint32_t address_to_jump)
 The function goes to the received address.
 
void Update_FW_Receive (base_device_information_struct *deviceInfo, ubi4_bus_protocol_obj_struct *protocol_str, protocol_receive_struct receive_str)
 A function that determines which command has arrived and which state needs to be switched to.
 
void Init_Need_Struct_For_FW (base_BootloaderInfo_struct *base_boot, base_FWInfo_struct *base_fw, base_BoardInfo_struct *base_board)
 A function for initializing "Bootloader_struct", "FW_struct" and "Board_struct" from flash.
 
__weak uint8_t Compare_Data (void)
 A function for verifying the firmware.
 
void Calculate_CRC ()
 A function for calculating the CRC of downloaded firmware from memory.
 
uint8_t Get_Enable_CRC (void)
 The function returned by flag_crc.
 
void Set_Enable_CRC (uint8_t value)
 The function being modified by flag_crc.
 

Variables

uint16_t compare_data_mask = COMPARE_DATA_MASK
 
uint8_t flag_crc = END_CALCULATE_CRC
 
uint32_t write_fw_pointer = 0
 
uint32_t crc_firmware_from_master = 0
 
uint32_t crc_firmware_calculate = 0
 
uint8_t data_for_boot [SIZE_BUFF_FOR_BOOT]
 
base_BootloaderInfo_structBootloader_struct
 
base_FWInfo_structFW_struct
 
base_BoardInfo_structBoard_struct
 
FW_info_struct fw_info
 
FW_up_load_atribute parametrs
 
state_process_bootloader Process_boot =BOOTLOADER_IDLE
 
uint8_t array_sizeof_for_compare [SIZE_FW_INFO_STRUCT]
 
union Update_FW_temp_union_structs UpdateFWtempData
 

Function Documentation

◆ Calculate_CRC()

void Calculate_CRC ( )

A function for calculating the CRC of downloaded firmware from memory.

Returns
Nothing.

Available to call in any module.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_crc_from_while()

void calculate_crc_from_while ( void * args)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Check_New_FW()

static void Check_New_FW ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

A function that verifies the firmware that will be transferred from the master.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

If the firmware does not match the device, the function sends a BAD_COMPARE message to the master. When the firmware matches the device, the function sends a GOOD_COMPARE message to the master. It also sends the command that called this function.

Assigns the status to the global variable Process_boot in what state the program is currently in. Resets write_fw_pointer.

Assigns the received structure from the wizard to the fw_info structure. Receives the reference CRC of the firmware.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_flash_from_while()

void clear_flash_from_while ( temp_clear_flash_from_while_struct * args)
Here is the caller graph for this function:

◆ Compare_Data()

__weak uint8_t Compare_Data ( void )

A function for verifying the firmware.

Parameters
Nothing.
Returns
1 - if the firmware is correct. 0 - in case of a firmware mismatch.

Available to call in any module.

Here is the caller graph for this function:

◆ Enable_Calculate_CRC()

static void Enable_Calculate_CRC ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

A function for calculating CRC.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

Sends 0x01 to the master in order to make sure that the command has reached the slave. It sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Changes the value of the flag_crc flag to BEGIN_CALCULATE_CRC - the CRC can be considered.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get_Bootloader_Info()

static void Get_Bootloader_Info ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

The function sends data about the loader program to the wizard.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

It sends the command that called this function.

Here is the caller graph for this function:

◆ Get_Bootloader_Status()

static void Get_Bootloader_Status ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

This function sends a Process_boot.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

It sends the command that called this function.

Here is the caller graph for this function:

◆ Get_CRC()

static void Get_CRC ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

A function for determining the correctness of the calculated CRC.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

If the calculated CRC matches the CRC received from the wizard, the device sends GOOD_CRC_FIRMWARE and jumps to MAIN_PROGRAM_START_ADDRESS. If the calculated CRC does not match the CRC received from the wizard, the device sends BAD_CRC_FIRMWARE and remains in the loader program. It sends the command that called this function.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get_Enable_CRC()

uint8_t Get_Enable_CRC ( void )

The function returned by flag_crc.

Parameters
Nothing.
Returns
flag_crc.

Available to call in any module.

◆ Get_Run_Program_Type()

static void Get_Run_Program_Type ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

The "Get_Run_Program_Type" function is needed to determine which program the device is currently in. In the loader program or the main program.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

Sends the wizard the mode in which the device is located. It also sends the command that called this function. BOOTLOADER_IDLE - the loader program. IN_MAIN_APP_STATUS - main program.

Assigns the status to the global variable Process_boot in what state the program is currently in.

Here is the caller graph for this function:

◆ Get_Up_Load_Atribute()

static void Get_Up_Load_Atribute ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

The function sends the chunck size to the master.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

It sends the command that called this function.

Here is the caller graph for this function:

◆ Init_Need_Struct_For_FW()

void Init_Need_Struct_For_FW ( base_BootloaderInfo_struct * base_boot,
base_FWInfo_struct * base_fw,
base_BoardInfo_struct * base_board )

A function for initializing "Bootloader_struct", "FW_struct" and "Board_struct" from flash.

Parameters
base_boot- a pointer to a structure containing information about the loader program itself. base_fw - a pointer to a structure containing information about the firmware received from the master device. base_board - a pointer to a structure containing information about the board itself, which is necessary for firmware verification.
Returns
Nothing.

Available to call in any module.

◆ Jump_To_Bootloader()

static void Jump_To_Bootloader ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

A function for switching to the loader program.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

Writes the firmware-enabling flag to the flash memory. Restarts the device.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JumpToProgramCommand()

void JumpToProgramCommand ( uint32_t address_to_jump)

The function goes to the received address.

Parameters
address_to_jump- The program's transition address.
Returns
Nothing.

◆ Load_New_FW()

static void Load_New_FW ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

This function loads the firmware into flash.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

It sends the size of the received fragments to the master device to make sure that the command has reached the slave device, as well as to determine the offset in the firmware file. It also sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Receives from the master the offset and a part of the firmware, the size of which is equal to chunck. The end address of the firmware is considered to be write_fw_pointer. The MAIN PROGRAM_START_ADDRESS is the initial address of the firmware, to which the offset received from the wizard is added to determine which address to write a new piece of firmware to.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Preload_Info()

static void Preload_Info ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )
static

The function of preparing the device for firmware.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

Sends 0x01 to the master in order to make sure that the command has reached the slave. It also sends the command that called this function. Assigns the status to the global variable Process_boot in what state the program is currently in. Resets write_fw_pointer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set_Enable_CRC()

void Set_Enable_CRC ( uint8_t value)

The function being modified by flag_crc.

Parameters
value- the flag_crc value..
Returns
Nothing.

Available to call in any module.

◆ start_program_from_while()

void start_program_from_while ( void * soft_timer_obj,
int instance,
void * args )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update_FW_Receive()

void Update_FW_Receive ( base_device_information_struct * deviceInfo,
ubi4_bus_protocol_obj_struct * protocol_str,
protocol_receive_struct receive_str )

A function that determines which command has arrived and which state needs to be switched to.

Parameters
deviceInfo- a pointer to a structure containing information about the device. protocol_str - a pointer to a structure for communication. receive_str - a structure containing information about the received data.
Returns
Nothing.

The first byte of the received buffer is the status. Takes the value from "update_fw_state_enum". Available for calling in other libraries.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_to_flash_from_while()

void write_to_flash_from_while ( temp_write_to_flash_from_while_struct * args)
Here is the caller graph for this function:

Variable Documentation

◆ array_sizeof_for_compare

uint8_t array_sizeof_for_compare[SIZE_FW_INFO_STRUCT]
Initial value:
=
{
sizeof(fw_info.BoardName),
sizeof(fw_info.BoardVersion),
sizeof(fw_info.BoardSubVersion),
sizeof(fw_info.BoardRev),
sizeof(fw_info.BoardSubRev),
sizeof(fw_info.BoardBuild),
sizeof(fw_info.BoardType),
sizeof(fw_info.BoardCode),
sizeof(fw_info.BoardAdditionalInfoType),
sizeof(fw_info.BoardAdditionalInfo),
}
FW_info_struct fw_info
Definition update_fw.c:68
Parameters
array_sizeof_for_compare- an array containing the field sizes of the structure containing information about the board required for firmware verification.

◆ Board_struct

base_BoardInfo_struct* Board_struct

◆ Bootloader_struct

base_BootloaderInfo_struct* Bootloader_struct

Required global structure for the loader to work.

Parameters
Bootloader_struct- a pointer to a structure containing information about the loader program itself. FW_struct - a pointer to a structure containing information about the firmware received from the master device. Board_struct - A pointer to a structure containing information about the board itself, which is necessary for firmware verification. fw_info - a structure containing information about the firmware and the board from the wizard. deviceInfo_Test -

◆ compare_data_mask

uint16_t compare_data_mask = COMPARE_DATA_MASK

This library is universal and contains functions for downloading new firmware. It doesn't matter which controller is used or which interface the device communicates with. Is he a master or a slave. A detailed description of each function is described below.

These are variables that depend on the externally mutable values of the constants CHUNCK_SIZE and COMPARE_DATA_MASK, which are contained in the UBI_SDK.h library.

Parameters
chunck_size- required size of data acquisition for recording in flash. compare_data_mask - the mask used to determine which properties of the board need to be compared to determine the correctness of the firmware.

◆ crc_firmware_calculate

uint32_t crc_firmware_calculate = 0

◆ crc_firmware_from_master

uint32_t crc_firmware_from_master = 0

◆ data_for_boot

uint8_t data_for_boot[SIZE_BUFF_FOR_BOOT]

◆ flag_crc

uint8_t flag_crc = END_CALCULATE_CRC

Required global variables for the loader to work.

Parameters
flag_crc- A flag that determines whether the CRC of the downloaded firmware has been calculated, it can be obtained and changed using the functions contained in this library. write_fw_pointer - the total offset from the initial firmware address. crc_firmware_from_master - CRC received from the master. crc_firmware_calculate - the calculated CRC after downloading the firmware. data_for_boot - an auxiliary array for downloading firmware, obtained from the received data, with a size of SIZE_BUFF_FOR_BOOT - 1024.

◆ fw_info

FW_info_struct fw_info

◆ FW_struct

base_FWInfo_struct* FW_struct

◆ parametrs

Initial value:
=
{
.chanck_size=CHUNCK_SIZE,
.bytes_interval=BYTES_INTERVAL_FOR_FW,
.timeout_ms=TIMEOUT_SEND_FOR_FW,
.flash_clear_delay_ms=TIMEOUT_CLEAR_FLASH
}

◆ Process_boot

Parameters
Process_boot- the enum is used to determine the current state of the device.

◆ UpdateFWtempData

union Update_FW_temp_union_structs UpdateFWtempData

◆ write_fw_pointer

uint32_t write_fw_pointer = 0