added toplevel makefile for xpd
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#error DFU_PID not defined!
|
||||
#endif
|
||||
|
||||
#ifndef DFU_BCD_DEVICE
|
||||
#ifndef DFU_BCD_DEVICE
|
||||
#error DFU_BCD_DEVICE not defined!
|
||||
#endif
|
||||
|
||||
@@ -36,12 +36,12 @@ unsigned char DFUdevDesc[] = {
|
||||
0x00, /* 5 bDeviceSubClass: See interface */
|
||||
0, /* 6 bDeviceProtocol: See interface */
|
||||
64, /* 7 bMaxPacketSize */
|
||||
(DFU_VENDOR_ID & 0xFF), /* 8 idVendor */
|
||||
(DFU_VENDOR_ID >> 8), /* 9 idVendor */
|
||||
(DFU_PID & 0xFF), /* 10 idProduct */
|
||||
(DFU_PID >> 8), /* 11 idProduct */
|
||||
(DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */
|
||||
(DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */
|
||||
(DFU_VENDOR_ID & 0xFF), /* 8 idVendor */
|
||||
(DFU_VENDOR_ID >> 8), /* 9 idVendor */
|
||||
(DFU_PID & 0xFF), /* 10 idProduct */
|
||||
(DFU_PID >> 8), /* 11 idProduct */
|
||||
(DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */
|
||||
(DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */
|
||||
DFU_MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */
|
||||
DFU_PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */
|
||||
DFU_SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */
|
||||
@@ -49,7 +49,7 @@ unsigned char DFUdevDesc[] = {
|
||||
};
|
||||
|
||||
unsigned char DFUcfgDesc[] = {
|
||||
/* Standard USB device descriptor */
|
||||
/* Standard USB device descriptor */
|
||||
0x09, /* 0 bLength */
|
||||
USB_CONFIGURATION, /* 1 bDescriptorType */
|
||||
0x1b, /* 2 wTotalLength */
|
||||
|
||||
@@ -22,28 +22,28 @@ extern int DFU_reset_override;
|
||||
extern void DFUCustomFlashEnable();
|
||||
extern void DFUCustomFlashDisable();
|
||||
|
||||
void temp()
|
||||
void temp()
|
||||
{
|
||||
asm(".linkset DFU_reset_override, _edp.bss");
|
||||
asm(".globl DFU_reset_override");
|
||||
}
|
||||
|
||||
static int DFU_OpenFlash(chanend ?c_user_cmd)
|
||||
static int DFU_OpenFlash(chanend ?c_user_cmd)
|
||||
{
|
||||
if (!DFU_flash_connected)
|
||||
if (!DFU_flash_connected)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
DFUCustomFlashEnable();
|
||||
flash_cmd_init();
|
||||
DFU_flash_connected = 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
{
|
||||
if (DFU_flash_connected)
|
||||
if (DFU_flash_connected)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
DFUCustomFlashDisable();
|
||||
@@ -53,9 +53,9 @@ static int DFU_CloseFlash(chanend ?c_user_cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
{
|
||||
if (DFU_state == STATE_APP_IDLE)
|
||||
if (DFU_state == STATE_APP_IDLE)
|
||||
{
|
||||
|
||||
DFU_state = STATE_APP_DETACH;
|
||||
@@ -64,15 +64,15 @@ static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
|
||||
|
||||
// Setup DFU timeout value
|
||||
DFUResetTimeout = timeout * 100000;
|
||||
|
||||
|
||||
// Start DFU reset timer
|
||||
DFUTimer :> DFUTimerStart;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
@@ -86,7 +86,7 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
|
||||
DFU_OpenFlash(c_user_cmd);
|
||||
|
||||
switch (DFU_state)
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_IDLE:
|
||||
case STATE_DFU_DOWNLOAD_IDLE:
|
||||
@@ -96,29 +96,29 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
return 0;
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
{
|
||||
fromDfuIdle = 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
fromDfuIdle = 0;
|
||||
}
|
||||
|
||||
if (request_len == 0)
|
||||
if (request_len == 0)
|
||||
{
|
||||
// Host signalling complete download
|
||||
int i = 0;
|
||||
unsigned int cmd_data[16];
|
||||
if (subPagesLeft)
|
||||
if (subPagesLeft)
|
||||
{
|
||||
unsigned int subPagePad[16] = {0};
|
||||
for (i = 0; i < subPagesLeft; i++)
|
||||
for (i = 0; i < subPagesLeft; i++)
|
||||
{
|
||||
flash_cmd_write_page_data((subPagePad, unsigned char[64]));
|
||||
}
|
||||
@@ -128,16 +128,16 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
flash_cmd_write_page((cmd_data, unsigned char[]));
|
||||
|
||||
DFU_state = STATE_DFU_MANIFEST_SYNC;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int flash_cmd = 0;
|
||||
unsigned int flash_page_index = 0;
|
||||
unsigned int cmd_data[16];
|
||||
|
||||
if (fromDfuIdle)
|
||||
{
|
||||
|
||||
if (fromDfuIdle)
|
||||
{
|
||||
unsigned s = 0;
|
||||
|
||||
// Erase flash on first block
|
||||
@@ -145,14 +145,14 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
}
|
||||
|
||||
// Program firmware, STATE_DFU_DOWNLOAD_BUSY not currently used
|
||||
if (!(block_num % 4))
|
||||
if (!(block_num % 4))
|
||||
{
|
||||
cmd_data[0] = !fromDfuIdle; // 0 for first page, 1 for other pages.
|
||||
flash_cmd_write_page((cmd_data, unsigned char[64]));
|
||||
subPagesLeft = 4;
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
cmd_data[i] = request_data[i];
|
||||
}
|
||||
@@ -163,11 +163,11 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
DFU_state = STATE_DFU_DOWNLOAD_SYNC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
unsigned int firstRead = 0;
|
||||
@@ -176,8 +176,8 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
// Keep reading flash pages until read_page returns 1 (address out of range)
|
||||
// Return terminating upload packet at this point
|
||||
DFU_OpenFlash(c_user_cmd);
|
||||
|
||||
switch (DFU_state)
|
||||
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_IDLE:
|
||||
case STATE_DFU_UPLOAD_IDLE:
|
||||
@@ -187,18 +187,18 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0))
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
return 0;
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
}
|
||||
else if (DFU_state == STATE_DFU_IDLE)
|
||||
{
|
||||
firstRead = 1;
|
||||
subPagesLeft = 0;
|
||||
}
|
||||
|
||||
if (!subPagesLeft)
|
||||
if (!subPagesLeft)
|
||||
{
|
||||
cmd_data[0] = !firstRead;
|
||||
|
||||
@@ -207,14 +207,14 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
subPagesLeft = 4;
|
||||
|
||||
// If address out of range, terminate!
|
||||
if (cmd_data[0] == 1)
|
||||
if (cmd_data[0] == 1)
|
||||
{
|
||||
subPagesLeft = 0;
|
||||
// Back to idle state, upload complete
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read page data
|
||||
flash_cmd_write_page_data((request_data, unsigned char[64]));
|
||||
@@ -223,16 +223,16 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
|
||||
|
||||
DFU_state = STATE_DFU_UPLOAD_IDLE;
|
||||
|
||||
return 64;
|
||||
return 64;
|
||||
}
|
||||
|
||||
static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int timeout = 0;
|
||||
|
||||
request_data[0] = timeout << 8 | (unsigned char)DFU_status;
|
||||
|
||||
switch (DFU_state)
|
||||
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_MANIFEST:
|
||||
case STATE_DFU_MANIFEST_WAIT_RESET:
|
||||
@@ -255,28 +255,28 @@ static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16]
|
||||
|
||||
request_data[1] = DFU_state;
|
||||
|
||||
return 6;
|
||||
return 6;
|
||||
}
|
||||
|
||||
static int DFU_ClrStatus(void)
|
||||
static int DFU_ClrStatus(void)
|
||||
{
|
||||
if (DFU_state == STATE_DFU_ERROR)
|
||||
if (DFU_state == STATE_DFU_ERROR)
|
||||
{
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd)
|
||||
{
|
||||
|
||||
request_data[0] = DFU_state;
|
||||
|
||||
switch (DFU_state)
|
||||
switch (DFU_state)
|
||||
{
|
||||
case STATE_DFU_DOWNLOAD_BUSY:
|
||||
case STATE_DFU_MANIFEST:
|
||||
@@ -287,22 +287,22 @@ static int DFU_GetState(unsigned int request_len, unsigned int request_data[16],
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int DFU_Abort(void)
|
||||
static int DFU_Abort(void)
|
||||
{
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Tell the DFU state machine that a USB reset has occured
|
||||
int DFUReportResetState(chanend ?c_user_cmd)
|
||||
int DFUReportResetState(chanend ?c_user_cmd)
|
||||
{
|
||||
unsigned int inDFU = 0;
|
||||
unsigned int currentTime = 0;
|
||||
|
||||
if (DFU_reset_override == 0x11042011)
|
||||
if (DFU_reset_override == 0x11042011)
|
||||
{
|
||||
unsigned int cmd_data[16];
|
||||
inDFU = 1;
|
||||
@@ -310,19 +310,19 @@ int DFUReportResetState(chanend ?c_user_cmd)
|
||||
return inDFU;
|
||||
}
|
||||
|
||||
switch(DFU_state)
|
||||
switch(DFU_state)
|
||||
{
|
||||
case STATE_APP_DETACH:
|
||||
case STATE_DFU_IDLE:
|
||||
DFU_state = STATE_DFU_IDLE;
|
||||
|
||||
DFUTimer :> currentTime;
|
||||
if (currentTime - DFUTimerStart > DFUResetTimeout)
|
||||
if (currentTime - DFUTimerStart > DFUResetTimeout)
|
||||
{
|
||||
DFU_state = STATE_APP_IDLE;
|
||||
inDFU = 0;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
inDFU = 1;
|
||||
}
|
||||
@@ -339,13 +339,13 @@ int DFUReportResetState(chanend ?c_user_cmd)
|
||||
inDFU = 0;
|
||||
DFU_state = STATE_APP_IDLE;
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
DFU_state = STATE_DFU_ERROR;
|
||||
inDFU = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!inDFU)
|
||||
if (!inDFU)
|
||||
{
|
||||
DFU_CloseFlash(c_user_cmd);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ static int XMOS_DFU_RevertFactory(chanend ?c_user_cmd)
|
||||
|
||||
DFUTimer :> s;
|
||||
DFUTimer when timerafter(s + 25000000) :> s; // Wait for flash erase
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd)
|
||||
|
||||
|
||||
static int XMOS_DFU_SaveState()
|
||||
{
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -391,16 +391,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
unsigned int data_buffer_len = 0;
|
||||
unsigned int data_buffer[17];
|
||||
unsigned int reset_device_after_ack = 0;
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
// Host to device
|
||||
if (sp.wLength)
|
||||
if (sp.wLength)
|
||||
data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[]));
|
||||
}
|
||||
|
||||
// Map Standard DFU commands onto device level firmware upgrade mechanism
|
||||
switch (sp.bRequest)
|
||||
switch (sp.bRequest)
|
||||
{
|
||||
case DFU_DETACH:
|
||||
return_data_len = DFU_Detach(sp.wValue, c_user_cmd);
|
||||
@@ -456,16 +456,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
break;
|
||||
}
|
||||
|
||||
if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0)
|
||||
{
|
||||
if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0)
|
||||
{
|
||||
// Device to host
|
||||
#ifdef ARCH_G
|
||||
XUD_DoGetRequest(ep0_out, 0, (data_buffer, unsigned char[]), return_data_len, return_data_len);
|
||||
#else
|
||||
XUD_DoGetRequest(ep0_out, ep0_in, (data_buffer, unsigned char[]), return_data_len, return_data_len);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ARCH_G
|
||||
XUD_DoSetRequestStatus(ep0_out);
|
||||
@@ -475,11 +475,11 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch
|
||||
}
|
||||
|
||||
// If device reset requested, handle after command acknowledgement
|
||||
if (reset_device_after_ack)
|
||||
if (reset_device_after_ack)
|
||||
{
|
||||
if (user_reset)
|
||||
if (user_reset)
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <xclib.h>
|
||||
|
||||
#ifndef FLASH_MAX_UPGRADE_SIZE
|
||||
#ifndef FLASH_MAX_UPGRADE_SIZE
|
||||
#define FLASH_MAX_UPGRADE_SIZE 128 * 1024 // 128K default
|
||||
#endif
|
||||
|
||||
@@ -40,11 +40,11 @@ void DFUCustomFlashDisable()
|
||||
return;
|
||||
}
|
||||
|
||||
int flash_cmd_init(void)
|
||||
int flash_cmd_init(void)
|
||||
{
|
||||
fl_BootImageInfo image;
|
||||
|
||||
if (!flash_device_open)
|
||||
if (!flash_device_open)
|
||||
{
|
||||
if (flash_cmd_enable_ports())
|
||||
flash_device_open = 1;
|
||||
@@ -56,14 +56,14 @@ int flash_cmd_init(void)
|
||||
// Disable flash protection
|
||||
fl_setProtection(0);
|
||||
|
||||
if (fl_getFactoryImage(&image) != 0)
|
||||
if (fl_getFactoryImage(&image) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
factory_image = image;
|
||||
|
||||
if (fl_getNextBootImage(&image) == 0)
|
||||
if (fl_getNextBootImage(&image) == 0)
|
||||
{
|
||||
upgrade_image_valid = 1;
|
||||
upgrade_image = image;
|
||||
@@ -72,43 +72,43 @@ int flash_cmd_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flash_cmd_deinit(void)
|
||||
int flash_cmd_deinit(void)
|
||||
{
|
||||
if (!flash_device_open)
|
||||
return 0;
|
||||
|
||||
|
||||
flash_cmd_disable_ports();
|
||||
flash_device_open = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flash_cmd_read_page(unsigned char *data)
|
||||
int flash_cmd_read_page(unsigned char *data)
|
||||
{
|
||||
if (!upgrade_image_valid)
|
||||
if (!upgrade_image_valid)
|
||||
{
|
||||
*(unsigned int *)data = 1;
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (*(unsigned int *)data == 0)
|
||||
|
||||
if (*(unsigned int *)data == 0)
|
||||
{
|
||||
fl_startImageRead(&upgrade_image);
|
||||
}
|
||||
|
||||
|
||||
current_flash_subpage_index = 0;
|
||||
|
||||
if (fl_readImageRead(current_flash_page_data) == 0)
|
||||
|
||||
if (fl_readImageRead(current_flash_page_data) == 0)
|
||||
{
|
||||
*(unsigned int *)data = 0;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
*(unsigned int *)data = 1;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
int flash_cmd_read_page_data(unsigned char *data)
|
||||
int flash_cmd_read_page_data(unsigned char *data)
|
||||
{
|
||||
unsigned char *page_data_ptr = ¤t_flash_page_data[current_flash_subpage_index * 64];
|
||||
memcpy(data, page_data_ptr, 64);
|
||||
@@ -124,27 +124,27 @@ static void begin_write()
|
||||
// TODO this will take a long time. To minimise the amount of time spent
|
||||
// paused on this operation it would be preferable to move to this to a
|
||||
// seperate command, e.g. start_write.
|
||||
do
|
||||
do
|
||||
{
|
||||
result = fl_startImageAdd(&factory_image, FLASH_MAX_UPGRADE_SIZE, 0);
|
||||
} while (result > 0);
|
||||
|
||||
|
||||
if (result < 0)
|
||||
FLASH_ERROR();
|
||||
}
|
||||
|
||||
static int pages_written = 0;
|
||||
|
||||
int flash_cmd_write_page(unsigned char *data)
|
||||
int flash_cmd_write_page(unsigned char *data)
|
||||
{
|
||||
unsigned int flag = *(unsigned int *)data;
|
||||
|
||||
if (upgrade_image_valid)
|
||||
if (upgrade_image_valid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (flag)
|
||||
switch (flag)
|
||||
{
|
||||
case 0:
|
||||
// First page.
|
||||
@@ -158,7 +158,7 @@ int flash_cmd_write_page(unsigned char *data)
|
||||
// Termination.
|
||||
if (fl_endWriteImage() != 0)
|
||||
FLASH_ERROR();
|
||||
|
||||
|
||||
// Sanity check
|
||||
fl_BootImageInfo image = factory_image;
|
||||
if (fl_getNextBootImage(&image) != 0)
|
||||
@@ -173,7 +173,7 @@ int flash_cmd_write_page(unsigned char *data)
|
||||
static int isAllOnes(unsigned char page[256])
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if (page[i] != 0xff)
|
||||
return 0;
|
||||
@@ -181,16 +181,16 @@ static int isAllOnes(unsigned char page[256])
|
||||
return 1;
|
||||
}
|
||||
|
||||
int flash_cmd_write_page_data(unsigned char *data)
|
||||
int flash_cmd_write_page_data(unsigned char *data)
|
||||
{
|
||||
unsigned char *page_data_ptr = ¤t_flash_page_data[current_flash_subpage_index * 64];
|
||||
|
||||
if (upgrade_image_valid)
|
||||
if (upgrade_image_valid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (current_flash_subpage_index >= 4)
|
||||
if (current_flash_subpage_index >= 4)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -199,11 +199,11 @@ int flash_cmd_write_page_data(unsigned char *data)
|
||||
|
||||
current_flash_subpage_index++;
|
||||
|
||||
if (current_flash_subpage_index == 4)
|
||||
if (current_flash_subpage_index == 4)
|
||||
{
|
||||
if (isAllOnes(data))
|
||||
FLASH_ERROR();
|
||||
if (fl_writeImagePage(current_flash_page_data) != 0)
|
||||
if (fl_writeImagePage(current_flash_page_data) != 0)
|
||||
FLASH_ERROR();
|
||||
pages_written++;
|
||||
}
|
||||
@@ -211,22 +211,22 @@ int flash_cmd_write_page_data(unsigned char *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flash_cmd_erase_all(void)
|
||||
int flash_cmd_erase_all(void)
|
||||
{
|
||||
fl_BootImageInfo tmp_image = upgrade_image;
|
||||
|
||||
if (upgrade_image_valid)
|
||||
if (upgrade_image_valid)
|
||||
{
|
||||
if (fl_deleteImage(&upgrade_image) != 0)
|
||||
{
|
||||
FLASH_ERROR();
|
||||
}
|
||||
|
||||
|
||||
// Keep deleting all upgrade images
|
||||
// TODO Perhaps using replace would be nicer...
|
||||
// TODO Perhaps using replace would be nicer...
|
||||
while(1)
|
||||
{
|
||||
if (fl_getNextBootImage(&tmp_image) == 0)
|
||||
if (fl_getNextBootImage(&tmp_image) == 0)
|
||||
{
|
||||
if (fl_deleteImage(&tmp_image) != 0)
|
||||
{
|
||||
@@ -238,7 +238,7 @@ int flash_cmd_erase_all(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
upgrade_image_valid = 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user