From: Xiangfu Liu <[email protected]>
Signed-off-by: Xiangfu Liu <[email protected]> --- urjtag/include/urjtag/flash.h | 3 +++ urjtag/src/cmd/cmd_lockflash.c | 30 +++++++++++++++++++++++++++++- urjtag/src/flash/flash.c | 34 ++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/urjtag/include/urjtag/flash.h b/urjtag/include/urjtag/flash.h index e0b751e..0f492db 100644 --- a/urjtag/include/urjtag/flash.h +++ b/urjtag/include/urjtag/flash.h @@ -79,4 +79,7 @@ int urj_flashmsbin (urj_bus_t *bus, FILE *f, int); /** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ int urj_flasherase (urj_bus_t *bus, uint32_t addr, uint32_t number); +/** @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error */ +int urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number, int unlock); + #endif /* URJ_FLASH_H */ diff --git a/urjtag/src/cmd/cmd_lockflash.c b/urjtag/src/cmd/cmd_lockflash.c index 829bd2f..cbbf65c 100644 --- a/urjtag/src/cmd/cmd_lockflash.c +++ b/urjtag/src/cmd/cmd_lockflash.c @@ -39,6 +39,7 @@ cmd_lockflash_run (urj_chain_t *chain, char *params[]) { long unsigned adr = 0; long unsigned number = 0; + int unlock = 0; if (urj_cmd_params (params) != 3) { @@ -60,7 +61,10 @@ cmd_lockflash_run (urj_chain_t *chain, char *params[]) if (urj_cmd_get_number (params[2], &number) != URJ_STATUS_OK) return URJ_STATUS_FAIL; - return urj_flashlock (urj_bus, adr, number); + if (!strcmp(params[0], "unlockflash")) + unlock = 1; + + return urj_flashlock (urj_bus, adr, number, unlock); } static void @@ -86,3 +90,27 @@ const urj_cmd_t urj_cmd_lockflash = { cmd_lockflash_help, cmd_lockflash_run }; + +static void +cmd_unlockflash_help (void) +{ + urj_log (URJ_LOG_LEVEL_NORMAL, + _("Usage: %s ADDR BLOCKS\n" + "Unlock flash memory from ADDR.\n" + "\n" + "ADDR target addres for erasing block\n" + "BLOCKS number of blocks to lock\n" + "\n" + "ADDR and BLOCKS could be in decimal or hexadecimal (prefixed with 0x) form.\n" + "\n" "Supported Flash Memories:\n"), + "lockflash"); + + urj_cmd_show_list (urj_flash_flash_drivers); +} + +const urj_cmd_t urj_cmd_unlockflash = { + "unlockflash", + N_("unlock flash memory by number of blocks"), + cmd_unlockflash_help, + cmd_lockflash_run +}; diff --git a/urjtag/src/flash/flash.c b/urjtag/src/flash/flash.c index 9c6089b..010b4c3 100644 --- a/urjtag/src/flash/flash.c +++ b/urjtag/src/flash/flash.c @@ -555,7 +555,7 @@ urj_flasherase (urj_bus_t *bus, uint32_t addr, uint32_t number) } int -urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number) +urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number, int unlock) { urj_flash_cfi_query_structure_t *cfi; uint32_t i; @@ -575,7 +575,9 @@ urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number) chip_width = urj_flash_cfi_array->cfi_chips[0]->width; urj_log (URJ_LOG_LEVEL_NORMAL, - _("\nLocking %d Flash block%s from address 0x%lx\n"), number, + _("\n%s %d Flash block%s from address 0x%lx\n"), + unlock == 1 ? "Unlocking" : "Locking", + number, number > 1 ? "s" : "", (long unsigned) addr); for (i = 1; i <= number; i++) @@ -587,23 +589,33 @@ urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number) if (block_no < 0) { - urj_error_set (URJ_ERROR_FLASH_LOCK, "Cannot find block"); + urj_error_set ((unlock == 1 + ? URJ_ERROR_FLASH_UNLOCK : URJ_ERROR_FLASH_LOCK), + "Cannot find block"); status = URJ_STATUS_FAIL; break; } urj_log (URJ_LOG_LEVEL_NORMAL, - _("(%d%% Completed) FLASH Block %d : locking ... "), - i * 100 / number, block_no); - r = flash_driver->lock_block (urj_flash_cfi_array, addr); + _("(%d%% Completed) FLASH Block %d : %s ... "), + i * 100 / number, block_no, + unlock == 1 ? "unlocking" : "locking"); + + if (unlock) + r = flash_driver->unlock_block (urj_flash_cfi_array, addr); + else + r = flash_driver->lock_block (urj_flash_cfi_array, addr); + if (r == URJ_STATUS_OK) { if (i == number) { urj_log (URJ_LOG_LEVEL_NORMAL, "\r"); urj_log (URJ_LOG_LEVEL_NORMAL, - _("(100%% Completed) FLASH Block %d : locking ... Ok.\n"), - block_no); + _("(100%% Completed) FLASH Block %d : %s ... Ok.\n"), + block_no, + unlock == 1 ? "unlocking" : "locking"); + } else { @@ -622,9 +634,11 @@ urj_flashlock (urj_bus_t *bus, uint32_t addr, uint32_t number) } if (status == URJ_STATUS_OK) - urj_log (URJ_LOG_LEVEL_NORMAL, _("\nLocking Completed.\n")); + urj_log (URJ_LOG_LEVEL_NORMAL, _("\n%s Completed.\n"), + unlock == 1 ? "Unlocking" : "Locking"); else - urj_log (URJ_LOG_LEVEL_NORMAL, _("\nLocking (partially) Failed.\n")); + urj_log (URJ_LOG_LEVEL_NORMAL, _("\n%s (partially) Failed.\n"), + unlock == 1 ? "Unlocking" : "Locking"); return status; } -- 1.7.4.1 ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ UrJTAG-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/urjtag-development
