From db788e19231e14d20537abd6acda539b6a361d13 Mon Sep 17 00:00:00 2001 From: Bruno Vetel Date: Tue, 6 Jan 2009 14:46:13 +0100 Subject: [PATCH] reduce size --- dataflash.cpp | 91 ++++++++++++++++++++++++++++------------------------------- dataflash.h | 7 +++-- main.cpp | 46 +++++++++++++++--------------- 3 files changed, 71 insertions(+), 73 deletions(-) diff --git a/dataflash.cpp b/dataflash.cpp index c785f5a..1d9f6f7 100644 --- a/dataflash.cpp +++ b/dataflash.cpp @@ -46,6 +46,7 @@ int AT91F_DataflashInit (void) dfcode = AT91F_DataflashProbe(cs[i][1], &dataflash_info[i].Desc); switch (dfcode) { +#if 0 case AT45DB161: printf("\n\rflash nb %d found",i); dataflash_info[i].Device.pages_number = 4096; @@ -69,6 +70,7 @@ int AT91F_DataflashInit (void) dataflash_info[i].logical_address = cs[i][0]; dataflash_info[i].id = dfcode; break; +#endif case AT45DB642: printf("\n\rflash nb %d found",i); @@ -388,13 +390,13 @@ void read_lock_reg(t_read_lock_cmd *ptrcmd) AT91F_SpiWrite(&desc); printf("\n\r"); if ( ptrcmd == &read_lock_cmd_sector ) { - printf("read_lock_cmd_sector Lock status "); + printf("Lock status register"); } if ( ptrcmd == &read_lock_cmd_lockdown ) { - printf("read_lock_cmd_lockdown Lock status "); + printf("lockdown status register"); } if ( ptrcmd == &read_lock_cmd_security ) { - printf("read_lock_cmd_security Lock status "); + printf("security register "); } printf("size %d flash_nb %d \n\r",ptrcmd->rxsize,fl_nb); for ( i = 0 ; i < ptrcmd->rxsize ; i++ ) { @@ -414,27 +416,32 @@ unsigned char clear_lock_cmd[4]= 0x3D,0x2A,0x7F,0xCF }; -void clear_lock_reg() +int test_fl_info(int fl_nb) +{ + if (dataflash_info[fl_nb].id != 0) { + AT91F_SpiEnable(cs[fl_nb][1]); + + clear_desc(&desc); + return(1); + } + else { + return(0); + } +} + +void erase_lock_reg(int fl_nb) { int i; unsigned char rx[33]; - int fl_nb; - - memset(rx,0,sizeof(rx)); + if (test_fl_info(fl_nb)) { + memset(rx,0,sizeof(rx)); - for ( fl_nb = 0 ; fl_nb < CFG_MAX_DATAFLASH_BANKS ; fl_nb++) { - if (dataflash_info[fl_nb].id != 0) { - AT91F_SpiEnable(cs[fl_nb][1]); - - clear_desc(&desc); - desc.tx_cmd_pt = clear_lock_cmd; desc.rx_cmd_pt = rx; desc.tx_cmd_size = 4; desc.rx_cmd_size = 4; AT91F_SpiWrite(&desc); } - } } unsigned char lock_unlock_cmd[4]= @@ -457,7 +464,6 @@ void flash_en_lock_unlock(unsigned char *cmd) { unsigned char rxf[4]; unsigned char rx[33]; - clear_desc(&desc); desc.tx_cmd_pt = cmd; desc.rx_cmd_pt = rxf; @@ -467,50 +473,39 @@ void flash_en_lock_unlock(unsigned char *cmd) AT91F_SpiWrite(&desc); } -void flash_cmd_lock_unlock() +void program_lock_reg(int fl_nb) { unsigned char rxf[4]; unsigned char rx[33]; - memset(rx,0,sizeof(rx)); - - clear_desc(&desc); - desc.tx_cmd_pt = lock_unlock_cmd; - desc.rx_cmd_pt = rxf; - desc.tx_cmd_size = 4; - desc.rx_cmd_size = 4; - desc.tx_data_size = 32; - desc.rx_data_size = 32; - desc.tx_data_pt = rx; - desc.rx_data_pt = rx; - - AT91F_SpiWrite(&desc); + if (test_fl_info(fl_nb)) { + + memset(rx,0xff,sizeof(rx)); + desc.tx_cmd_pt = lock_unlock_cmd; + desc.rx_cmd_pt = rxf; + desc.tx_cmd_size = 4; + desc.rx_cmd_size = 4; + desc.tx_data_size = 32; + desc.rx_data_size = 32; + desc.tx_data_pt = rx; + desc.rx_data_pt = rx; + + AT91F_SpiWrite(&desc); + } } -void flash_lock_reg() +void flash_enable_lock(int fl_nb) { int i; - int fl_nb; - for ( fl_nb = 0 ; fl_nb < CFG_MAX_DATAFLASH_BANKS ; fl_nb++) { - if (dataflash_info[fl_nb].id != 0) { - AT91F_SpiEnable(cs[fl_nb][1]); - flash_en_lock_unlock(enable_lock_unlock_cmd); - flash_cmd_lock_unlock(); - - } + if (test_fl_info(fl_nb)) { + flash_en_lock_unlock(enable_lock_unlock_cmd); } } - -void flash_unlock_reg() +void flash_disable_lock(int fl_nb) { int i; - - int fl_nb; - for ( fl_nb = 0 ; fl_nb < CFG_MAX_DATAFLASH_BANKS ; fl_nb++) { - if (dataflash_info[fl_nb].id != 0) { - AT91F_SpiEnable(cs[fl_nb][1]); - flash_cmd_lock_unlock(); - flash_en_lock_unlock(disable_lock_unlock_cmd); - } + if (test_fl_info(fl_nb)) { + flash_en_lock_unlock(disable_lock_unlock_cmd); } } + diff --git a/dataflash.h b/dataflash.h index 0bc4655..c8dfb91 100644 --- a/dataflash.h +++ b/dataflash.h @@ -182,9 +182,10 @@ int get_size_reg(void); int erase_dataflash(int nb); // static void clear_desc( AT91S_DataflashDesc *d); void read_lock_reg(t_read_lock_cmd *ptrcmd); -void clear_lock_reg(void); -void flash_lock_reg(void); -void flash_unlock_reg(void); +void erase_lock_reg(int fl_nb); +void program_lock_reg(int fl_nb); +void flash_enable_lock(int fl_nb); +void flash_disable_lock(int fl_nb); void erase_chip(int); extern t_read_lock_cmd read_lock_cmd_sector; diff --git a/main.cpp b/main.cpp index aaa2c11..8320667 100644 --- a/main.cpp +++ b/main.cpp @@ -45,12 +45,14 @@ const char *menu_dataflash = { "2: Read Dataflash [addr]\n\r" "3: Erase chip [nb]\n\r" "4: Clear bootloader section in Dataflash\n\r" - "5: clear lock registers\n\r" - "6: Lock the flash\n\r" - "7: Unlock the flash\r\n" - "8: Read the sector lock register status of the flash\r\n" - "9: Read the lockdown lock register status of the flash\r\n" - "a: Read the security lock register status of the flash\r\n" + "5: start Uboot\n\r" + "6: Enable flash lock (flash_nb)\n\r" + "7: Disable flash lock (fl_nb)\r\n" + "8: Read lock status register (fl_nb)\r\n" + "9: Read lockdown status register (fl_nb)\r\n" + "a: Read security register (fl_nb)\r\n" + "b: Program lock register (fl_nb) all to ff \r\n" + "c: Erase lock register (fl_nb) all to 0 \r\n" }; //* Globales variables @@ -375,7 +377,6 @@ void AT91F_StartUboot(unsigned int dummy, void *pvoid) while(1); } -#if 0 void turn_led_off() { *AT91C_PIOD_ODR = AT91C_PIO_PD6; /* Manage PD6 io */ @@ -392,7 +393,6 @@ void turn_led_on() *AT91C_PIOD_CODR = AT91C_PIO_PD6; } -#endif void reset_flash_lock() { @@ -402,7 +402,6 @@ void reset_flash_lock() *AT91C_PIOB_CODR = AT91C_PIO_PC15; /* Clear PB 15 */ } -#if 0 #define ILIM0 0 #define ILIM1 100 #define ILIM2 200 @@ -437,8 +436,6 @@ void switch_led() } } -#endif - //*---------------------------------------------------------------------------- //* Function Name : main @@ -521,7 +518,12 @@ int main(void) AT91F_ReadLine("Enter: ", message); command = message[0]; - if(command == '1' || command == '2' || command == '3' || command == '5' ) + if(command == '1' || command == '2' || + command == '3' || + command == '6' || + command == '7' || + command == 'b' + ) if(AsciiToHex(&message[2], &DeviceAddress) == 0) command = 0; @@ -581,29 +583,23 @@ int main(void) command = 0; break; - case 5: - { - // flash_lock_sect(DeviceAddress); - command = 0; - break; - } case '5': { - clear_lock_reg(); + AT91F_StartUboot(0, (void *)0); command = 0; break; } case '6': { - flash_lock_reg(); + flash_enable_lock(DeviceAddress); command = 0; break; } case '7': { - flash_unlock_reg(); + flash_disable_lock(DeviceAddress); command = 0; break; } @@ -628,7 +624,13 @@ int main(void) } case 'b': { - clear_lock_reg(); + erase_lock_reg(DeviceAddress); + command = 0; + break; + } + case 'c': + { + program_lock_reg(DeviceAddress); command = 0; break; } -- 2.11.4.GIT