Hi all,
I converted my elf file to a bin file and put it in an FTP server. I'm trying to download this file to swap file 1 under MQX 4.1 the next way:
/************************************************************************************/
void FirmwareUpdateTask(uint32_t PrivateData) {
void *FTPHandle;
int32_t Response;
_ip_address ServerAddress;
MQX_FILE_PTR SwapFile;
uint32_t IOCTLParam;
char Buffer[10];
// set server address
printf("This is firmwareUpdateTask speaking\n");
memset(&ServerAddress, 0, sizeof(ServerAddress));
ServerAddress = IPADDR(192, 168, 1, 25);
//Open Swap file
SwapFile = fopen("flashx:swap1", NULL);
if(SwapFile == NULL) {
printf("KO\n");
_task_block();
}
else {
printf("OK\n");
}
/* Enable sector cache */
ioctl(SwapFile, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);
printf("\nFlash sector cache enabled\n");
/* Unprotecting the the FLASH might be required */
IOCTLParam = 0;
ioctl(SwapFile, FLASH_IOCTL_WRITE_PROTECT, &IOCTLParam);
fseek(SwapFile, 0, IO_SEEK_SET);
//open ftp session
Response = FTP_open(&FTPHandle, ServerAddress, stdout);
if (Response == -1) {
printf("Couldn't open FTP session\n");
return;
} /* Endif */
printf("FTP session opened\n");
Response = FTP_command(FTPHandle, "USER user\r\n", stdout);
/* Response 3xx means Password Required */
if ((Response >= 300) && (Response < 400)) {
printf("sending password\n");
Response = FTP_command(FTPHandle, "PASS pass\r\n", stdout);
} /* Endif */
/* Response 2xx means Logged In */
if ((Response >= 200) && (Response < 300)) {
printf("Logged in\n");
Response = FTP_command(FTPHandle, "CWD /ogarcia\r\n", stdout);
printf("Response1 = %ld\n", Response);
Response = FTP_command(FTPHandle, "TYPE I\r\n", stdout);
printf("Response2 = %ld\n", Response);
Response = FTP_command_data(FTPHandle, "RETR CptWifiNode.bin\r\n", stdout, SwapFile, FTPMODE_PORT | FTPDIR_RECV);
} /* Endif */
else {
printf("Not logged in\n");
}
FTP_close(FTPHandle, stdout);
fclose(SwapFile);
printf("Rebooting... \n");
ioctl(SwapFile, FLASH_IOCTL_SWAP_FLASH_AND_RESET, NULL);
/*******************************************************************/
After reset my application has not been updated, and the old firmware runs again.
If I make
Response = FTP_command_data(FTPHandle, "RETR CptWifiNode.bin\r\n", stdout, stdout, FTPMODE_PORT | FTPDIR_RECV);
I can see the content of the file I'm downloading printed over the uart.
My binary file is 520416 bytes long and the swap block is 524288 bytes lonk (512 kB) Is this ok?
What I'm doing wrong with the swap?
Thanks in advance.
Óscar.