Go to the source code of this file.
Functions | |
| void | firm_upgrade_run (void) |
| This function runs the upgrade process. | |
Definition in file firm_upgrade.h.
| void firm_upgrade_run | ( | void | ) |
This function runs the upgrade process.
//! The status of process is display on UART and writed in a status file on U-Disk. //!
Definition at line 111 of file firm_upgrade.c.
References St_hex_line::datas, file_close(), file_eof(), file_open(), file_seek(), firm_upgrade_displayzone(), firm_upgrade_readhexline(), firm_upgrade_searchfile(), firm_upgrade_status(), flash_lib_check(), flash_rd_byte(), flash_wr_block(), FOPEN_MODE_R, FS_SEEK_SET, MAX_DATA_LINE, nav_file_getname(), nav_getindex(), nav_gotoindex(), St_hex_line::u16_add, St_hex_line::u8_nb_data, St_hex_line::u8_type, UPGRADE_ADDR, and UPGRADE_SIZE_MAX.
00112 { 00113 Fs_index sav_index; 00114 U8 u8_i, save_int; 00115 St_hex_line hex_line; 00116 U8 datas[MAX_DATA_LINE]; 00117 char filename[30]; 00118 00119 hex_line.datas = datas; // Init data buffer used 00120 hex_line.u8_type = 0; // Autotrize only type 0 00121 00122 // Save current position to resolve it before exit routine 00123 sav_index = nav_getindex(); 00124 00125 printf("\n\rDislpay upgrade zone BEFORE upgrade:\n\r"); 00126 firm_upgrade_displayzone(); 00127 00128 printf("Search upgrade file\n\r...\r"); 00129 if( !firm_upgrade_searchfile( "upgrade*" ) ) 00130 { 00131 firm_upgrade_status("No upgrade file"); 00132 nav_gotoindex(&sav_index); 00133 return; 00134 } 00135 00136 nav_file_getname( filename, 50 ); 00137 printf("Open upgrade file \"%s\"\n\r...\r", filename ); 00138 if( !file_open(FOPEN_MODE_R) ) 00139 { 00140 firm_upgrade_status("!! Error to open upgrade file"); 00141 nav_gotoindex(&sav_index); // Restore previous position 00142 return; 00143 } 00144 00145 printf("Check upgrade file\n\r...\r"); 00146 while (!file_eof()) 00147 { 00148 // For each text line, check upgrade zone 00149 hex_line.u8_nb_data = MAX_DATA_LINE; 00150 if( !firm_upgrade_readhexline( &hex_line ) ) 00151 { 00152 file_close(); 00153 firm_upgrade_status("!! Error in HEX file format"); 00154 nav_gotoindex(&sav_index); 00155 return; 00156 } 00157 00158 if( (hex_line.u16_add < UPGRADE_ADDR) 00159 || (hex_line.u16_add+hex_line.u8_nb_data) > (UPGRADE_ADDR+UPGRADE_SIZE_MAX) ) 00160 { 00161 file_close(); 00162 firm_upgrade_status("!! Upgrade zone not autorized"); 00163 nav_gotoindex(&sav_index); 00164 return; 00165 } 00166 } 00167 00168 printf("Program FLASH\n\r...\r"); 00169 // Check bootloader 00170 if( !flash_lib_check() ) 00171 { 00172 file_close(); 00173 firm_upgrade_status("!! The bootloder if not loaded"); 00174 nav_gotoindex(&sav_index); 00175 return; 00176 } 00177 00178 file_seek(0,FS_SEEK_SET); // Restart at beginning of file 00179 while (!file_eof()) 00180 { 00181 // For each text line, check upgrade zone 00182 hex_line.u8_nb_data = MAX_DATA_LINE; 00183 if( !firm_upgrade_readhexline( &hex_line ) ) 00184 { 00185 file_close(); 00186 firm_upgrade_status("!! Error in HEX file format"); 00187 nav_gotoindex(&sav_index); 00188 return; 00189 } 00190 00191 // Disabling the interrupt 00192 save_int=Get_interrupt_state(); 00193 Disable_interrupt(); 00194 // Writing the flash with a check of highest flash address 00195 flash_wr_block( hex_line.datas, hex_line.u16_add, hex_line.u8_nb_data ); 00196 // Read data in flash and check programmation with buffer 00197 for( u8_i=0; u8_i<hex_line.u8_nb_data; u8_i++ ) 00198 { 00199 if( hex_line.datas[u8_i] != flash_rd_byte((U8 farcode*)hex_line.u16_add) ) 00200 { 00201 file_close(); 00202 firm_upgrade_status("!! Programmation in flash BAD\n\r!!! Check if the bootloader is loaded in chip."); 00203 nav_gotoindex(&sav_index); 00204 return; 00205 } 00206 hex_line.u16_add++; 00207 } 00208 // Restore interrupt state 00209 if(save_int) { Enable_interrupt(); } 00210 } 00211 00212 file_close(); 00213 firm_upgrade_status("Upgrade successfull"); 00214 nav_gotoindex(&sav_index); 00215 00216 printf("Dislpay upgrade zone AFTER upgrade:\n\r"); 00217 firm_upgrade_displayzone(); 00218 }
1.5.3