Microchip® Advanced Software Framework

sam/applications/sam4l_host_msc_aes_bootloader/bootloader/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"

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
Value:
((volatile GpioPort *)(GPIO_ADDR + \
(BOOT_LOAD_PIN >> 5) * sizeof(GpioPort)))

static void bootloader_mode_check ( void  )
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 void bootloader_system_init ( void  )
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 void crc32_calculate ( uint32_t  address,
uint32_t  size 
)
static
static bool integrity_check ( void  )
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().

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.

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 cpu_irq_disable, and ioport_set_pin_level().

Referenced by main().

COMPILER_WORD_ALIGNED volatile uint8_t buffer[FLASH_BUFFER_SIZE]
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
char input_file_name[]
Initial value:
= {
FIRMWARE_IN_FILE_NAME
}

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