cancel
Showing results for 
Search instead for 
Did you mean: 

File Transfer Issue and Rollback mechanism in Bootloader Development

Kai_Satone
Associate III

I am working on the development of a Bootloader for one of our projects. We are encountering an issue with the file transfer process, and I am reaching out to seek your guidance.

Our setup involves receiving a .bin firmware file from a server, which is stored in an EC200U module (responsible for the server connection). The file is then transferred in 5KB chunks from the EC200U to the buffer, and subsequently, attempt to transfer it in similar chunks to a designated slot address on an STM32F411 microcontroller.

The problem arises during the final stage when try to copy the data from the EC200U to the STM32F411 slot address. When we copy the data in chunks the data is getting alter or corrupted. Also need guidance on rollback mechanism on how can we implement .would be grateful for any guidance or recommendations you could provide.

Thank you in advance for your time and assistance. 

 

while (position < FILE_SIZE) {
            	memset(readBuffer,0,sizeof(readBuffer));
            	uint32_t bytesToRead = (FILE_SIZE - position) < CHUNK_SIZE ? (FILE_SIZE - position) : CHUNK_SIZE;
                // Step 3: Seek to the current position
            	snprintf(command, sizeof(command), "AT+QFSEEK=%d,%d,0", fileHandle, position);
                sendATCommand(command, response, 1000);   			snprintf(command, sizeof(command), "AT+QFREAD=%d,%d",fileHandle,bytesToRead);
                            sendATCommand(command, response, 1000);

                            // Calculate the total size of the response
//                            uint32_t totalSizeOfResponse = strlen(response); // Get the length of the full response
                            // Remove the unwanted header from the response before processing the actual data
//                            char *actualData = strstr(response, "\r\nCONNECT 4096\r\n");  // Look for the header end

//                            if (actualData != NULL) {
//                                actualData += strlen("\r\nCONNECT 4096\r\n");  // Skip the header part

                            char *header = strstr(response, "\r\nCONNECT ");
                            if (header != NULL) {
                                header += strlen("\r\nCONNECT ");  // Skip the static part of the header

                                // Extract the numeric value after "CONNECT " (e.g., 256, 4096, etc.)
                                int size;
                                sscanf(header, "%d", &size);  // Extract the numeric value into size
                                // Skip past the number and the trailing "\r\n"
                                char *actualData = strstr(header, "\r\n");
                                if (actualData != NULL) {
                                    actualData += strlen("\r\n");  // Now actualData points to the actual data, past the header
                               }
                            }
          // Copy the 5KB chunk (or less if it's the last chunk) into the main buffer
                            memcpy(&fileBuffer[position], strlen(actualData), bytesToRead);
                           // Process the read data (response will contain the data read)
                            printf("Read %d bytes of data\n", bytesToRead);

                            // Write the chunk to external flash memory
                            Flash_Write(addr, &fileBuffer[position], bytesToRead);  // Write to external memory
                           // Read back from flash for verification
                            Flash_Read(addr, readBuffer, bytesToRead);
//                            } else {
//                                printf("Error: Header not found in the response\n");
//                            }

                            // Compare the written data with the read data
                            if (memcmp(readBuffer, &fileBuffer[position], bytesToRead) == 0)
                            	{
                            	printf("Data verification successful.\n");
                            	HAL_UART_Transmit(&huart1, (uint8_t *)"Data verification successful\r\n", sizeof("Data verification successful\r\n"), 100);
                            	}
                            else
                            	{
                            	printf("Data verification failed!\n");
                            	HAL_UART_Transmit(&huart1, (uint8_t *)"Data verification failed!\r\n", sizeof("Data verification failed!\r\n"), 100);
                            	}
                           // Move to the next chunk
                            addr += 0x1000;

                            // Step 5: Move to the next chunknote
                            position += bytesToRead;
                            totalBytesRead += bytesToRead;

                        }

 

0 REPLIES 0