Microchip® Advanced Software Framework

main.c File Reference

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"
#include "aesa.h"

Macros

#define GPIO_BOOT_PIN_MASK   (1U << (BOOT_LOAD_PIN & 0x1F))
 
#define GPIO_BOOT_PIN_PORT
 

Functions

static void aes_decrypt (uint32_t *encrypted_data, uint32_t size)
 AES Decryption routine. More...
 
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 console_init (void)
 Initializes the console output. More...
 
static void crc32_calculate (uint32_t address, uint32_t size)
 
static void init_aes ()
 AES Initialization routine. More...
 
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
uint32_t 
aes_output [FLASH_BUFFER_SIZE/4]
 
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
 
struct aes_config g_aes_cfg
 
struct aes_dev_inst g_aes_inst
 
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
Value:
((volatile GpioPort *)(GPIO_ADDR + \
(BOOT_LOAD_PIN >> 5) * sizeof(GpioPort)))
#define BOOT_LOAD_PIN
GPIO pin used to activate the bootloader mode.
Definition: conf_bootloader.h:59

static void aes_decrypt ( uint32_t *  encrypted_data,
uint32_t  size 
)
static

AES Decryption routine.

References aes_read_output_data(), aes_read_status(), aes_write_input_data(), and g_aes_inst.

Referenced by integrity_check(), and program_memory().

static void bootloader_mode_check ( void  )
static

Function to check the bootloader mode activaton.

References APP_START_ADDRESS, BOOT_GP_FUSE_BIT, BOOT_LOAD_PIN, BOOT_LOAD_PIN_ACTIVE_LVL, flashcalw_read_gp_fuse_bit(), GPIO_BOOT_PIN_MASK, and start_application().

Referenced by main().

static void bootloader_system_init ( void  )
static

Initializes the device for the bootloader.

References board_init(), console_init(), cpu_irq_enable, sleepmgr_init(), sysclk_enable_peripheral_clock(), sysclk_init(), and uhc_start().

Referenced by main().

static void console_init ( void  )
static
static bool integrity_check ( void  )
static
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 void start_application ( void  )
static

Function to start the application.

References APP_START_ADDRESS.

Referenced by bootloader_mode_check().

static void start_application_with_wdt ( )
static

Function to issue a WDT reset to start the application.

This will reset the clock & peripheral configurations.

References BOOT_LED, BOOT_LED_ON_LVL, cpu_irq_disable, and ioport_set_pin_level().

Referenced by main().

COMPILER_WORD_ALIGNED volatile uint32_t aes_output[FLASH_BUFFER_SIZE/4]
COMPILER_WORD_ALIGNED volatile uint8_t buffer[FLASH_BUFFER_SIZE]

Referenced by integrity_check(), and program_memory().

crccu_dscr_type_t crc_dscr
static
DIR file_dir
static
FIL file_object
static
uint32_t firmware_crc = 0
static

Referenced by integrity_check(), and program_memory().

FATFS fs
static

Referenced by chk_mounted(), and f_mount().

struct aes_config g_aes_cfg

Referenced by init_aes().

struct aes_dev_inst g_aes_inst
char input_file_name[]
Initial value:
= {
}
#define FIRMWARE_IN_FILE_NAME
Definition: conf_bootloader.h:57

Referenced by integrity_check(), main(), and program_memory().

volatile bool lun_connected = false
static

Referenced by main(), and main_usb_connection_event().

volatile uint32_t sof_count = 0
static