EFFS Load Application From Flash Card
Overview
This NetBurner application demonstrates how to update firmware from a binary image file stored on a flash card. The application uses the Extra File Descriptor (ExtraFD) mechanism to create a file stream interface that enables direct firmware programming from flash card storage.
Supported Platforms
- MOD5441X - On-board microSD card socket support
- Support for external flash card interfaces (commented options available)
Hardware Requirements
- NetBurner MOD5441X module
- MicroSD card with firmware binary file
- Serial console for monitoring update process
- Formatted flash card (FAT16/FAT32)
Application Functionality
Main Features
- Flash Card Mounting: Automatically detects and mounts microSD card
- Binary File Reading: Reads application binary from flash card storage
- ExtraFD Stream Interface: Creates file descriptor from flash file pointer
- Stream-Based Programming: Programs firmware using NetBurner's stream update mechanism
- Automatic Reboot: Restarts system after successful firmware update
Program Flow
- Initialization
- Initialize network stack and file system
- Enter EFFS file system context
- Mount on-board flash card (microSD)
- File System Operations
- Display directory contents
- Locate firmware file "AppToLoad.bin"
- Create Extra FD from file pointer
- Firmware Update Process
- Read binary file through ExtraFD interface
- Program new application to flash memory
- Verify programming success
- Reboot system to run new firmware
Update Process Flow
Flash Card ---> ExtraFD ---> Stream Interface ---> Flash Programming ---> Reboot
| | | | |
AppToLoad.bin File Stream Binary Reader Application New App
Update Running
Key Components
Files Structure
EffsLoadAppFromFlashCard/
|-- src/
| |-- main.cpp # Main application logic
| +-- FileSystemUtils.h # File system utility functions
|-- makefile # Build configuration
+-- README.md # This documentation
ExtraFD Implementation
Core ExtraFD Functions:**
Stream Update Process
Key Functions:**
File Preparation
Creating Update Files
- Build Target Application:
make PLATFORM=MOD5441X
# This creates *.s19 file in project directory
- Convert to Binary Format:
# Use NetBurner tools or standard utilities
objcopy -O binary target.elf AppToLoad.bin
- Copy to Flash Card:
- Name the file exactly "AppToLoad.bin"
- Place in root directory of flash card
- Ensure flash card is FAT16 or FAT32 formatted
File Requirements
- Filename: Must be exactly "AppToLoad.bin"
- Location: Root directory of flash card
- Format: Raw binary (not S-record or ELF)
- Size: Must fit in available flash memory
- Compatibility: Must be compiled for target platform
Building and Deployment
Build the updater application
Load updater to device
Required Libraries
This example requires EFFS FAT file system support:
Additional Files Required
Copy from \nburn\examples\_common\EFFS\FAT:
FileSystemUtils.h
FileSystemUtils.cpp
cardtype.h (if needed)
Usage Instructions
Step-by-Step Update Process
- Prepare Flash Card:
- Format microSD card (FAT32 recommended)
- Copy "AppToLoad.bin" to root directory
- Verify file is present and readable
- Load Updater:
- Build and load this updater application
- Insert prepared flash card into module
- Connect serial console for monitoring
- Execute Update:
- Application will display directory contents
- Press any key when prompted to start update
- Monitor progress messages
- Wait for automatic reboot (10 seconds)
Expected Console Output
Initializing the on-board Flash card...
Drive change successful
Directory listing:
AppToLoad.bin 524288
Type any key to program new application to flash
Opening file: "AppToLoad.bin"
Update complete, system will reboot in 10 seconds...
Error Handling
Common Error Conditions
- Drive Mount Failure:
drive change failed: [error code]
- Check flash card insertion
- Verify card formatting (FAT16/FAT32)
- Ensure card is not corrupted
- File Not Found:
Failed to find file: "AppToLoad.bin"
- Verify filename is exactly "AppToLoad.bin"
- Check file is in root directory
- Confirm file is not corrupted
- Stream Update Failure:
ERROR: Stream update failed, error code: [code]
- Binary file may be corrupted
- Insufficient flash memory space
- Binary not compatible with target platform
- ExtraFD Creation Failure:
- System resource exhaustion
- File system integrity issues
Debug Techniques
File System Verification:**
iprintf("Current directory: %s\n", GetCurrentDirectory());
iprintf("File size: %ld bytes\n", GetFileSize("AppToLoad.bin"));
Stream Progress Monitoring:**
int totalBytes = fdReadToEnd(fd);
iprintf("Total bytes processed: %d\n", totalBytes);
Advanced Features
Custom Update Sources
External Flash Card Support:**
int drv = OpenOnBoardFlash();
Network-Based Updates:**
int networkToExtraFdRead(int fd, char *buf, int nbytes) {
return networkRead(buf, nbytes);
}
Multi-File Updates
char *updateFiles[] = {"bootloader.bin", "application.bin", "config.bin"};
for(int i = 0; i < 3; i++) {
UpdateFromFile(updateFiles[i]);
}
Verification and Security
uint32_t CalculateChecksum(int fd) {
return checksum;
}
bool VerifyUpdate(const char *filename) {
return checksumValid;
}
Safety Considerations
Update Reliability
- Power Supply: Ensure stable power during update process
- Backup Strategy: Keep previous firmware version accessible
- Verification: Implement checksum validation before programming
- Recovery Mode: Consider implementing emergency recovery mechanism
Flash Memory Protection
uint32_t requiredSpace = GetFileSize("AppToLoad.bin");
uint32_t availableSpace = GetFlashSpaceAvailable();
if(requiredSpace > availableSpace) {
iprintf("ERROR: Insufficient flash memory\n");
return;
}
Update Validation
bool ValidateBinaryFormat(int fd) {
return isValid;
}
Performance Characteristics
Update Timing
- Read Speed: Limited by flash card interface (typically 1-10 MB/s)
- Programming Speed: Limited by internal flash programming rate
- Total Time: Depends on application size (typically seconds to minutes)
Memory Usage
- ExtraFD Overhead: Minimal system resource usage
- Buffer Size: Configurable read buffer size
- Flash Requirements: Must fit in available application flash space
Application Extensions
User Interface Enhancements
void DisplayUpdateProgress(int bytesProcessed, int totalBytes) {
int percent = (bytesProcessed * 100) / totalBytes;
iprintf("Update progress: %d%%\r", percent);
}
Remote Update Management
void HandleUpdateCommand(char *filename) {
StartUpdateProcess(filename);
}
Batch Updates
void BroadcastUpdate(char *filename) {
}
Related Examples
- EFFS Examples: File system operations and management
- Stream Examples: Alternative stream-based programming methods
- Network Update: Over-the-air firmware update mechanisms
- Bootloader Examples: Custom bootloader implementation
- Flash Programming: Direct flash memory programming techniques