SAM4L USB Host Mass Storage Bootloader Application with CRC Check and AES decryption support.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <string.h>
#include "conf_usb_host.h"
#include "conf_bootloader.h"
#include "main.h"
Macros | |
#define | GPIO_BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1F)) |
#define | GPIO_BOOT_PIN_PORT |
Functions | |
static void | bootloader_mode_check () |
Function to check the bootloader mode activaton. More... | |
static void | bootloader_system_init () |
Initializes the device for the bootloader. More... | |
static void | crc32_calculate (uint32_t address, uint32_t size) |
static bool | integrity_check () |
Function to check the integrity of the firmware. More... | |
int | main (void) |
Main function. More... | |
void | main_usb_connection_event (uhc_device_t *dev, bool b_present) |
Callback on enumeration status change of a MSC device. More... | |
void | main_usb_sof_event (void) |
Notify that a SOF has been sent (each 1 ms) More... | |
static bool | program_memory () |
Function to program the Flash. More... | |
static void | start_application (void) |
Function to start the application. More... | |
static void | start_application_with_wdt () |
Function to issue a WDT reset to start the application. More... | |
Variables | |
COMPILER_WORD_ALIGNED volatile uint8_t | buffer [FLASH_BUFFER_SIZE] |
static crccu_dscr_type_t | crc_dscr |
static DIR | file_dir |
static FIL | file_object |
static uint32_t | firmware_crc = 0 |
static FATFS | fs |
char | input_file_name [] |
static volatile bool | lun_connected = false |
static volatile uint32_t | sof_count = 0 |
#define GPIO_BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1F)) |
Referenced by bootloader_mode_check().
#define GPIO_BOOT_PIN_PORT |
|
static |
Function to check the bootloader mode activaton.
References flashcalw_read_gp_fuse_bit(), GPIO_BOOT_PIN_MASK, start_application(), and temp.
Referenced by main().
|
static |
Initializes the device for the bootloader.
References board_init(), cpu_irq_enable, sleepmgr_init(), sysclk_enable_peripheral_clock(), sysclk_init(), and uhc_start().
Referenced by main().
|
static |
References crccu_configure_descriptor(), crccu_configure_mode(), crccu_enable_dma(), crccu_get_dma_status(), CRCCU_TR_CTRL_IEN_DISABLE, and CRCCU_TR_CTRL_TRWIDTH_BYTE.
Referenced by integrity_check(), and program_memory().
|
static |
Function to check the integrity of the firmware.
References buffer, crc32_calculate(), crccu_read_crc_value(), crccu_reset(), f_close(), f_lseek(), f_open(), f_read(), FA_OPEN_EXISTING, FA_READ, firmware_crc, input_file_name, and NULL.
Referenced by main().
int main | ( | void | ) |
Main function.
Execution starts here.
References bootloader_mode_check(), bootloader_system_init(), cpu_irq_disable, f_close(), f_mount(), f_open(), f_opendir(), FA_OPEN_EXISTING, FA_READ, flashcalw_erase_gp_fuse_bit(), flashcalw_is_security_bit_active(), flashcalw_read_gp_fuse_bit(), flashcalw_set_security_bit(), FR_OK, FIL::fsize, input_file_name, integrity_check(), lun_connected, NULL, program_memory(), sof_count, start_application_with_wdt(), uhc_stop(), and uhi_msc_mem_get_lun().
void main_usb_connection_event | ( | uhc_device_t * | dev, |
bool | b_present | ||
) |
Callback on enumeration status change of a MSC device.
Notify that a USB device has been connected or disconnected.
References lun_connected, sof_count, and UNUSED.
void main_usb_sof_event | ( | void | ) |
Notify that a SOF has been sent (each 1 ms)
References sof_count.
|
static |
Function to program the Flash.
Decrypt the firmware and program it.
References aes_set_new_message(), buffer, cpu_irq_disable, cpu_irq_enable, crc32_calculate(), crccu_read_crc_value(), crccu_reset(), f_close(), f_open(), f_read(), FA_OPEN_EXISTING, FA_READ, firmware_crc, FLASH_PAGE_SIZE, flashcalw_erase_page(), flashcalw_is_lock_error(), flashcalw_is_programming_error(), flashcalw_memcpy(), g_aes_inst, input_file_name, ioport_set_pin_level(), min, and NULL.
Referenced by main().
|
static |
Function to start the application.
Referenced by bootloader_mode_check().
|
static |
Function to issue a WDT reset to start the application.
This will reset the clock & peripheral configurations.
References cpu_irq_disable, and ioport_set_pin_level().
Referenced by main().
COMPILER_WORD_ALIGNED volatile uint8_t buffer[FLASH_BUFFER_SIZE] |
|
static |
|
static |
|
static |
|
static |
Referenced by integrity_check(), and program_memory().
|
static |
char input_file_name[] |
Referenced by integrity_check(), main(), and program_memory().
Referenced by main(), and main_usb_connection_event().
|
static |
Referenced by main(), main_usb_connection_event(), and main_usb_sof_event().