1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-21 07:15:09 +03:00

Merge pull request #954 from opentx/bsongis/Bootloader_FIRMWARE_exported_in_masstorage

Bsongis/bootloader firmware exported in masstorage
This commit is contained in:
Andre Bernet 2014-04-08 16:50:11 +02:00
commit 578a94f744
6 changed files with 276 additions and 200 deletions

View file

@ -969,7 +969,7 @@ QString MainWindow::FindTaranisPath()
QString vName=QString::fromUtf16 ( (const ushort *) szVolumeName) ; QString vName=QString::fromUtf16 ( (const ushort *) szVolumeName) ;
if (vName.contains("TARANIS")) { if (vName.contains("TARANIS")) {
eepromfile=drive.absolutePath(); eepromfile=drive.absolutePath();
eepromfile.append("/TARANIS.BIN"); eepromfile.append("/EEPROM.BIN");
if (QFile::exists(eepromfile)) { if (QFile::exists(eepromfile)) {
pathcount++; pathcount++;
path=eepromfile; path=eepromfile;
@ -985,7 +985,7 @@ QString MainWindow::FindTaranisPath()
drives.append(entry->me_devname); drives.append(entry->me_devname);
eepromfile=entry->me_mountdir; eepromfile=entry->me_mountdir;
eepromfile.append("/TARANIS.BIN"); eepromfile.append("/EEPROM.BIN");
#if !defined __APPLE__ && !defined WIN32 #if !defined __APPLE__ && !defined WIN32
QString fstype=entry->me_type; QString fstype=entry->me_type;
qDebug() << fstype; qDebug() << fstype;

View file

@ -79,14 +79,6 @@
#define BOOTLOADER_TITLE "Boot Loader - Sky9x" #define BOOTLOADER_TITLE "Boot Loader - Sky9x"
#endif #endif
#define BOOTLOADER_SIZE 0x8000
#if defined(PCBTARANIS)
#define FIRMWARE_ADDRESS 0x08000000
#elif defined(PCBSKY9X)
#define FIRMWARE_ADDRESS 0x00400000
#endif
// states // states
enum BootLoaderStates { enum BootLoaderStates {
ST_START, ST_START,
@ -212,15 +204,12 @@ uint32_t isFirmwareStart( uint32_t *block )
uint32_t (*IAP_Function)(uint32_t, uint32_t); uint32_t (*IAP_Function)(uint32_t, uint32_t);
uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes void writeFlash(uint32_t *address, uint32_t *buffer) // size is 256 bytes
{ {
uint32_t FlashSectorNum; uint32_t FlashSectorNum;
uint32_t flash_cmd = 0; uint32_t flash_cmd = 0;
uint32_t i;
// uint32_t flash_status = 0;
// uint32_t EFCIndex = 0; // 0:EEFC0, 1: EEFC1
/* Initialize the function pointer (retrieve function address from NMI vector) */
/* Initialize the function pointer (retrieve function address from NMI vector) */
if ((uint32_t) address == FIRMWARE_START+BOOTLOADER_SIZE) { if ((uint32_t) address == FIRMWARE_START+BOOTLOADER_SIZE) {
if (isFirmwareStart(buffer)) if (isFirmwareStart(buffer))
FlashBlocked = 0; FlashBlocked = 0;
@ -229,7 +218,7 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
} }
if (FlashBlocked) { if (FlashBlocked) {
return 1; return;
} }
// Always initialise this here, setting a default doesn't seem to work // Always initialise this here, setting a default doesn't seem to work
@ -239,8 +228,7 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
FlashSectorNum &= 2047;// max page number FlashSectorNum &= 2047;// max page number
/* Send data to the sector here */ /* Send data to the sector here */
for ( i = 0; i < 64; i += 1 ) for (int i=0; i<FLASH_PAGESIZE/4; i++) {
{
*address++ = *buffer++; *address++ = *buffer++;
} }
@ -249,9 +237,8 @@ uint32_t program( uint32_t *address, uint32_t *buffer ) // size is 256 bytes
__disable_irq(); __disable_irq();
/* Call the IAP function with appropriate command */ /* Call the IAP function with appropriate command */
i = IAP_Function( 0, flash_cmd ); i = IAP_Function(0, flash_cmd);
__enable_irq(); __enable_irq();
return i;
} }
uint32_t readLockBits() uint32_t readLockBits()
@ -420,7 +407,7 @@ void eraseSector(uint32_t sector)
FLASH->CR &= SECTOR_MASK; FLASH->CR &= SECTOR_MASK;
} }
uint32_t program(uint32_t *address, uint32_t *buffer) // size is 256 bytes void writeFlash(uint32_t *address, uint32_t *buffer) // size is 256 bytes
{ {
uint32_t i; uint32_t i;
@ -434,7 +421,7 @@ uint32_t program(uint32_t *address, uint32_t *buffer) // size is 256 bytes
} }
if (FlashBlocked) { if (FlashBlocked) {
return 1; return;
} }
if ((uint32_t) address == 0x08008000) { if ((uint32_t) address == 0x08008000) {
@ -478,13 +465,12 @@ uint32_t program(uint32_t *address, uint32_t *buffer) // size is 256 bytes
/* Check the written value */ /* Check the written value */
if (*address != *buffer) { if (*address != *buffer) {
/* Flash content doesn't match SRAM content */ /* Flash content doesn't match SRAM content */
return 2; return;
} }
/* Increment FLASH destination address */ /* Increment FLASH destination address */
address += 1; address += 1;
buffer += 1; buffer += 1;
} }
return 0;
} }
#endif #endif
@ -877,11 +863,11 @@ int main()
uint32_t blockOffset = 0; uint32_t blockOffset = 0;
lcd_putsLeft(4*FH, "\032Loading..."); lcd_putsLeft(4*FH, "\032Loading...");
while (BlockCount) { while (BlockCount) {
program((uint32_t *) firmwareAddress, &Block_buffer[blockOffset]); // size is 256 bytes writeFlash((uint32_t *)firmwareAddress, &Block_buffer[blockOffset]);
blockOffset += 64; // 32-bit words (256 bytes) blockOffset += FLASH_PAGESIZE/4; // 32-bit words
firmwareAddress += 256; firmwareAddress += FLASH_PAGESIZE;
if (BlockCount > 256) { if (BlockCount > FLASH_PAGESIZE) {
BlockCount -= 256; BlockCount -= FLASH_PAGESIZE;
} }
else { else {
BlockCount = 0; BlockCount = 0;

View file

@ -43,6 +43,10 @@
extern uint16_t ResetReason; extern uint16_t ResetReason;
#define BOOTLOADER_SIZE 0x8000
#define FIRMWARE_SIZE (256*1024)
#define FIRMWARE_ADDRESS 0x00400000
#if defined(REVA) #if defined(REVA)
#define GPIO_BUTTON_MENU PIOB->PIO_PDSR #define GPIO_BUTTON_MENU PIOB->PIO_PDSR
#define GPIO_BUTTON_EXIT PIOA->PIO_PDSR #define GPIO_BUTTON_EXIT PIOA->PIO_PDSR

View file

@ -51,6 +51,7 @@ extern "C" {
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dma.h" #include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dma.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h" #include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h"
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h" #include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
#if !defined(SIMU) #if !defined(SIMU)
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc/usbd_hid_core.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/hid/inc/usbd_hid_core.h"
@ -72,6 +73,10 @@ extern "C" {
#include "audio_driver.h" #include "audio_driver.h"
#endif #endif
#define FLASHSIZE 0x80000
#define BOOTLOADER_SIZE 0x8000
#define FIRMWARE_ADDRESS 0x08000000
#define PERI1_FREQUENCY 30000000 #define PERI1_FREQUENCY 30000000
#define PERI2_FREQUENCY 60000000 #define PERI2_FREQUENCY 60000000
#define TIMER_MULT_APB1 2 #define TIMER_MULT_APB1 2
@ -136,6 +141,10 @@ void delay_01us(uint16_t nb);
#define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_Pin) #define SD_CARD_PRESENT() (~SD_PRESENT_GPIO->IDR & SD_PRESENT_GPIO_Pin)
#endif #endif
// Flash Write driver
#define FLASH_PAGESIZE 256
void writeFlash(uint32_t * address, uint32_t * buffer);
// Pulses driver // Pulses driver
void init_no_pulses(uint32_t port); void init_no_pulses(uint32_t port);
void disable_no_pulses(uint32_t port); void disable_no_pulses(uint32_t port);

View file

@ -139,7 +139,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
{ {
if (lun == 1) { if (lun == 1) {
*block_size = BLOCKSIZE; *block_size = BLOCKSIZE;
*block_num = EESIZE/BLOCKSIZE + 3 ; *block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
} }
else { else {
if (!SD_CARD_PRESENT()) if (!SD_CARD_PRESENT())
@ -282,12 +282,12 @@ const char g_FATboot[BLOCKSIZE] =
0xeb, 0x3c, 0x90, // Jump instruction. 0xeb, 0x3c, 0x90, // Jump instruction.
0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name 0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name
0x00, 0x02, // Bytes per sector 0x00, 0x02, // Bytes per sector
0x01, // Sectors per FS cluster. 0x08, // Sectors per FS cluster.
0x01, 0x00, // Reserved sector count 0x01, 0x00, // Reserved sector count
0x01, // Number of FATs 0x01, // Number of FATs
0x10, 0x00, // Number of root directory entries 0x10, 0x00, // Number of root directory entries
(EESIZE/BLOCKSIZE)+3, 0x00, // Total sectors = 131 3+(EESIZE/BLOCKSIZE), (FLASHSIZE/BLOCKSIZE)>>8, // Total sectors
0xf8, // Media descriptor 0xf8, // Media descriptor
0x01, 0x00, // Sectors per FAT table 0x01, 0x00, // Sectors per FAT table
0x20, 0x00, // Sectors per track 0x20, 0x00, // Sectors per track
@ -339,7 +339,7 @@ const char g_FATboot[BLOCKSIZE] =
const char g_FAT[BLOCKSIZE] = const char g_FAT[BLOCKSIZE] =
{ {
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B, 0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60, 0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0xF0, 0xFF, 0x13, 0x40, 0x01, 0x15, 0x60,
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02, 0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B, 0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60, 0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
@ -350,7 +350,8 @@ const char g_FAT[BLOCKSIZE] =
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B, 0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60, 0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08, 0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
0x81, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x20, 0x08, 0x83, 0x40, 0x08, 0x85, 0x60, 0x08, 0x87, 0x80, 0x08, 0x89, 0xA0, 0x08, 0x8B,
0xC0, 0x08, 0x8D, 0xE0, 0x08, 0x8F, 0x00, 0x09, 0x91, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -373,13 +374,19 @@ const char g_FAT[BLOCKSIZE] =
#else #else
const char g_FAT[BLOCKSIZE] = const char g_FAT[BLOCKSIZE] =
{ {
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B, 0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xF0, 0xFF, 0x0B,
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60, 0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02, 0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B, 0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60, 0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04, 0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04,
0x41, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x20, 0x04, 0x43, 0x40, 0x04, 0x45, 0x60, 0x04, 0x47, 0x80, 0x04, 0x49, 0xA0, 0x04, 0x4B,
0xC0, 0x04, 0x4D, 0xE0, 0x04, 0x4F, 0x00, 0x05, 0x51, 0x20, 0x05, 0x53, 0x40, 0x05, 0x55, 0x60,
0x05, 0x57, 0x80, 0x05, 0x59, 0xA0, 0x05, 0x5B, 0xC0, 0x05, 0x5D, 0xE0, 0x05, 0x5F, 0x00, 0x06,
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
0x81, 0x20, 0x08, 0x83, 0x40, 0x08, 0x85, 0x60, 0x08, 0x87, 0x80, 0x08, 0x89, 0xF0, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -399,12 +406,6 @@ const char g_FAT[BLOCKSIZE] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
#endif #endif
@ -454,7 +455,7 @@ const FATDirEntry_t g_DIRroot[16] =
0x00000000 0x00000000
}, },
{ {
{ 'T', 'A', 'R', 'A', 'N', 'I', 'S', ' '}, { 'E', 'E', 'P', 'R', 'O', 'M', ' ', ' '},
{ 'B', 'I', 'N'}, { 'B', 'I', 'N'},
0x24, // Archive, hidden, system 0x24, // Archive, hidden, system
0x00, 0x00,
@ -469,19 +470,19 @@ const FATDirEntry_t g_DIRroot[16] =
EESIZE EESIZE
}, },
{ {
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, { 'F', 'I', 'R', 'M', 'W', 'A', 'R', 'E'},
{ ' ', ' ', ' '}, { 'B', 'I', 'N'},
0x00, 0x24, // Archive, hidden, system
0x00,
0x00, 0x00,
0x3E,
0xA301,
0x3D55,
0x3D55,
0x0000, 0x0000,
0x0000, 0xA302,
0x0000, 0x3D55,
0x0000, 0x0002 + (EESIZE/BLOCKSIZE)/8,
0x0000, FLASHSIZE
0x0000,
0x0000,
0x00000000
}, },
{ {
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, { '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
@ -686,33 +687,42 @@ int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count )
while ( count ) while ( count )
{ {
if (sector == 0) { if (sector == 0) {
memcpy( buffer, g_FATboot, BLOCKSIZE ) ; memcpy(buffer, g_FATboot, BLOCKSIZE ) ;
} }
else if (sector == 1/*Reserved sector count*/) { else if (sector == 1/*Reserved sector count*/) {
// FAT table. // FAT table.
memcpy( buffer, g_FAT, BLOCKSIZE); memcpy(buffer, g_FAT, BLOCKSIZE);
} }
else if (sector == 2) { else if (sector == 2) {
memcpy( buffer, g_DIRroot, BLOCKSIZE ) ; memcpy(buffer, g_DIRroot, BLOCKSIZE ) ;
} }
else { else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
eeprom_read_block (buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); eeprom_read_block (buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
} }
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
uint32_t address;
address = sector - 3 - (EESIZE/BLOCKSIZE);
address *= BLOCKSIZE;
address += FIRMWARE_ADDRESS;
memcpy(buffer, (uint8_t *)address, BLOCKSIZE);
}
buffer += BLOCKSIZE ; buffer += BLOCKSIZE ;
sector++ ; sector++ ;
count-- ; count-- ;
} }
return 0 ; return 0 ;
} }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count ) int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
{ {
static int offset = 0; static int offset = 0;
TRACE("FAT12 Write(sector=%d, count=%d)", sector, count); TRACE("FAT12 Write(sector=%d, count=%d)", sector, count);
if (sector < 3) {
// reserved, read-only
}
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
while (count) { while (count) {
const EeFs * test = (const EeFs *)buffer; const EeFs * test = (const EeFs *)buffer;
if (offset == 0 && test->version==EEFS_VERS && test->mySize==sizeof(eeFs) && test->bs==BS) { if (offset == 0 && test->version==EEFS_VERS && test->mySize==sizeof(eeFs) && test->bs==BS) {
@ -730,9 +740,26 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
offset = 0; offset = 0;
} }
} }
}
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
// firmware
uint32_t address;
address = sector - 3 - (EESIZE/BLOCKSIZE);
address *= BLOCKSIZE;
address += FIRMWARE_ADDRESS;
while (count) {
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
writeFlash((uint32_t *)address, (uint32_t *)buffer);
}
address += FLASH_PAGESIZE;
buffer += FLASH_PAGESIZE;
}
count--;
}
}
return 0 ; return 0 ;
} }
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

50
radio/util/fat12.py Executable file
View file

@ -0,0 +1,50 @@
#!/bin/env python
curr = 0
idx = 0
byte = 0
def push4bits(val):
global curr, idx, byte
val = val & 0x0f
curr += val << idx
idx += 4
if idx == 8:
print "0x%02X," % curr,
idx = 0
curr = 0
byte += 1
if byte % 16 == 0:
print
cluster = 0
def pushCluster(val):
global cluster
push4bits(val)
push4bits(val >> 4)
push4bits(val >> 8)
cluster += 1
def pushFile(size):
sectors = size / 512
count = sectors / 8
for i in range(count-1):
pushCluster(cluster+1)
pushCluster(0xFFF)
def pushDisk(eeprom, flash):
global curr, idx, byte, cluster
curr = idx = byte = cluster = 0
print "Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash)
pushCluster(0xFF8)
pushCluster(0xFFF)
pushFile(eeprom*1024)
pushFile(flash*1024)
while byte < 512:
push4bits(0)
print
pushDisk(32, 512)
pushDisk(64, 512)