You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(75) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(70) |
Feb
(20) |
Mar
(52) |
Apr
(149) |
May
(387) |
Jun
(466) |
Jul
(133) |
Aug
(87) |
Sep
(122) |
Oct
(140) |
Nov
(185) |
Dec
(105) |
2010 |
Jan
(85) |
Feb
(45) |
Mar
(75) |
Apr
(17) |
May
(41) |
Jun
(52) |
Jul
(33) |
Aug
(29) |
Sep
(36) |
Oct
(15) |
Nov
(26) |
Dec
(34) |
2011 |
Jan
(26) |
Feb
(25) |
Mar
(26) |
Apr
(29) |
May
(20) |
Jun
(27) |
Jul
(15) |
Aug
(32) |
Sep
(13) |
Oct
(64) |
Nov
(60) |
Dec
(10) |
2012 |
Jan
(64) |
Feb
(63) |
Mar
(39) |
Apr
(43) |
May
(54) |
Jun
(11) |
Jul
(30) |
Aug
(45) |
Sep
(11) |
Oct
(70) |
Nov
(24) |
Dec
(23) |
2013 |
Jan
(17) |
Feb
(8) |
Mar
(35) |
Apr
(40) |
May
(20) |
Jun
(24) |
Jul
(36) |
Aug
(25) |
Sep
(42) |
Oct
(40) |
Nov
(9) |
Dec
(21) |
2014 |
Jan
(29) |
Feb
(24) |
Mar
(60) |
Apr
(22) |
May
(22) |
Jun
(46) |
Jul
(11) |
Aug
(23) |
Sep
(26) |
Oct
(10) |
Nov
(14) |
Dec
(2) |
2015 |
Jan
(28) |
Feb
(47) |
Mar
(33) |
Apr
(58) |
May
(5) |
Jun
(1) |
Jul
|
Aug
(8) |
Sep
(12) |
Oct
(25) |
Nov
(58) |
Dec
(21) |
2016 |
Jan
(12) |
Feb
(40) |
Mar
(2) |
Apr
(1) |
May
(67) |
Jun
(2) |
Jul
(5) |
Aug
(36) |
Sep
|
Oct
(24) |
Nov
(17) |
Dec
(50) |
2017 |
Jan
(14) |
Feb
(16) |
Mar
(2) |
Apr
(35) |
May
(14) |
Jun
(16) |
Jul
(3) |
Aug
(3) |
Sep
|
Oct
(19) |
Nov
|
Dec
(16) |
2018 |
Jan
(55) |
Feb
(11) |
Mar
(34) |
Apr
(14) |
May
(4) |
Jun
(20) |
Jul
(39) |
Aug
(16) |
Sep
(17) |
Oct
(16) |
Nov
(20) |
Dec
(30) |
2019 |
Jan
(29) |
Feb
(24) |
Mar
(37) |
Apr
(26) |
May
(19) |
Jun
(21) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(12) |
Nov
(12) |
Dec
(12) |
2020 |
Jan
(47) |
Feb
(36) |
Mar
(54) |
Apr
(44) |
May
(37) |
Jun
(19) |
Jul
(32) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(32) |
Dec
(11) |
2021 |
Jan
(14) |
Feb
(5) |
Mar
(40) |
Apr
(32) |
May
(42) |
Jun
(31) |
Jul
(29) |
Aug
(47) |
Sep
(38) |
Oct
(17) |
Nov
(74) |
Dec
(33) |
2022 |
Jan
(11) |
Feb
(15) |
Mar
(40) |
Apr
(21) |
May
(39) |
Jun
(44) |
Jul
(19) |
Aug
(46) |
Sep
(79) |
Oct
(35) |
Nov
(21) |
Dec
(15) |
2023 |
Jan
(56) |
Feb
(13) |
Mar
(43) |
Apr
(28) |
May
(60) |
Jun
(15) |
Jul
(29) |
Aug
(28) |
Sep
(32) |
Oct
(21) |
Nov
(42) |
Dec
(39) |
2024 |
Jan
(35) |
Feb
(17) |
Mar
(28) |
Apr
(7) |
May
(14) |
Jun
(35) |
Jul
(30) |
Aug
(35) |
Sep
(30) |
Oct
(28) |
Nov
(38) |
Dec
(18) |
2025 |
Jan
(21) |
Feb
(28) |
Mar
(36) |
Apr
(35) |
May
(34) |
Jun
(58) |
Jul
(9) |
Aug
(37) |
Sep
|
Oct
|
Nov
|
Dec
|
From: Zach W. <zw...@us...> - 2009-11-25 21:09:17
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 49036463dbebcd4c5722f89b86dc6cec777bab0f (commit) from 4946925bea77a4aace6c310b2b724cf2095c6719 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 49036463dbebcd4c5722f89b86dc6cec777bab0f Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 07:06:32 2009 -0800 update NEWS with recent developments Mention changes to flash bank command syntax, 'nand verify' command, command error handling and reporting, and help/usage command upgrades. diff --git a/NEWS b/NEWS index 0dcc4bc..a0bf43c 100644 --- a/NEWS +++ b/NEWS @@ -16,13 +16,30 @@ Target Layer: - accelerated GDB memory checksum Flash Layer: + 'flash bank' and 'nand device' take <bank_name> as first argument. + With this, flash/NAND commands allow referencing banks by name: + - <bank_name>: reference the bank with its defined name + - <driver_name>[.N]: reference the driver's Nth bank + New 'nand verify' command to check bank against an image file. + Board, Target, and Interface Configuration Scripts: ARM9 - ETM and ETB hookup for iMX2* targets Add $HOME/.openocd to the search path. +Core Jim/TCL Scripting: + New 'usage' command to provide terse command help. + Improved command 'help' command output (sorted and indented). + Improved command handling: + - Most boolean settings now accept any of the following: + on/off, enable/disable, true/false, yes/no, 1/0 + - More error checking and reporting. + Documentation: + New built-in command development documentation and primer. + Build and Release: + Use --enable-doxygen-pdf to build PDF developer documentation. For more details about what has changed since the last release, see the git repository history. With gitweb, you can browse that ----------------------------------------------------------------------- Summary of changes: NEWS | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-25 19:58:21
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 4946925bea77a4aace6c310b2b724cf2095c6719 (commit) via a3d81eed4d2aac51056f36d7c00ee639bb39c552 (commit) via be482a5335dd35ee1fa163faa0af481b2ec65b70 (commit) via ed90b6659f6d6b98b59d65f7a889e0221bdffa87 (commit) via 9d4c89f37f814df05837cec280b362ad2962c667 (commit) via a93b404161dc42f8dee805c8f95bc4974aded9cb (commit) via d89c6310146d9e5fd1a4ab364f09c0f841da5c73 (commit) via 9e5d8a94f1ea28ee6764511f0cb3c38b22ca8b51 (commit) via 910bb250c479b4de9c30231e1a090e9a2d647434 (commit) via c297a14f7072d98bdad6bd7b9bac3a3069de9ed9 (commit) via 6b066cd17073d868b88414556d1ca3f0580449ec (commit) via 8f5ff3ddcf0ab11b0ec6fc9215144154fb0519f9 (commit) via 17a9dea53a71e9d7e241262725f3dd707b620d37 (commit) via cd7e76ebf0e09466aeb3c61498360c45a1a3ad39 (commit) from f74e2e033a2ad082e5bef67d0ddedd1db3f58300 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4946925bea77a4aace6c310b2b724cf2095c6719 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 20:32:10 2009 -0800 use ARRAY_SIZE macro Search and destroy lingering cases where the ARRAY_SIZE macro should be used to convey more intrinsic meaning in the OpenOCD code. diff --git a/src/flash/avrf.c b/src/flash/avrf.c index 1c48464..687dd4b 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -290,7 +290,7 @@ static int avrf_probe(struct flash_bank *bank) LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); } - for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++) + for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++) { if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id)) { @@ -369,7 +369,7 @@ static int avrf_info(struct flash_bank *bank, char *buf, int buf_size) LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F); } - for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++) + for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++) { if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id)) { diff --git a/src/flash/tms470.c b/src/flash/tms470.c index 682013e..5965934 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -46,7 +46,7 @@ const struct flash_sector TMS470R1A256_SECTORS[] = { }; #define TMS470R1A256_NUM_SECTORS \ - (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0])) + ARRAY_SIZE(TMS470R1A256_SECTORS) const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = { {0x00000000, 0x00002000, -1, -1}, @@ -56,7 +56,7 @@ const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = { }; #define TMS470R1A288_BANK0_NUM_SECTORS \ - (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0])) + ARRAY_SIZE(TMS470R1A288_BANK0_SECTORS) const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = { {0x00040000, 0x00010000, -1, -1}, @@ -66,7 +66,7 @@ const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = { }; #define TMS470R1A288_BANK1_NUM_SECTORS \ - (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0])) + ARRAY_SIZE(TMS470R1A288_BANK1_SECTORS) const struct flash_sector TMS470R1A384_BANK0_SECTORS[] = { {0x00000000, 0x00002000, -1, -1}, @@ -82,7 +82,7 @@ const struct flash_sector TMS470R1A384_BANK0_SECTORS[] = { }; #define TMS470R1A384_BANK0_NUM_SECTORS \ - (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0])) + ARRAY_SIZE(TMS470R1A384_BANK0_SECTORS) const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = { {0x00020000, 0x00008000, -1, -1}, @@ -92,7 +92,7 @@ const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = { }; #define TMS470R1A384_BANK1_NUM_SECTORS \ - (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0])) + ARRAY_SIZE(TMS470R1A384_BANK1_SECTORS) const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = { {0x00040000, 0x00008000, -1, -1}, @@ -102,7 +102,7 @@ const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = { }; #define TMS470R1A384_BANK2_NUM_SECTORS \ - (sizeof(TMS470R1A384_BANK2_SECTORS)/sizeof(TMS470R1A384_BANK2_SECTORS[0])) + ARRAY_SIZE(TMS470R1A384_BANK2_SECTORS) /* ---------------------------------------------------------------------- */ diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 73cbaf3..29b6389 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -1949,7 +1949,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor { static const char* type_str[] = {"BM", "AM", "100AX", "UNKNOWN", "2232C", "232R", "2232H", "4232H"}; - unsigned no_of_known_types = sizeof(type_str) / sizeof(type_str[0]) - 1; + unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1; unsigned type_index = ((unsigned)ftdi_device <= no_of_known_types) ? ftdi_device : FT_DEVICE_UNKNOWN; LOG_INFO("device: %lu \"%s\"", ftdi_device, type_str[type_index]); @@ -2034,7 +2034,7 @@ static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_mo ftdi_device = ftdic.type; static const char* type_str[] = {"AM", "BM", "2232C", "R", "2232H", "4232H", "Unknown"}; - unsigned no_of_known_types = sizeof(type_str) / sizeof(type_str[0]) - 1; + unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1; unsigned type_index = ((unsigned)ftdi_device < no_of_known_types) ? ftdi_device : no_of_known_types; LOG_DEBUG("FTDI chip type: %i \"%s\"", (int)ftdi_device, type_str[type_index]); diff --git a/src/jtag/rlink/rlink_speed_table.c b/src/jtag/rlink/rlink_speed_table.c index 5c40ab4..2ef62ee 100644 --- a/src/jtag/rlink/rlink_speed_table.c +++ b/src/jtag/rlink/rlink_speed_table.c @@ -97,5 +97,5 @@ const struct rlink_speed_table rlink_speed_table[] = {{ dtc_2, sizeof(dtc_2), (ST7_FOSC * 2) / (1000 * 2), 2 }}; -const size_t rlink_speed_table_size = sizeof(rlink_speed_table) / sizeof(*rlink_speed_table); +const size_t rlink_speed_table_size = ARRAY_SIZE(rlink_speed_table); diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index bc29078..e755dd7 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1304,7 +1304,7 @@ static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *ar { tap_state_t states[8]; - if ((argc < 2) || ((size_t)argc > (sizeof(states)/sizeof(*states) + 1))) + if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1))) { Jim_WrongNumArgs(interp, 1, args, "wrong arguments"); return JIM_ERR; diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 9d89086..fc3f47c 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -596,7 +596,7 @@ int armv7m_checksum_memory(struct target *target, } /* convert flash writing code into a buffer in target endianness */ - for (i = 0; i < (sizeof(cortex_m3_crc_code)/sizeof(uint16_t)); i++) + for (i = 0; i < ARRAY_SIZE(cortex_m3_crc_code); i++) if ((retval = target_write_u16(target, crc_algorithm->address + i*sizeof(uint16_t), cortex_m3_crc_code[i])) != ERROR_OK) { return retval; @@ -659,7 +659,7 @@ int armv7m_blank_check_memory(struct target *target, } /* convert flash writing code into a buffer in target endianness */ - for (i = 0; i < (sizeof(erase_check_code)/sizeof(uint16_t)); i++) + for (i = 0; i < ARRAY_SIZE(erase_check_code); i++) target_write_u16(target, erase_check_algorithm->address + i*sizeof(uint16_t), erase_check_code[i]); armv7m_info.common_magic = ARMV7M_COMMON_MAGIC; diff --git a/src/target/avrt.c b/src/target/avrt.c index dc527f5..6ba6206 100644 --- a/src/target/avrt.c +++ b/src/target/avrt.c @@ -196,7 +196,7 @@ int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_l field[0].num_bits = tap->ir_length; field[0].out_value = ir_out; field[0].in_value = ir_in; - jtag_add_plain_ir_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE)); + jtag_add_plain_ir_scan(ARRAY_SIZE(field), field, jtag_set_end_state(TAP_IDLE)); } return ERROR_OK; @@ -217,7 +217,7 @@ int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_l field[0].num_bits = dr_len; field[0].out_value = dr_out; field[0].in_value = dr_in; - jtag_add_plain_dr_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE)); + jtag_add_plain_dr_scan(ARRAY_SIZE(field), field, jtag_set_end_state(TAP_IDLE)); } return ERROR_OK; diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 4f9a704..604d34e 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -348,8 +348,8 @@ int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int co param_in[0] = addr; param_in[1] = blocksize; - if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, - sizeof(param_in)/sizeof(param_in[0]), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK) + if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK) { return retval; } @@ -387,8 +387,8 @@ int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t param_in[0] = addr; - if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, - sizeof(param_in)/sizeof(param_in[0]), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK) + if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK) { return retval; } @@ -459,8 +459,8 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co param_in[0] = addr; param_in[1] = blocksize; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1); + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ + ARRAY_SIZE(param_in), param_in, count, param_out, 1); // count -= blocksize; // addr += blocksize; @@ -540,8 +540,8 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou param_in[0] = addr; param_in[1] = blocksize; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1); + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ + ARRAY_SIZE(param_in), param_in, count, param_out, 1); // count -= blocksize; // addr += blocksize; @@ -619,7 +619,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c memcpy(¶m_in[2], buf, count * sizeof(uint32_t)); - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ count + 2, param_in, 0, NULL, 1); free(param_in); @@ -654,8 +654,8 @@ int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_ param_in[0] = addr; param_in[1] = *buf; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1); + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ + ARRAY_SIZE(param_in),param_in, 0, NULL, 1); return ERROR_OK; } @@ -714,7 +714,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c param_in[i + 2] = buf[i]; } - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ count + 2, param_in, 0, NULL, 1); free(param_in); @@ -777,7 +777,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co param_in[i + 2] = buf[i]; } - retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ count +2, param_in, 0, NULL, 1); free(param_in); @@ -851,7 +851,7 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs) int retval; - retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ 38, regs, 0, NULL, 1); return retval; @@ -928,7 +928,7 @@ int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs) int retval; - retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ 0, NULL, 38, regs, 1); return retval; diff --git a/src/target/mips_ejtag.c b/src/target/mips_ejtag.c index 6f06d9a..68a39fa 100644 --- a/src/target/mips_ejtag.c +++ b/src/target/mips_ejtag.c @@ -143,7 +143,7 @@ int mips_ejtag_step_enable(struct mips_ejtag *ejtag_info) MIPS32_NOP, }; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ 0, NULL, 0, NULL, 1); return ERROR_OK; @@ -169,7 +169,7 @@ int mips_ejtag_step_disable(struct mips_ejtag *ejtag_info) MIPS32_NOP, }; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ 0, NULL, 0, NULL, 1); return ERROR_OK; @@ -234,7 +234,7 @@ int mips_ejtag_read_debug(struct mips_ejtag *ejtag_info, uint32_t* debug_reg) MIPS32_NOP, }; - mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ + mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ 0, NULL, 1, debug_reg, 1); return ERROR_OK; diff --git a/src/target/xscale.c b/src/target/xscale.c index e402a11..07fcc4c 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -412,7 +412,7 @@ static int xscale_read_tx(struct target *target, int consume) jtag_add_pathmove(3, path); else { - jtag_add_pathmove(sizeof(noconsume_path)/sizeof(*noconsume_path), noconsume_path); + jtag_add_pathmove(ARRAY_SIZE(noconsume_path), noconsume_path); } jtag_add_dr_scan(3, fields, jtag_set_end_state(TAP_IDLE)); @@ -2825,7 +2825,7 @@ static void xscale_build_reg_cache(struct target *target) struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); struct xscale_reg *arch_info = malloc(sizeof(xscale_reg_arch_info)); int i; - int num_regs = sizeof(xscale_reg_arch_info) / sizeof(struct xscale_reg); + int num_regs = ARRAY_SIZE(xscale_reg_arch_info); (*cache_p) = armv4_5_build_reg_cache(target, armv4_5); commit a3d81eed4d2aac51056f36d7c00ee639bb39c552 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 12:14:05 2009 -0800 support OPENOCD_DEBUG_LEVEL environment setting Detect the OPENOCD_DEBUG_LEVEL setting in log_init(), allowing the very early startup phases to be debugged. diff --git a/src/helper/log.c b/src/helper/log.c index 27fa831..3067ecc 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -346,6 +346,19 @@ void log_init(void) if (debug_level == -1) debug_level = LOG_LVL_INFO; + char *debug_env = getenv("OPENOCD_DEBUG_LEVEL"); + if (NULL != debug_env) + { + int value; + int retval = parse_int(debug_env, &value); + if (ERROR_OK == retval && + debug_level >= LOG_LVL_SILENT && + debug_level <= LOG_LVL_DEBUG) + { + debug_level = value; + } + } + if (log_output == NULL) log_output = stderr; commit be482a5335dd35ee1fa163faa0af481b2ec65b70 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 16:36:32 2009 -0800 log: improve initialization Removes redundant assignment of start_ms from log_register_commands(). Eliminates command_context parameter and return value. Adds Doxygen comment block for this API call. diff --git a/src/helper/log.c b/src/helper/log.c index 3799fb3..27fa831 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -336,25 +336,20 @@ static struct command_registration log_command_handlers[] = { int log_register_commands(struct command_context *cmd_ctx) { - start = timeval_ms(); - return register_commands(cmd_ctx, NULL, log_command_handlers); } -int log_init(struct command_context *cmd_ctx) +void log_init(void) { - /* set defaults for daemon configuration, if not set by cmdline or cfgfile */ + /* set defaults for daemon configuration, + * if not set by cmdline or cfgfile */ if (debug_level == -1) debug_level = LOG_LVL_INFO; if (log_output == NULL) - { log_output = stderr; - } start = last_time = timeval_ms(); - - return ERROR_OK; } int set_log_output(struct command_context *cmd_ctx, FILE *output) diff --git a/src/helper/log.h b/src/helper/log.h index 6f7c24a..f2d19d1 100644 --- a/src/helper/log.h +++ b/src/helper/log.h @@ -66,7 +66,10 @@ void log_printf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, ...) __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6))); -int log_init(struct command_context *cmd_ctx); +/** + * Initialize logging module. Call during program startup. + */ +void log_init(void); int set_log_output(struct command_context *cmd_ctx, FILE *output); int log_register_commands(struct command_context *cmd_ctx); diff --git a/src/openocd.c b/src/openocd.c index 1f29acd..629d50a 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -182,6 +182,9 @@ struct command_context *global_cmd_ctx; /* NB! this fn can be invoked outside this file for non PC hosted builds */ struct command_context *setup_command_handler(void) { + log_init(); + LOG_DEBUG("log_init: complete"); + struct command_context *cmd_ctx; global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl); @@ -202,11 +205,7 @@ struct command_context *setup_command_handler(void) pld_register_commands(cmd_ctx); mflash_register_commands(cmd_ctx); - if (log_init(cmd_ctx) != ERROR_OK) - { - exit(-1); - } - LOG_DEBUG("log init complete"); + LOG_DEBUG("command registration: complete"); LOG_OUTPUT(OPENOCD_VERSION "\n"); commit ed90b6659f6d6b98b59d65f7a889e0221bdffa87 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 18:47:35 2009 -0800 update command handler documentation Adds sections on command registration and chaining, giving an overview to developers that want to use these features. diff --git a/doc/manual/helper.txt b/doc/manual/helper.txt index e7454b6..aa52355 100644 --- a/doc/manual/helper.txt +++ b/doc/manual/helper.txt @@ -80,6 +80,42 @@ command handlers and helpers: - @c CMD_ARGC - the number of command arguments - @c CMD_ARGV - array of command argument strings +@section helpercmdregister Command Registration + +In order to use a command handler, it must be registered with the +command subsystem. All commands are registered with command_registration +structures, specifying the name of the command, its handler, its allowed +mode(s) of execution, and strings that provide usage and help text. +A single handler may be registered using multiple names, but any name +may have only one handler associated with it. + +The @c register_commands() and @c register_commands() functions provide +registration, while the @c unregister_command() and +@c unregister_all_commands() functions will remove existing commands. +These may be called at any time, allowing the command set to change in +response to system actions. + +@subsection helpercmdjim Jim Command Registration + +The command_registration structure provides support for registering +native Jim command handlers (@c jim_handler) too. For these handlers, +the module can provide help and usage support; however, this mechanism +allows Jim handlers to be called as sub-commands of other commands. +These commands may be registered with a private data value (@c +jim_handler_data) that will be available when called, as with low-level +Jim command registration. + +A command may have a normal @c handler or a @c jim_handler, but not both. + +@subsection helpercmdregisterchains Command Chaining + +When using register_commands(), the array of commands may reference +other arrays. When the @c chain field is filled in a +command_registration record, the commands on in the chained list will +added in one of two places. If the record defines a new command, then +the chained commands are added under it; otherwise, the commands are +added in the same context as the other commands in the array. + @section helpercmdprimer Command Development Primer This @ref primercommand provides details about the @c hello module, diff --git a/doc/manual/primer/commands.txt b/doc/manual/primer/commands.txt index b15f669..c9db7cc 100644 --- a/doc/manual/primer/commands.txt +++ b/doc/manual/primer/commands.txt @@ -63,42 +63,71 @@ Before this new function can be used, it must be registered somehow. For a new module, registering should be done in a new function for the purpose, which must be called from @c openocd.c: @code + +static const struct command_registration hello_command_handlers[] = { + { + .name = "hello", + .mode = COMMAND_ANY, + .handler = &handle_hello_command, + .help = "print a warm greetings", + .usage = "[<name>]", + }, + { + .chain = foo_command_handlers, + } + COMMAND_REGISTRATION_DONE +}; + int hello_register_commands(struct command_context_s *cmd_ctx) { - struct command_s *cmd = register_command(cmd_ctx, NULL, "hello", - NULL, COMMAND_ANY, "print greetings"); - return cmd ? ERROR_OK : -ENOMEM; + return register_commands(cmd_ctx, NULL, handle_command_handlers); } @endcode That's it! The command should now be registered and avaiable to scripts. +@section primercmdchain Command Chaining + +This example also shows how to chain command handler registration, so +your modules can "inherit" commands provided by other (sub)modules. +Here, the hello module includes the foo commands in the same context +that the 'hello' command will be registered. + +If the @c chain field had been put in the 'hello' command, then the +@c foo module commands would be registered under it. Indeed, that +technique is used to define the 'foo bar' and 'foo baz' commands, +as well as for the example drivers that use these modules. + +The code for the 'foo' command handlers can be found in @c hello.c. + @section primercmdcode Trying These Example Commands -The commands may be enabled by editing src/openocd.c and uncommenting -the call to @c hello_register_commands and rebuilding the source tree. +These commands have been inherited by the dummy interface, faux flash, +and testee target drivers. The easiest way to test these is by using the +dummy interface. -Once OpenOCD has been built with this example code, the following script -demonstrate the abilities that the @c hello module provides: +Once OpenOCD has been built with this example code, the following command +demonstrates the abilities that the @c hello module provides: @code -hello -hello World -hello {John Doe} -hello John Doe # error: too many arguments +openocd -c 'interface dummy' \ + -c 'dummy hello' \ + -c 'dummy hello World' \ + -c 'dummy hello {John Doe}' \ + -c 'dummy hello John Doe' # error: too many arguments @endcode If saved in @c hello.cfg, then running <code>openocd -f hello.cfg</code> -should produce the following output before exiting: +should produce the following output before displaying the help text and +exiting: @code Greetings! Greetings, World! Greetings, John Doe! -Error: ocd_hello: too many arguments +Error: hello: too many arguments +Runtime error, file "openocd.cfg", line 14: + hello: too many arguments +dummy hello [<name>] + prints a warm welcome @endcode -This difference between the registered and displayed command name comes from -the fact that the TCL scripts are provided with a stub that calls the munged -name. This stub wraps the internal <code>ocd_</code>-prefixed routine, -providing a measure of high-level error handling. - */ commit 9d4c89f37f814df05837cec280b362ad2962c667 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 22:09:53 2009 -0800 add 'testee' target type Alliteration aside, this should provide the final piece of the puzzle for developers that want to get started writing a new target type. In this way, it also seeks to complement the 'dummy' interface driver and 'faux' NOR flash driver. diff --git a/src/target/Makefile.am b/src/target/Makefile.am index a367fd4..d00b0e4 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -42,7 +42,8 @@ TARGET_CORE_SRC = \ image.c \ breakpoints.c \ target.c \ - target_request.c + target_request.c \ + testee.c ARMV4_5_SRC = \ armv4_5.c \ diff --git a/src/target/target.c b/src/target/target.c index 4a9095a..97a93c0 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -65,6 +65,7 @@ extern struct target_type cortexa8_target; extern struct target_type arm11_target; extern struct target_type mips_m4k_target; extern struct target_type avr_target; +extern struct target_type testee_target; struct target_type *target_types[] = { @@ -83,6 +84,7 @@ struct target_type *target_types[] = &arm11_target, &mips_m4k_target, &avr_target, + &testee_target, NULL, }; diff --git a/src/target/testee.c b/src/target/testee.c new file mode 100644 index 0000000..ca3d56e --- /dev/null +++ b/src/target/testee.c @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2009 Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "target.h" +#include "target_type.h" +#include "log.h" +#include "../hello.h" + +static const struct command_registration testee_command_handlers[] = { + { + .name = "testee", + .mode = COMMAND_ANY, + .help = "testee target commands", + + .chain = hello_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + +static int testee_init(struct command_context *cmd_ctx, struct target *target) +{ + return ERROR_OK; +} + +struct target_type testee_target = { + .name = "testee", + .init_target = &testee_init, + .commands = testee_command_handlers, +}; commit a93b404161dc42f8dee805c8f95bc4974aded9cb Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 19:27:20 2009 -0800 improve command handling examples Removes hello and foo commands from top-level registration. Instead, the dummy interface driver and faux flash driver have been augmented to register these commands as sub-commands. diff --git a/src/flash/faux.c b/src/flash/faux.c index adfc7bd..caec2c7 100644 --- a/src/flash/faux.c +++ b/src/flash/faux.c @@ -23,6 +23,7 @@ #include "flash.h" #include "image.h" +#include "../hello.h" struct faux_flash_bank @@ -123,8 +124,19 @@ static int faux_probe(struct flash_bank *bank) return ERROR_OK; } +static const struct command_registration faux_command_handlers[] = { + { + .name = "faux", + .mode = COMMAND_ANY, + .help = "faux flash command group", + .chain = hello_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + struct flash_driver faux_flash = { .name = "faux", + .commands = faux_command_handlers, .flash_bank_command = &faux_flash_bank_command, .erase = &faux_erase, .protect = &faux_protect, diff --git a/src/hello.c b/src/hello.c index 9a1bf92..2e5c928 100644 --- a/src/hello.c +++ b/src/hello.c @@ -101,7 +101,7 @@ COMMAND_HANDLER(handle_hello_command) return retval; } -static const struct command_registration hello_command_handlers[] = { +const struct command_registration hello_command_handlers[] = { { .name = "hello", .handler = &handle_hello_command, diff --git a/src/hello.h b/src/hello.h new file mode 100644 index 0000000..fc674ad --- /dev/null +++ b/src/hello.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2009 Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef OPENOCD_HELLO_H +#define OPENOCD_HELLO_H + +struct command_context; +struct command_registration; + +/// Register the hello commands in the specified command_context +int hello_register_commands(struct command_context *cmd_ctx); + +/** + * Export the registration for the hello command group, so it can be + * embedded in example drivers. + */ +extern const struct command_registration hello_command_handlers[]; + +#endif // OPENOCD_HELLO_H diff --git a/src/jtag/dummy.c b/src/jtag/dummy.c index 11b6f71..c2beb09 100644 --- a/src/jtag/dummy.c +++ b/src/jtag/dummy.c @@ -23,6 +23,7 @@ #include "interface.h" #include "bitbang.h" +#include "../hello.h" /* my private tap controller state, which tracks state for calling code */ @@ -146,12 +147,25 @@ static int dummy_quit(void) return ERROR_OK; } +static const struct command_registration dummy_command_handlers[] = { + { + .name = "dummy", + .mode = COMMAND_ANY, + .help = "dummy interface driver commands", + + .chain = hello_command_handlers, + }, + COMMAND_REGISTRATION_DONE, +}; + /* The dummy driver is used to easily check the code path * where the target is unresponsive. */ struct jtag_interface dummy_interface = { .name = "dummy", + .commands = dummy_command_handlers, + .execute_queue = &bitbang_execute_queue, .speed = &dummy_speed, diff --git a/src/openocd.c b/src/openocd.c index e38c84e..1f29acd 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -179,9 +179,6 @@ static const struct command_registration openocd_command_handlers[] = { struct command_context *global_cmd_ctx; -/// src/hello.c gives a simple example for writing new command modules -int hello_register_commands(struct command_context *cmd_ctx); - /* NB! this fn can be invoked outside this file for non PC hosted builds */ struct command_context *setup_command_handler(void) { @@ -191,7 +188,6 @@ struct command_context *setup_command_handler(void) register_commands(cmd_ctx, NULL, openocd_command_handlers); /* register subsystem commands */ - hello_register_commands(cmd_ctx); server_register_commands(cmd_ctx); telnet_register_commands(cmd_ctx); gdb_register_commands(cmd_ctx); commit d89c6310146d9e5fd1a4ab364f09c0f841da5c73 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 19:51:49 2009 -0800 add script_command_run helper Eliminates duplicated code in script_command and handle_unknown_command. Fixes bug with duplicated help output generated by placeholder commands. diff --git a/src/helper/command.c b/src/helper/command.c index 8b29ab4..62fb487 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -150,33 +150,41 @@ static struct command_context *current_command_context(void) return cmd_ctx; } -static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +static int script_command_run(Jim_Interp *interp, + int argc, Jim_Obj *const *argv, struct command *c, bool capture) { - /* the private data is stashed in the interp structure */ - - struct command *c = interp->cmdPrivData; - assert(c); - target_call_timer_callbacks_now(); LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ - script_debug(interp, c->name, argc, argv); - unsigned nwords; const char **words = script_command_args_alloc(argc, argv, &nwords); if (NULL == words) return JIM_ERR; - Jim_Obj *tclOutput = command_log_capture_start(interp); + Jim_Obj *tclOutput = NULL; + if (capture) + tclOutput = command_log_capture_start(interp); struct command_context *cmd_ctx = current_command_context(); int retval = run_command(cmd_ctx, c, (const char **)words, nwords); - command_log_capture_finish(interp, tclOutput); + if (capture) + command_log_capture_finish(interp, tclOutput); + script_command_args_free(words, nwords); return command_retval_set(interp, retval); } +static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + /* the private data is stashed in the interp structure */ + + struct command *c = interp->cmdPrivData; + assert(c); + script_debug(interp, c->name, argc, argv); + return script_command_run(interp, argc, argv, c, true); +} + /* nice short description of source file */ #define __THIS__FILE__ "command.c" @@ -922,22 +930,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return (*c->jim_handler)(interp, count, start); } - unsigned nwords; - const char **words = script_command_args_alloc(count, start, &nwords); - if (NULL == words) - return JIM_ERR; - - Jim_Obj *tclOutput = command_log_capture_start(interp); - - int retval = run_command(cmd_ctx, c, words, nwords); - - command_log_capture_finish(interp, tclOutput); - script_command_args_free(words, nwords); - - if (!found && ERROR_OK == retval) - retval = ERROR_FAIL; - - return command_retval_set(interp, retval); + return script_command_run(interp, count, start, c, found); } int help_add_command(struct command_context *cmd_ctx, struct command *parent, commit 9e5d8a94f1ea28ee6764511f0cb3c38b22ca8b51 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 19:13:03 2009 -0800 encapsulate and re-use log capture, retval setup Factors log capture while running script commands, eliminating duplicated code between script_command and jim_capture. Factors setting a command's Jim "retval" into a new helper as well. Using these new helpers in the new unknown command handler's fixes possible regressions caused by these bits being missing. diff --git a/src/helper/command.c b/src/helper/command.c index 54eec3b..8b29ab4 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -56,6 +56,34 @@ static void tcl_output(void *privData, const char *file, unsigned line, Jim_AppendString(interp, tclOutput, string, strlen(string)); } +static Jim_Obj *command_log_capture_start(Jim_Interp *interp) +{ + /* capture log output and return it. A garbage collect can + * happen, so we need a reference count to this object */ + Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); + if (NULL == tclOutput) + return NULL; + Jim_IncrRefCount(tclOutput); + log_add_callback(tcl_output, tclOutput); + return tclOutput; +} + +static void command_log_capture_finish(Jim_Interp *interp, Jim_Obj *tclOutput) +{ + log_remove_callback(tcl_output, tclOutput); + Jim_SetResult(interp, tclOutput); + Jim_DecrRefCount(interp, tclOutput); +} + +static int command_retval_set(Jim_Interp *interp, int retval) +{ + int *return_retval = Jim_GetAssocData(interp, "retval"); + if (return_retval != NULL) + *return_retval = retval; + + return (retval == ERROR_OK) ? JIM_OK : JIM_ERR; +} + extern struct command_context *global_cmd_ctx; void script_debug(Jim_Interp *interp, const char *name, @@ -125,20 +153,10 @@ static struct command_context *current_command_context(void) static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { /* the private data is stashed in the interp structure */ - struct command *c; - int retval; - /* DANGER!!!! be careful what we invoke here, since interp->cmdPrivData might - * get overwritten by running other Jim commands! Treat it as an - * emphemeral global variable that is used in lieu of an argument - * to the fn and fish it out manually. - */ - c = interp->cmdPrivData; - if (c == NULL) - { - LOG_ERROR("BUG: interp->cmdPrivData == NULL"); - return JIM_ERR; - } + struct command *c = interp->cmdPrivData; + assert(c); + target_call_timer_callbacks_now(); LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ @@ -149,31 +167,14 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (NULL == words) return JIM_ERR; - /* capture log output and return it */ - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); - /* a garbage collect can happen, so we need a reference count to this object */ - Jim_IncrRefCount(tclOutput); - - log_add_callback(tcl_output, tclOutput); + Jim_Obj *tclOutput = command_log_capture_start(interp); struct command_context *cmd_ctx = current_command_context(); - retval = run_command(cmd_ctx, c, (const char **)words, nwords); - - log_remove_callback(tcl_output, tclOutput); - - /* We dump output into this local variable */ - Jim_SetResult(interp, tclOutput); - Jim_DecrRefCount(interp, tclOutput); + int retval = run_command(cmd_ctx, c, (const char **)words, nwords); + command_log_capture_finish(interp, tclOutput); script_command_args_free(words, nwords); - - int *return_retval = Jim_GetAssocData(interp, "retval"); - if (return_retval != NULL) - { - *return_retval = retval; - } - - return (retval == ERROR_OK)?JIM_OK:JIM_ERR; + return command_retval_set(interp, retval); } /* nice short description of source file */ @@ -766,23 +767,13 @@ static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { if (argc != 2) return JIM_ERR; - int retcode; - const char *str = Jim_GetString(argv[1], NULL); - - /* capture log output and return it */ - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); - /* a garbage collect can happen, so we need a reference count to this object */ - Jim_IncrRefCount(tclOutput); - - log_add_callback(tcl_output, tclOutput); - retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__); + Jim_Obj *tclOutput = command_log_capture_start(interp); - log_remove_callback(tcl_output, tclOutput); + const char *str = Jim_GetString(argv[1], NULL); + int retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__); - /* We dump output into this local variable */ - Jim_SetResult(interp, tclOutput); - Jim_DecrRefCount(interp, tclOutput); + command_log_capture_finish(interp, tclOutput); return retcode; } @@ -936,14 +927,17 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (NULL == words) return JIM_ERR; + Jim_Obj *tclOutput = command_log_capture_start(interp); + int retval = run_command(cmd_ctx, c, words, nwords); + command_log_capture_finish(interp, tclOutput); script_command_args_free(words, nwords); if (!found && ERROR_OK == retval) retval = ERROR_FAIL; - return retval; + return command_retval_set(interp, retval); } int help_add_command(struct command_context *cmd_ctx, struct command *parent, commit 910bb250c479b4de9c30231e1a090e9a2d647434 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 22:18:28 2009 -0800 combine help and usage command handlers Remove duplicated handler code by checking the running command name. diff --git a/src/helper/command.c b/src/helper/command.c index a1ba358..54eec3b 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -861,30 +861,18 @@ static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, } COMMAND_HANDLER(handle_help_command) { - struct command *c = CMD_CTX->commands; - - if (0 == CMD_ARGC) - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, true); + bool full = strcmp(CMD_NAME, "help") == 0; - int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); - if (ERROR_OK != retval) - return retval; - - return CALL_COMMAND_HANDLER(command_help_show, c, 0, true); -} - -COMMAND_HANDLER(handle_usage_command) -{ struct command *c = CMD_CTX->commands; if (0 == CMD_ARGC) - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, false); + return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, full); int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); if (ERROR_OK != retval) return retval; - return CALL_COMMAND_HANDLER(command_help_show, c, 0, false); + return CALL_COMMAND_HANDLER(command_help_show, c, 0, full); } static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, @@ -1106,15 +1094,15 @@ static const struct command_registration command_builtin_handlers[] = { .name = "help", .handler = &handle_help_command, .mode = COMMAND_ANY, - .help = "show built-in command help", - .usage = "[<command_name> ...]", + .help = "show full command help", + .usage = "[<command> ...]", }, { .name = "usage", - .handler = &handle_usage_command, + .handler = &handle_help_command, .mode = COMMAND_ANY, - .help = "show command usage", - .usage = "[<command_name> ...]", + .help = "show basic command usage", + .usage = "[<command> ...]", }, COMMAND_REGISTRATION_DONE }; commit c297a14f7072d98bdad6bd7b9bac3a3069de9ed9 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 12:00:31 2009 -0800 improve usage and help command output Rewrite formatting code in C, removing last remenants of TCL help code. Sinificantly improves the readability by using smarter indent and wrap. diff --git a/src/helper/command.c b/src/helper/command.c index 1263a93..a1ba358 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -811,20 +811,48 @@ static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n, CALL_COMMAND_HANDLER(command_help_show, c, n, show_help); return ERROR_OK; } + +#define HELP_LINE_WIDTH(_n) (int)(76 - (2 * _n)) + +static void command_help_show_indent(unsigned n) +{ + for (unsigned i = 0; i < n; i++) + LOG_USER_N(" "); +} +static void command_help_show_wrap(const char *str, unsigned n, unsigned n2) +{ + const char *cp = str, *last = str; + while (*cp) + { + const char *next = last; + do { + cp = next; + do { + next++; + } while (*next != ' ' && *next != '\t' && *next != '\0'); + } while ((next - last < HELP_LINE_WIDTH(n)) && *next != '\0'); + if (next - last < HELP_LINE_WIDTH(n)) + cp = next; + command_help_show_indent(n); + LOG_USER_N("%.*s", (int)(cp - last), last); + LOG_USER_N("\n"); + last = cp + 1; + n = n2; + } +} static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, bool show_help) { - const char *usage = c->usage ? : ""; - const char *help = ""; - const char *sep = ""; - if (show_help && c->help) - { - help = c->help ? : ""; - sep = c->usage ? " | " : ""; + command_help_show_indent(n); + LOG_USER_N("%s", command_name(c, ' ')); + if (c->usage) { + LOG_USER_N(" "); + command_help_show_wrap(c->usage, 0, n + 5); } - command_run_linef(CMD_CTX, "cmd_help {%s} {%s%s%s} %d", - command_name(c, ' '), usage, sep, help, n); - + else + LOG_USER_N("\n"); + if (show_help && c->help) + command_help_show_wrap(c->help, n + 3, n + 3); if (++n >= 2) return ERROR_OK; diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 5969cfe..f11d5b6 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -10,40 +10,6 @@ proc exit {} { ocd_throw exit } -# Help text list. A list of command + help text pairs. -proc cmd_help {cmdname h indent} { - set indent [expr $indent * 2] - - set fmt_str [format "%%%ds%%-%ds %%s" $indent [expr 25 - $indent]] - set w [expr 50 - $indent] - set n 0 - - while 1 { - if {$n > [string length $h]} {break} - - set next_a [expr $n + $w] - if {[string length $h] > $n + $w} \ - { - set xxxx [string range $h $n [expr $n + $w]] - for {set lastpos [expr [string length $xxxx] - 1]} \ - {$lastpos >= 0 && [string compare \ - [string range $xxxx $lastpos $lastpos] " "] != 0} \ - {set lastpos [expr $lastpos - 1]} \ - { - } - #set next_a -1 - if {$lastpos != -1} { - set next_a [expr $lastpos + $n + 1] - } - } - - puts [format $fmt_str "" $cmdname \ - [string range $h $n [expr $next_a - 1]] ] - set cmdname "" - set n [expr $next_a] - } -} - # Try flipping / and \ to find file if the filename does not # match the precise spelling proc find {filename} { commit 6b066cd17073d868b88414556d1ca3f0580449ec Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 12:16:27 2009 -0800 allow scripts to update usage information The add_usage_text command uses the same C handler, which was updated to support its new polymorphic role. This patch updates the two script commands that needed this support: 'find' and 'script'. diff --git a/src/helper/command.c b/src/helper/command.c index 3cb36ea..1263a93 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -951,8 +951,9 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, return ERROR_FAIL; } LOG_DEBUG("added '%s' help text", cmd_name); + return ERROR_OK; } - else + if (help_text) { bool replaced = false; if (nc->help) @@ -961,12 +962,25 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, replaced = true; } nc->help = strdup(help_text); - if (replaced) LOG_INFO("replaced existing '%s' help", cmd_name); else LOG_DEBUG("added '%s' help text", cmd_name); } + if (usage) + { + bool replaced = false; + if (nc->usage) + { + free((void *)nc->usage); + replaced = true; + } + nc->usage = strdup(usage); + if (replaced) + LOG_INFO("replaced existing '%s' usage", cmd_name); + else + LOG_DEBUG("added '%s' usage text", cmd_name); + } return ERROR_OK; } @@ -979,7 +993,14 @@ COMMAND_HANDLER(handle_help_add_command) } // save help text and remove it from argument list - const char *help_text = CMD_ARGV[--CMD_ARGC]; + const char *str = CMD_ARGV[--CMD_ARGC]; + const char *help = !strcmp(CMD_NAME, "add_help_text") ? str : NULL; + const char *usage = !strcmp(CMD_NAME, "add_usage_text") ? str : NULL; + if (!help && !usage) + { + LOG_ERROR("command name '%s' is unknown", CMD_NAME); + return ERROR_INVALID_ARGUMENTS; + } // likewise for the leaf command name const char *cmd_name = CMD_ARGV[--CMD_ARGC]; @@ -991,7 +1012,7 @@ COMMAND_HANDLER(handle_help_add_command) if (ERROR_OK != retval) return retval; } - return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL); + return help_add_command(CMD_CTX, c, cmd_name, help, usage); } /* sleep command sleeps for <n> miliseconds @@ -1039,6 +1060,13 @@ static const struct command_registration command_builtin_handlers[] = { .usage = "<command> [...] <help_text>]", }, { + .name = "add_usage_text", + .handler = &handle_help_add_command, + .mode = COMMAND_ANY, + .help = "add new command usage text", + .usage = "<command> [...] <usage_text>]", + }, + { .name = "sleep", .handler = &handle_sleep_command, .mode = COMMAND_ANY, diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index ede8cdb..5969cfe 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -59,14 +59,15 @@ proc find {filename} { # make sure error message matches original input string return -code error "Can't find $filename" } -add_help_text find "<file> - print full path to file according to OpenOCD search rules" +add_usage_text find "<file>" +add_help_text find "print full path to file according to OpenOCD search rules" # Run script proc script {filename} { source [find $filename] } - -add_help_text script "<filename> - filename of OpenOCD script (tcl) to run" +add_help_text script "filename of OpenOCD script (tcl) to run" +add_usage_text script "<file>" ######### commit 8f5ff3ddcf0ab11b0ec6fc9215144154fb0519f9 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 10:58:32 2009 -0800 httpd: use register_commands() Updates httpd_start() to use register_commands() for 'readform' and 'writeform' commands. Adds server/httpd.h to export the new signatures for this function (and httpd_stop), which allows removing the obsoleted declarations inside openocd.c. diff --git a/src/openocd.c b/src/openocd.c index 63289e4..e38c84e 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -41,6 +41,7 @@ #include "telnet_server.h" #include "gdb_server.h" #include "tcl_server.h" +#include "httpd.h" #ifdef HAVE_STRINGS_H #include <strings.h> @@ -216,10 +217,6 @@ struct command_context *setup_command_handler(void) return cmd_ctx; } -int httpd_start(void); -void httpd_stop(void); - - #if !BUILD_HTTPD && !BUILD_ECOSBOARD /* implementations of OpenOCD that uses multithreading needs to know when * OpenOCD is sleeping. No-op in vanilla OpenOCD @@ -269,7 +266,7 @@ int openocd_main(int argc, char *argv[]) return EXIT_FAILURE; #if BUILD_HTTPD - if (httpd_start() != ERROR_OK) + if (httpd_start(cmd_ctx) != ERROR_OK) return EXIT_FAILURE; #endif diff --git a/src/server/Makefile.am b/src/server/Makefile.am index bb7d5ef..95fb519 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -14,6 +14,7 @@ libserver_la_SOURCES = server.c telnet_server.c gdb_server.c if HTTPD libserver_la_SOURCES += httpd.c endif +noinst_HEADERS += httpd.h libserver_la_CFLAGS = if IS_MINGW diff --git a/src/server/httpd.c b/src/server/httpd.c index 1c5e6d2..8c1d3db 100644 --- a/src/server/httpd.c +++ b/src/server/httpd.c @@ -460,7 +460,25 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, static struct MHD_Daemon * d; -int httpd_start(void) +static const struct command_registration httpd_command_handlers[] = { + { + .name = "formfetch", + .jim_handler = &httpd_Jim_Command_formfetch, + .mode = COMMAND_EXEC, + .usage = "<parameter_name>", + .help = "Reads a posted form value.", + }, + { + .name = "writeform", + .jim_handler = &httpd_Jim_Command_writeform, + .mode = COMMAND_EXEC, + .usage = "<parameter_name> <file>", + .help = "Writes a form value to a file.", + }, + COMMAND_REGISTRATION_DONE +}; + +int httpd_start(struct command_context *cmd_ctx) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); @@ -475,20 +493,7 @@ int httpd_start(void) if (d == NULL) return ERROR_FAIL; - Jim_CreateCommand(interp, - "formfetch", - httpd_Jim_Command_formfetch, - NULL, - NULL); - - Jim_CreateCommand(interp, - "writeform", - httpd_Jim_Command_writeform, - NULL, - NULL); - - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, httpd_command_handlers); } void httpd_stop(void) diff --git a/src/server/httpd.h b/src/server/httpd.h new file mode 100644 index 0000000..0502deb --- /dev/null +++ b/src/server/httpd.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * Copyright (C) 2009 Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef OPENOCD_SERVER_HTTPD_H +#define OPENOCD_SERVER_HTTPD_H + +struct command_context; + +int httpd_start(struct command_context *cmd_ctx); +void httpd_stop(void); + +#endif // OPENOCD_SERVER_HTTPD_H commit 17a9dea53a71e9d7e241262725f3dd707b620d37 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 15:03:04 2009 -0800 add jim_handler to command_registration Adding jim_handler field to command_registration allows removing the register_jim helper. All command registrations now go through the register_command{,s}() functions. diff --git a/src/flash/flash.c b/src/flash/flash.c index 4584c5d..bbdbaa8 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -1368,8 +1368,6 @@ static const struct command_registration flash_exec_command_handlers[] = { int flash_init_drivers(struct command_context *cmd_ctx) { - register_jim(cmd_ctx, "ocd_flash_banks", - jim_flash_banks, "return information about the flash banks"); if (!flash_banks) return ERROR_OK; @@ -1377,7 +1375,6 @@ int flash_init_drivers(struct command_context *cmd_ctx) return register_commands(cmd_ctx, parent, flash_exec_command_handlers); } - static const struct command_registration flash_config_command_handlers[] = { { .name = "bank", @@ -1389,6 +1386,12 @@ static const struct command_registration flash_config_command_handlers[] = { .help = "Define a new bank with the given name, " "using the specified NOR flash driver.", }, + { + .name = "banks", + .mode = COMMAND_ANY, + .jim_handler = &jim_flash_banks, + .help = "return information about the flash banks", + }, COMMAND_REGISTRATION_DONE }; static const struct command_registration flash_command_handlers[] = { diff --git a/src/helper/command.c b/src/helper/command.c index 8d710c9..3cb36ea 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -252,6 +252,8 @@ static struct command *command_new(struct command_context *cmd_ctx, c->usage = strdup(cr->usage); c->parent = parent; c->handler = cr->handler; + c->jim_handler = cr->jim_handler; + c->jim_handler_data = cr->jim_handler_data; c->mode = cr->mode; command_add_child(command_list_for_parent(cmd_ctx, parent), c); @@ -327,16 +329,22 @@ struct command* register_command(struct command_context *context, } c = command_new(context, parent, cr); - /* if allocation failed or it is a placeholder (no handler), we're done */ - if (NULL == c || NULL == c->handler) - return c; + if (NULL == c) + return NULL; - int retval = register_command_handler(c); - if (ERROR_OK != retval) + if (NULL != c->handler) { - unregister_command(context, parent, name); - c = NULL; + int retval = register_command_handler(c); + if (ERROR_OK != retval) + { + unregister_command(context, parent, name); + return NULL; + } } + + if (NULL != cr->jim_handler && NULL == parent) + Jim_CreateCommand(interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL); + return c; } @@ -882,7 +890,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) bool found = true; Jim_Obj *const *start; unsigned count; - if (c->handler) + if (c->handler || c->jim_handler) { // include the command name in the list count = remaining + 1; @@ -900,6 +908,12 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) start = argv; found = false; } + // pass the command through to the intended handler + if (c->jim_handler) + { + interp->cmdPrivData = c->jim_handler_data; + return (*c->jim_handler)(interp, count, start); + } unsigned nwords; const char **words = script_command_args_alloc(count, start, &nwords); @@ -1149,18 +1163,6 @@ void process_jim_events(void) #endif } -void register_jim(struct command_context *cmd_ctx, const char *name, - Jim_CmdProc cmd, const char *help) -{ - Jim_CreateCommand(interp, name, cmd, NULL, NULL); - - Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0); - Jim_ListAppendElement(interp, cmd_list, - Jim_NewStringObj(interp, name, -1)); - - help_add_command(cmd_ctx, NULL, name, help, NULL); -} - #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \ int parse##name(const char *str, type *ul) \ { \ diff --git a/src/helper/command.h b/src/helper/command.h index 2edeca9..84bdb71 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -164,6 +164,8 @@ struct command struct command *parent; struct command *children; command_handler_t handler; + Jim_CmdProc jim_handler; + void *jim_handler_data; enum command_mode mode; struct command *next; }; @@ -198,6 +200,8 @@ char *command_name(struct command *c, char delim); struct command_registration { const char *name; command_handler_t handler; + Jim_CmdProc jim_handler; + void *jim_handler_data; enum command_mode mode; const char *help; /// a string listing the options and arguments, required or optional @@ -319,9 +323,6 @@ void process_jim_events(void); extern Jim_Interp *interp; -void register_jim(struct command_context *context, const char *name, - Jim_CmdProc cmd, const char *help); - int parse_ulong(const char *str, unsigned long *ul); int parse_ullong(const char *str, unsigned long long *ul); diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 58521ee..e13f590 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -685,27 +685,51 @@ static const struct command_registration ioutil_command_handlers[] = { .mode = COMMAND_ANY, .help = "display available ram memory", }, + // jim handlers + { + .name = "rm", + .mode = COMMAND_ANY, + .jim_handler = &zylinjtag_Jim_Command_rm, + .help = "remove a file", + .usage = "<file>", + }, + { + .name = "peek", + .mode = COMMAND_ANY, + .jim_handler = &zylinjtag_Jim_Command_peek, + .help = "peek at a memory address", + .usage = "<addr>", + }, + { + .name = "poke", + .mode = COMMAND_ANY, + .jim_handler = &zylinjtag_Jim_Command_poke, + .help = "poke at a memory address", + .usage = "<addr> <value>", + }, + { + .name = "ls", + .mode = COMMAND_ANY, + .jim_handler = &zylinjtag_Jim_Command_ls, + .help = "show a listing of files", + .usage = "<dir>", + }, + { + .name = "mac", + .mode = COMMAND_ANY, + .jim_handler = &zylinjtag_Jim_Command_mac, + .help = "show MAC address", + }, + { + .name = "ip", + .jim_handler = &zylinjtag_Jim_Command_ip, + .mode = COMMAND_ANY, + .help = "show IP address", + }, COMMAND_REGISTRATION_DONE }; - int ioutil_init(str... [truncated message content] |
From: Zach W. <zw...@us...> - 2009-11-25 19:57:58
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via f74e2e033a2ad082e5bef67d0ddedd1db3f58300 (commit) via 66ee303456910f684244a20a0ac2e958d40b78cb (commit) via 144e3678bd2d518388b6c2d7f3d2a912a9ac2abd (commit) via 8a41656391bd8eb6854c8573920d1155d815966b (commit) via 5f6962b34f623e7daf0dfb1f6249620431b5ab79 (commit) via 4e67912fb01a0ab60c246c12c7ce50e361dd3e20 (commit) via c3800b5e674be3a9e1c7976925f9cfc52cba3ad5 (commit) via a17caa387c0fb08ee2604e066b436d90d9cf0a2f (commit) via dd063d99147ff08ad817fc3fbd306425b6933d8d (commit) via 8161fd3163142f828a0bd79e0b5ad339dc4aec6b (commit) via 97fbd793b3a4edec490b2b034f7b6fe5261ca03e (commit) via 28300bbf6ff726fe1ab807fa9796241bb3348cfd (commit) via df95fe25a4f01db9e131272ee72ebbf328ede428 (commit) via d79176e1bc4699a52663b87dc52f02fb7afa3d54 (commit) via 84c03168a54549e2a102ceb25219ac8a2281d954 (commit) via d1eca9a74c7c57ba6a3210c51b2a10cc5adb22e1 (commit) via 69908ddbd04fc9382d02819e296bb4384ef78810 (commit) via 11061486b5e18b43cca6a94bdd9e998d5dde44c4 (commit) via 509fe82b07df4a7e6217bfde37374e90262aa2de (commit) via e232dea176cc8c831e77a10903120ff057337f6c (commit) via e905fe6e756453daf27cd064285aa9cddf31b1ef (commit) via b40f265f9cb9e6be4c979e7f4e10072822dcb5c7 (commit) from 90d09e35e4be6f0b35899238b253154249f85cb6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f74e2e033a2ad082e5bef67d0ddedd1db3f58300 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 08:24:02 2009 -0800 remove register_commands from etm_capture_driver Converts callback to an array of command_registration records. Moves oocd_trace driver definition to end of file to eliminate useless forward declaration. diff --git a/src/target/etb.c b/src/target/etb.c index 63dee18..bc0e1bf 100644 --- a/src/target/etb.c +++ b/src/target/etb.c @@ -421,11 +421,6 @@ static const struct command_registration etb_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int etb_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, etb_command_handlers); -} - static int etb_init(struct etm_context *etm_ctx) { struct etb *etb = etm_ctx->capture_driver_priv; @@ -696,7 +691,7 @@ static int etb_stop_capture(struct etm_context *etm_ctx) struct etm_capture_driver etb_capture_driver = { .name = "etb", - .register_commands = etb_register_commands, + .commands = etb_command_handlers, .init = etb_init, .status = etb_status, .start_capture = etb_start_capture, diff --git a/src/target/etm.c b/src/target/etm.c index 2465d5c..4e7f917 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -1471,8 +1471,9 @@ COMMAND_HANDLER(handle_etm_config_command) { if (strcmp(CMD_ARGV[4], etm_capture_drivers[i]->name) == 0) { - int retval; - if ((retval = etm_capture_drivers[i]->register_commands(CMD_CTX)) != ERROR_OK) + int retval = register_commands(CMD_CTX, NULL, + etm_capture_drivers[i]->commands); + if (ERROR_OK != retval) { free(etm_ctx); return retval; diff --git a/src/target/etm.h b/src/target/etm.h index 05e5495..c8da794 100644 --- a/src/target/etm.h +++ b/src/target/etm.h @@ -126,7 +126,7 @@ struct etm_context; struct etm_capture_driver { char *name; - int (*register_commands)(struct command_context *cmd_ctx); + const struct command_registration *commands; int (*init)(struct etm_context *etm_ctx); trace_status_t (*status)(struct etm_context *etm_ctx); int (*read_trace)(struct etm_context *etm_ctx); diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c index 27a8eec..647774f 100644 --- a/src/target/etm_dummy.c +++ b/src/target/etm_dummy.c @@ -77,11 +77,6 @@ static const struct command_registration etm_dummy_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int etm_dummy_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, etm_dummy_command_handlers); -} - static int etm_dummy_init(struct etm_context *etm_ctx) { return ERROR_OK; @@ -110,7 +105,7 @@ static int etm_dummy_stop_capture(struct etm_context *etm_ctx) struct etm_capture_driver etm_dummy_capture_driver = { .name = "dummy", - .register_commands = etm_dummy_register_commands, + .commands = etm_dummy_command_handlers, .init = etm_dummy_init, .status = etm_dummy_status, .start_capture = etm_dummy_start_capture, diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c index a34c63c..ac79f18 100644 --- a/src/target/oocd_trace.c +++ b/src/target/oocd_trace.c @@ -30,8 +30,6 @@ */ -static int oocd_trace_register_commands(struct command_context *cmd_ctx); - static int oocd_trace_read_reg(struct oocd_trace *oocd_trace, int reg, uint32_t *value) { size_t bytes_written, bytes_read, bytes_to_read; @@ -278,17 +276,6 @@ static int oocd_trace_stop_capture(struct etm_context *etm_ctx) return ERROR_OK; } -struct etm_capture_driver oocd_trace_capture_driver = -{ - .name = "oocd_trace", - .register_commands = oocd_trace_register_commands, - .init = oocd_trace_init, - .status = oocd_trace_status, - .start_capture = oocd_trace_start_capture, - .stop_capture = oocd_trace_stop_capture, - .read_trace = oocd_trace_read_trace, -}; - COMMAND_HANDLER(handle_oocd_trace_config_command) { struct target *target; @@ -438,7 +425,15 @@ static const struct command_registration oocd_trace_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int oocd_trace_register_commands(struct command_context *cmd_ctx) +struct etm_capture_driver oocd_trace_capture_driver = { - return register_commands(cmd_ctx, NULL, oocd_trace_command_handlers); -} + .name = "oocd_trace", + .commands = oocd_trace_command_handlers, + .init = oocd_trace_init, + .status = oocd_trace_status, + .start_capture = oocd_trace_start_capture, + .stop_capture = oocd_trace_stop_capture, + .read_trace = oocd_trace_read_trace, +}; + + commit 66ee303456910f684244a20a0ac2e958d40b78cb Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 08:17:01 2009 -0800 remove target_type register_command callback Uses chaining of command_registration structures to eliminate all target_type register_callback routines. Exports the command_handler registration arrays for those target types that are used by others. diff --git a/src/target/arm11.c b/src/target/arm11.c index 835234c..7c6d39c 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -1617,6 +1617,12 @@ static const struct command_registration arm11_any_command_handlers[] = { }; static const struct command_registration arm11_command_handlers[] = { { + .chain = arm_command_handlers, + }, + { + .chain = etm_command_handlers, + }, + { .name = "arm11", .mode = COMMAND_ANY, .help = "ARM11 command group", @@ -1625,13 +1631,6 @@ static const struct command_registration arm11_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int arm11_register_commands(struct command_context *cmd_ctx) -{ - armv4_5_register_commands(cmd_ctx); - etm_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm11_command_handlers); -} - /** Holds methods for ARM11xx targets. */ struct target_type arm11_target = { .name = "arm11", @@ -1666,7 +1665,7 @@ struct target_type arm11_target = { .run_algorithm = armv4_5_run_algorithm, - .register_commands = arm11_register_commands, + .commands = arm11_command_handlers, .target_create = arm11_target_create, .init_target = arm11_init_target, .examine = arm11_examine, diff --git a/src/target/arm720t.c b/src/target/arm720t.c index 52a311c..bae2561 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -504,6 +504,9 @@ static const struct command_registration arm720t_exec_command_handlers[] = { static const struct command_registration arm720t_command_handlers[] = { { + .chain = arm7_9_command_handlers, + }, + { .name = "arm720t", .mode = COMMAND_ANY, .help = "arm720t command group", @@ -512,12 +515,6 @@ static const struct command_registration arm720t_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int arm720t_register_commands(struct command_context *cmd_ctx) -{ - arm7_9_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm720t_command_handlers); -} - /** Holds methods for ARM720 targets. */ struct target_type arm720t_target = { @@ -555,7 +552,7 @@ struct target_type arm720t_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm720t_register_commands, + .commands = arm720t_command_handlers, .target_create = arm720t_target_create, .init_target = arm720t_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index b40be8d..c4775e8 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2873,7 +2873,13 @@ static const struct command_registration arm7_9_any_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm7_9_command_handlers[] = { +const struct command_registration arm7_9_command_handlers[] = { + { + .chain = arm_command_handlers, + }, + { + .chain = etm_command_handlers, + }, { .name = "arm7_9", .mode = COMMAND_ANY, @@ -2882,10 +2888,3 @@ static const struct command_registration arm7_9_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; - -int arm7_9_register_commands(struct command_context *cmd_ctx) -{ - armv4_5_register_commands(cmd_ctx); - etm_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm7_9_command_handlers); -} diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 2f7132a..d43eaa6 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -120,7 +120,7 @@ static inline bool is_arm7_9(struct arm7_9_common *arm7_9) return arm7_9->common_magic == ARM7_9_COMMON_MAGIC; } -int arm7_9_register_commands(struct command_context *cmd_ctx); +extern const struct command_registration arm7_9_command_handlers[]; int arm7_9_poll(struct target *target); diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c index 742eace..7d14ed6 100644 --- a/src/target/arm7tdmi.c +++ b/src/target/arm7tdmi.c @@ -747,7 +747,7 @@ struct target_type arm7tdmi_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm7_9_register_commands, + .commands = arm7_9_command_handlers, .target_create = arm7tdmi_target_create, .init_target = arm7tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 1e6019c..e6c2eed 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -1396,7 +1396,10 @@ static const struct command_registration arm920t_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm920t_command_handlers[] = { +const struct command_registration arm920t_command_handlers[] = { + { + .chain = arm9tdmi_command_handlers, + }, { .name = "arm920t", .mode = COMMAND_ANY, @@ -1406,13 +1409,6 @@ static const struct command_registration arm920t_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -/** Registers commands to access coprocessor, cache, and MMU resources. */ -int arm920t_register_commands(struct command_context *cmd_ctx) -{ - arm9tdmi_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm920t_command_handlers); -} - /** Holds methods for ARM920 targets. */ struct target_type arm920t_target = { @@ -1452,7 +1448,7 @@ struct target_type arm920t_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm920t_register_commands, + .commands = arm920t_command_handlers, .target_create = arm920t_target_create, .init_target = arm9tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm920t.h b/src/target/arm920t.h index ca6be7e..a75f01a 100644 --- a/src/target/arm920t.h +++ b/src/target/arm920t.h @@ -71,6 +71,7 @@ void arm920t_disable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache); void arm920t_enable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache); -int arm920t_register_commands(struct command_context *cmd_ctx); + +extern const struct command_registration arm920t_command_handlers[]; #endif /* ARM920T_H */ diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 329aa12..408ede9 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -766,7 +766,10 @@ static const struct command_registration arm926ejs_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm926ejs_command_handlers[] = { +const struct command_registration arm926ejs_command_handlers[] = { + { + .chain = arm9tdmi_command_handlers, + }, { .name = "arm926ejs", .mode = COMMAND_ANY, @@ -776,13 +779,6 @@ static const struct command_registration arm926ejs_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -/** Registers commands to access coprocessor, cache, and debug resources. */ -int arm926ejs_register_commands(struct command_context *cmd_ctx) -{ - arm9tdmi_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm926ejs_command_handlers); -} - /** Holds methods for ARM926 targets. */ struct target_type arm926ejs_target = { @@ -817,7 +813,7 @@ struct target_type arm926ejs_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm926ejs_register_commands, + .commands = arm926ejs_command_handlers, .target_create = arm926ejs_target_create, .init_target = arm9tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm926ejs.h b/src/target/arm926ejs.h index 514f054..274733b 100644 --- a/src/target/arm926ejs.h +++ b/src/target/arm926ejs.h @@ -48,10 +48,11 @@ target_to_arm926(struct target *target) int arm926ejs_init_arch_info(struct target *target, struct arm926ejs_common *arm926ejs, struct jtag_tap *tap); -int arm926ejs_register_commands(struct command_context *cmd_ctx); int arm926ejs_arch_state(struct target *target); int arm926ejs_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); int arm926ejs_soft_reset_halt(struct target *target); +extern const struct command_registration arm926ejs_command_handlers[]; + #endif /* ARM926EJS_H */ diff --git a/src/target/arm966e.c b/src/target/arm966e.c index 70cc3c4..9fe513c 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -232,7 +232,10 @@ static const struct command_registration arm966e_exec_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm966e_command_handlers[] = { +const struct command_registration arm966e_command_handlers[] = { + { + .chain = arm9tdmi_command_handlers, + }, { .name = "arm966e", .mode = COMMAND_ANY, @@ -242,13 +245,6 @@ static const struct command_registration arm966e_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -/** Registers commands used to access coprocessor resources. */ -int arm966e_register_commands(struct command_context *cmd_ctx) -{ - arm9tdmi_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm966e_command_handlers); -} - /** Holds methods for ARM966 targets. */ struct target_type arm966e_target = { @@ -283,7 +279,7 @@ struct target_type arm966e_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm966e_register_commands, + .commands = arm966e_command_handlers, .target_create = arm966e_target_create, .init_target = arm9tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm966e.h b/src/target/arm966e.h index 45aeb4e..24dcec3 100644 --- a/src/target/arm966e.h +++ b/src/target/arm966e.h @@ -43,7 +43,8 @@ target_to_arm966(struct target *target) int arm966e_init_arch_info(struct target *target, struct arm966e_common *arm966e, struct jtag_tap *tap); -int arm966e_register_commands(struct command_context *cmd_ctx); int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value); +extern const struct command_registration arm966e_command_handlers[]; + #endif /* ARM966E_H */ diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 87ace05..7eb5641 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -917,7 +917,10 @@ static const struct command_registration arm9tdmi_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm9tdmi_command_handlers[] = { +const struct command_registration arm9tdmi_command_handlers[] = { + { + .chain = arm7_9_command_handlers, + }, { .name = "arm9tdmi", .mode = COMMAND_ANY, @@ -927,12 +930,6 @@ static const struct command_registration arm9tdmi_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int arm9tdmi_register_commands(struct command_context *cmd_ctx) -{ - arm7_9_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, arm9tdmi_command_handlers); -} - /** Holds methods for ARM9TDMI targets. */ struct target_type arm9tdmi_target = { @@ -967,7 +964,7 @@ struct target_type arm9tdmi_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm9tdmi_register_commands, + .commands = arm9tdmi_command_handlers, .target_create = arm9tdmi_target_create, .init_target = arm9tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/arm9tdmi.h b/src/target/arm9tdmi.h index 351b00a..aff9fc5 100644 --- a/src/target/arm9tdmi.h +++ b/src/target/arm9tdmi.h @@ -29,7 +29,7 @@ int arm9tdmi_init_target(struct command_context *cmd_ctx, struct target *target); int arm9tdmi_init_arch_info(struct target *target, struct arm7_9_common *arm7_9, struct jtag_tap *tap); -int arm9tdmi_register_commands(struct command_context *cmd_ctx); +extern const struct command_registration arm9tdmi_command_handlers[]; int arm9tdmi_clock_out(struct arm_jtag *jtag_info, uint32_t instr, uint32_t out, uint32_t *in, int sysspeed); diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index dfb7094..7e5bb0a 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -809,7 +809,7 @@ static const struct command_registration arm_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration arm_command_handlers[] = { +const struct command_registration arm_command_handlers[] = { { .name = "arm", .mode = COMMAND_ANY, @@ -819,11 +819,6 @@ static const struct command_registration arm_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int armv4_5_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, arm_command_handlers); -} - int armv4_5_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size) { struct arm *armv4_5 = target_to_armv4_5(target); diff --git a/src/target/armv4_5.h b/src/target/armv4_5.h index 7a6cb61..822d143 100644 --- a/src/target/armv4_5.h +++ b/src/target/armv4_5.h @@ -27,6 +27,8 @@ #define ARMV4_5_H #include "target.h" +#include "command.h" + typedef enum armv4_5_mode { @@ -155,7 +157,8 @@ int armv4_5_arch_state(struct target *target); int armv4_5_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size); -int armv4_5_register_commands(struct command_context *cmd_ctx); +extern const struct command_registration arm_command_handlers[]; + int armv4_5_init_arch_info(struct target *target, struct arm *armv4_5); int armv4_5_run_algorithm(struct target *target, diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 7cc2273..3d94329 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -181,7 +181,7 @@ static const struct command_registration armv7a_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration armv7a_command_handlers[] = { +const struct command_registration armv7a_command_handlers[] = { { .name = "dap", .mode = COMMAND_ANY, @@ -191,7 +191,3 @@ static const struct command_registration armv7a_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int armv7a_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, armv7a_command_handlers); -} diff --git a/src/target/armv7a.h b/src/target/armv7a.h index 942bf8b..f843f03 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -103,7 +103,8 @@ struct armv7a_core_reg int armv7a_arch_state(struct target *target); struct reg_cache *armv7a_build_reg_cache(struct target *target, struct armv7a_common *armv7a_common); -int armv7a_register_commands(struct command_context *cmd_ctx); int armv7a_init_arch_info(struct target *target, struct armv7a_common *armv7a); +extern const struct command_registration armv7a_command_handlers[]; + #endif /* ARMV4_5_H */ diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 6d8ad5f..9d89086 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -832,7 +832,7 @@ static const struct command_registration armv7m_exec_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration armv7m_command_handlers[] = { +const struct command_registration armv7m_command_handlers[] = { { .name = "dap", .mode = COMMAND_ANY, @@ -841,8 +841,3 @@ static const struct command_registration armv7m_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; - -int armv7m_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, armv7m_command_handlers); -} diff --git a/src/target/armv7m.h b/src/target/armv7m.h index 9dd4ddb..7299bdf 100644 --- a/src/target/armv7m.h +++ b/src/target/armv7m.h @@ -143,7 +143,6 @@ int armv7m_arch_state(struct target *target); int armv7m_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size); -int armv7m_register_commands(struct command_context *cmd_ctx); int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m); int armv7m_run_algorithm(struct target *target, @@ -161,6 +160,8 @@ int armv7m_checksum_memory(struct target *target, int armv7m_blank_check_memory(struct target *target, uint32_t address, uint32_t count, uint32_t* blank); +extern const struct command_registration armv7m_command_handlers[]; + /* Thumb mode instructions */ diff --git a/src/target/avrt.c b/src/target/avrt.c index cabb272..dc527f5 100644 --- a/src/target/avrt.c +++ b/src/target/avrt.c @@ -28,9 +28,6 @@ #define AVR_JTAG_INS_LEN 4 -/* cli handling */ -int avr_register_commands(struct command_context *cmd_ctx); - /* forward declarations */ int avr_target_create(struct target *target, Jim_Interp *interp); int avr_init_target(struct command_context *cmd_ctx, struct target *target); @@ -91,17 +88,10 @@ struct target_type avr_target = .add_watchpoint = avr_add_watchpoint, .remove_watchpoint = avr_remove_watchpoint, */ - .register_commands = avr_register_commands, .target_create = avr_target_create, .init_target = avr_init_target, }; -int avr_register_commands(struct command_context *cmd_ctx) -{ - LOG_DEBUG("%s", __FUNCTION__); - return ERROR_OK; -} - int avr_target_create(struct target *target, Jim_Interp *interp) { struct avr_common *avr = calloc(1, sizeof(struct avr_common)); diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index 325a54b..b85481a 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -1642,6 +1642,12 @@ static const struct command_registration cortex_a8_exec_command_handlers[] = { }; static const struct command_registration cortex_a8_command_handlers[] = { { + .chain = arm_command_handlers, + }, + { + .chain = armv7a_command_handlers, + }, + { .name = "cortex_a8", .mode = COMMAND_ANY, .help = "Cortex-A8 command group", @@ -1650,13 +1656,6 @@ static const struct command_registration cortex_a8_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int cortex_a8_register_commands(struct command_context *cmd_ctx) -{ - armv4_5_register_commands(cmd_ctx); - armv7a_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, cortex_a8_command_handlers); -} - struct target_type cortexa8_target = { .name = "cortex_a8", @@ -1689,7 +1688,7 @@ struct target_type cortexa8_target = { .add_watchpoint = NULL, .remove_watchpoint = NULL, - .register_commands = cortex_a8_register_commands, + .commands = cortex_a8_command_handlers, .target_create = cortex_a8_target_create, .init_target = cortex_a8_init_target, .examine = cortex_a8_examine, diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index be81af9..7cfe540 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -1938,6 +1938,12 @@ static const struct command_registration cortex_m3_exec_command_handlers[] = { }; static const struct command_registration cortex_m3_command_handlers[] = { { + .chain = arm_command_handlers, + }, + { + .chain = armv7m_command_handlers, + }, + { .name = "cortex_m3", .mode = COMMAND_ANY, .help = "Cortex-M3 command group", @@ -1946,12 +1952,6 @@ static const struct command_registration cortex_m3_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int cortex_m3_register_commands(struct command_context *cmd_ctx) -{ - armv7m_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, cortex_m3_command_handlers); -} - struct target_type cortexm3_target = { .name = "cortex_m3", @@ -1984,7 +1984,7 @@ struct target_type cortexm3_target = .add_watchpoint = cortex_m3_add_watchpoint, .remove_watchpoint = cortex_m3_remove_watchpoint, - .register_commands = cortex_m3_register_commands, + .commands = cortex_m3_command_handlers, .target_create = cortex_m3_target_create, .init_target = cortex_m3_init_target, .examine = cortex_m3_examine, diff --git a/src/target/etm.c b/src/target/etm.c index 0f7b41e..2465d5c 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -2103,7 +2103,7 @@ static const struct command_registration etm_config_command_handlers[] = { }, COMMAND_REGISTRATION_DONE }; -static const struct command_registration etm_command_handlers[] = { +const struct command_registration etm_command_handlers[] = { { .name = "etm", .mode = COMMAND_ANY, @@ -2113,11 +2113,6 @@ static const struct command_registration etm_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int etm_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, etm_command_handlers); -} - static const struct command_registration etm_exec_command_handlers[] = { { .name = "tracemode", handle_etm_tracemode_command, diff --git a/src/target/etm.h b/src/target/etm.h index b74c6d9..05e5495 100644 --- a/src/target/etm.h +++ b/src/target/etm.h @@ -212,7 +212,7 @@ struct reg_cache* etm_build_reg_cache(struct target *target, int etm_setup(struct target *target); -int etm_register_commands(struct command_context *cmd_ctx); +extern const struct command_registration etm_command_handlers[]; #define ERROR_ETM_INVALID_DRIVER (-1300) #define ERROR_ETM_PORTMODE_NOT_SUPPORTED (-1301) diff --git a/src/target/fa526.c b/src/target/fa526.c index 9c22a75..32469d0 100644 --- a/src/target/fa526.c +++ b/src/target/fa526.c @@ -385,7 +385,7 @@ struct target_type fa526_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm920t_register_commands, + .commands = arm920t_command_handlers, .target_create = fa526_target_create, .init_target = arm9tdmi_init_target, .examine = arm7_9_examine, diff --git a/src/target/feroceon.c b/src/target/feroceon.c index 8c05276..432d49d 100644 --- a/src/target/feroceon.c +++ b/src/target/feroceon.c @@ -709,7 +709,7 @@ struct target_type feroceon_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm926ejs_register_commands, + .commands = arm926ejs_command_handlers, .target_create = feroceon_target_create, .init_target = feroceon_init_target, .examine = feroceon_examine, @@ -748,7 +748,7 @@ struct target_type dragonite_target = .add_watchpoint = arm7_9_add_watchpoint, .remove_watchpoint = arm7_9_remove_watchpoint, - .register_commands = arm966e_register_commands, + .commands = arm966e_command_handlers, .target_create = dragonite_target_create, .init_target = feroceon_init_target, .examine = feroceon_examine, diff --git a/src/target/mips32.c b/src/target/mips32.c index 0b8ebb4..48d0720 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -320,11 +320,6 @@ int mips32_init_arch_info(struct target *target, struct mips32_common *mips32, s return ERROR_OK; } -int mips32_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - int mips32_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info) { /*TODO*/ diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 0a566c3..a83217f 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -41,7 +41,6 @@ int mips_m4k_resume(struct target *target, int current, uint32_t address, int ha int mips_m4k_step(struct target *target, int current, uint32_t address, int handle_breakpoints); int mips_m4k_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); int mips_m4k_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); -int mips_m4k_register_commands(struct command_context *cmd_ctx); int mips_m4k_init_target(struct command_context *cmd_ctx, struct target *target); int mips_m4k_target_create(struct target *target, Jim_Interp *interp); @@ -82,7 +81,6 @@ struct target_type mips_m4k_target = .add_watchpoint = mips_m4k_add_watchpoint, .remove_watchpoint = mips_m4k_remove_watchpoint, - .register_commands = mips_m4k_register_commands, .target_create = mips_m4k_target_create, .init_target = mips_m4k_init_target, .examine = mips_m4k_examine, @@ -902,14 +900,6 @@ int mips_m4k_write_memory(struct target *target, uint32_t address, uint32_t size return mips32_dmaacc_write_mem(ejtag_info, address, size, count, (void *)buffer); } -int mips_m4k_register_commands(struct command_context *cmd_ctx) -{ - int retval; - - retval = mips32_register_commands(cmd_ctx); - return retval; -} - int mips_m4k_init_target(struct command_context *cmd_ctx, struct target *target) { mips32_build_reg_cache(target); diff --git a/src/target/target.c b/src/target/target.c index 6f48808..e999e68 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4353,9 +4353,14 @@ static int target_create(Jim_GetOptInfo *goi) if (!target->variant) target->variant = strdup(""); + cp = Jim_GetString(new_cmd, NULL); + target->cmd_name = strdup(cp); + /* create the target specific commands */ - if (target->type->register_commands) { - (*(target->type->register_commands))(cmd_ctx); + if (target->type->commands) { + e = register_commands(cmd_ctx, NULL, target->type->commands); + if (ERROR_OK != e) + LOG_ERROR("unable to register '%s' commands", cp); } if (target->type->target_create) { (*(target->type->target_create))(target, goi->interp); @@ -4371,9 +4376,6 @@ static int target_create(Jim_GetOptInfo *goi) *tpp = target; } - cp = Jim_GetString(new_cmd, NULL); - target->cmd_name = strdup(cp); - /* now - create the new target name command */ e = Jim_CreateCommand(goi->interp, /* name */ diff --git a/src/target/target_type.h b/src/target/target_type.h index aa87a74..9a0709d 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -148,7 +148,7 @@ struct target_type */ int (*run_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info); - int (*register_commands)(struct command_context *cmd_ctx); + const struct command_registration *commands; /* called when target is created */ int (*target_create)(struct target *target, Jim_Interp *interp); diff --git a/src/target/xscale.c b/src/target/xscale.c index 965ac52..e402a11 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3653,6 +3653,9 @@ static const struct command_registration xscale_any_command_handlers[] = { }; static const struct command_registration xscale_command_handlers[] = { { + .chain = arm_command_handlers, + }, + { .name = "xscale", .mode = COMMAND_ANY, .help = "xscale command group", @@ -3661,14 +3664,6 @@ static const struct command_registration xscale_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int xscale_register_commands(struct command_context *cmd_ctx) -{ - - armv4_5_register_commands(cmd_ctx); - - return ERROR_OK; -} - struct target_type xscale_target = { .name = "xscale", @@ -3702,7 +3697,7 @@ struct target_type xscale_target = .add_watchpoint = xscale_add_watchpoint, .remove_watchpoint = xscale_remove_watchpoint, - .register_commands = xscale_register_commands, + .commands = xscale_command_handlers, .target_create = xscale_target_create, .init_target = xscale_init_target, commit 144e3678bd2d518388b6c2d7f3d2a912a9ac2abd Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 xscale: use register_commands() diff --git a/src/target/xscale.c b/src/target/xscale.c index c2b3493..965ac52 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3554,31 +3554,115 @@ COMMAND_HANDLER(xscale_handle_cp15) return ERROR_OK; } +static const struct command_registration xscale_exec_command_handlers[] = { + { + .name = "cache_info", + .handler = &xscale_handle_cache_info_command, + .mode = COMMAND_EXEC, NULL, + }, + + { + .name = "mmu", + .handler = &xscale_handle_mmu_command, + .mode = COMMAND_EXEC, + .usage = "[enable|disable]", + .help = "enable or disable the MMU", + }, + { + .name = "icache", + .handler = &xscale_handle_idcache_command, + .mode = COMMAND_EXEC, + .usage = "[enable|disable]", + .help = "enable or disable the ICache", + }, + { + .name = "dcache", + .handler = &xscale_handle_idcache_command, + .mode = COMMAND_EXEC, + .usage = "[enable|disable]", + .help = "enable or disable the DCache", + }, + + { + .name = "vector_catch", + .handler = &xscale_handle_vector_catch_command, + .mode = COMMAND_EXEC, + .help = "mask of vectors that should be caught", + .usage = "[<mask>]", + }, + { + .name = "vector_table", + .handler = &xscale_handle_vector_table_command, + .mode = COMMAND_EXEC, + .usage = "<high|low> <index> <code>", + .help = "set static code for exception handler entry", + }, + + { + .name = "trace_buffer", + .handler = &xscale_handle_trace_buffer_command, + .mode = COMMAND_EXEC, + .usage = "<enable | disable> [fill [n]|wrap]", + }, + { + .name = "dump_trace", + .handler = &xscale_handle_dump_trace_command, + .mode = COMMAND_EXEC, + .help = "dump content of trace buffer to <file>", + .usage = "<file>", + }, + { + .name = "analyze_trace", + .handler = &xscale_handle_analyze_trace_buffer_command, + .mode = COMMAND_EXEC, + .help = "analyze content of trace buffer", + }, + { + .name = "trace_image", + .handler = &xscale_handle_trace_image_command, + COMMAND_EXEC, + .help = "load image from <file> [base address]", + .usage = "<file> [address] [type]", + }, + + { + .name = "cp15", + .handler = &xscale_handle_cp15, + .mode = COMMAND_EXEC, + .help = "access coproc 15", + .usage = "<register> [value]", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration xscale_any_command_handlers[] = { + { + .name = "debug_handler", + .handler = &xscale_handle_debug_handler_command, + .mode = COMMAND_ANY, + .usage = "<target#> <address>", + }, + { + .name = "cache_clean_address", + .handler = &xscale_handle_cache_clean_address_command, + .mode = COMMAND_ANY, + }, + { + .chain = xscale_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration xscale_command_handlers[] = { + { + .name = "xscale", + .mode = COMMAND_ANY, + .help = "xscale command group", + .chain = xscale_any_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int xscale_register_commands(struct command_context *cmd_ctx) { - struct command *xscale_cmd; - - xscale_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "xscale", NULL, COMMAND_ANY, "xscale specific commands"); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "debug_handler", xscale_handle_debug_handler_command, COMMAND_ANY, "'xscale debug_handler <target#> <address>' command takes two required operands"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "cache_clean_address", xscale_handle_cache_clean_address_command, COMMAND_ANY, NULL); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "cache_info", xscale_handle_cache_info_command, COMMAND_EXEC, NULL); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "mmu", xscale_handle_mmu_command, COMMAND_EXEC, "['enable'|'disable'] the MMU"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "icache", xscale_handle_idcache_command, COMMAND_EXEC, "['enable'|'disable'] the ICache"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "dcache", xscale_handle_idcache_command, COMMAND_EXEC, "['enable'|'disable'] the DCache"); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "vector_catch", xscale_handle_vector_catch_command, COMMAND_EXEC, "<mask> of vectors that should be catched"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "vector_table", xscale_handle_vector_table_command, COMMAND_EXEC, "<high|low> <index> <code> set static code for exception handler entry"); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "trace_buffer", xscale_handle_trace_buffer_command, COMMAND_EXEC, "<enable | disable> ['fill' [n]|'wrap']"); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "dump_trace", xscale_handle_dump_trace_command, COMMAND_EXEC, "dump content of trace buffer to <file>"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "analyze_trace", xscale_handle_analyze_trace_buffer_command, COMMAND_EXEC, "analyze content of trace buffer"); - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "trace_image", xscale_handle_trace_image_command, - COMMAND_EXEC, "load image from <file> [base address]"); - - COMMAND_REGISTER(cmd_ctx, xscale_cmd, "cp15", xscale_handle_cp15, COMMAND_EXEC, "access coproc 15 <register> [value]"); armv4_5_register_commands(cmd_ctx); commit 8a41656391bd8eb6854c8573920d1155d815966b Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 trace: use register_commands() diff --git a/src/target/trace.c b/src/target/trace.c index c3897a0..f257592 100644 --- a/src/target/trace.c +++ b/src/target/trace.c @@ -156,16 +156,35 @@ COMMAND_HANDLER(handle_trace_history_command) return ERROR_OK; } +static const struct command_registration trace_exec_command_handlers[] = { + { + .name = "history", + .handler = &handle_trace_history_command, + .mode = COMMAND_EXEC, + .help = "display trace history, clear history or set [size]", + .usage = "[clear|<size>]", + }, + { + .name = "point", + .handler = &handle_trace_point_command, + .mode = COMMAND_EXEC, + .help = "display trace points, clear list of trace points, " + "or add new tracepoint at [address]", + .usage = "[clear|<address>]", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration trace_command_handlers[] = { + { + .name = "trace", + .mode = COMMAND_ANY, + .help = "trace command group", + .chain = trace_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int trace_register_commands(struct command_context *cmd_ctx) { - struct command *trace_cmd = - COMMAND_REGISTER(cmd_ctx, NULL, "trace", NULL, COMMAND_ANY, "trace commands"); - - COMMAND_REGISTER(cmd_ctx, trace_cmd, "history", handle_trace_history_command, - COMMAND_EXEC, "display trace history, ['clear'] history or set [size]"); - - COMMAND_REGISTER(cmd_ctx, trace_cmd, "point", handle_trace_point_command, - COMMAND_EXEC, "display trace points, ['clear'] list of trace points, or add new tracepoint at [address]"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, trace_command_handlers); } commit 5f6962b34f623e7daf0dfb1f6249620431b5ab79 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 target_request: use register_commands() diff --git a/src/target/target_request.c b/src/target/target_request.c index a02e2c1..9e78178 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -35,7 +35,6 @@ #include "log.h" -static struct command *target_request_cmd = NULL; static int charmsg_mode = 0; static int target_asciimsg(struct target *target, uint32_t length) @@ -300,13 +299,27 @@ COMMAND_HANDLER(handle_target_request_debugmsgs_command) return ERROR_OK; } +static const struct command_registration target_req_exec_command_handlers[] = { + { + .name = "debugmsgs", + .handler = &handle_target_request_debugmsgs_command, + .mode = COMMAND_EXEC, + .help = "set reception of debug messages from target", + .usage = "(enable|disable)", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration target_req_command_handlers[] = { + { + .name = "target_request", + .mode = COMMAND_ANY, + .help = "target request command group", + .chain = target_req_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int target_request_register_commands(struct command_context *cmd_ctx) { - target_request_cmd = - COMMAND_REGISTER(cmd_ctx, NULL, "target_request", NULL, COMMAND_ANY, "target_request commands"); - - COMMAND_REGISTER(cmd_ctx, target_request_cmd, "debugmsgs", handle_target_request_debugmsgs_command, - COMMAND_EXEC, "enable/disable reception of debug messages from target"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, target_req_command_handlers); } commit 4e67912fb01a0ab60c246c12c7ce50e361dd3e20 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 target: use register_commands() diff --git a/src/target/target.c b/src/target/target.c index 2e93382..6f48808 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4762,19 +4762,211 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } +static const struct command_registration target_command_handlers[] = { + { + .name = "targets", + .handler = &handle_targets_command, + .mode = COMMAND_ANY, + .help = "change current command line target (one parameter) " + "or list targets (no parameters)", + .usage = "[<new_current_target>]", + }, + COMMAND_REGISTRATION_DONE +}; + int target_register_commands(struct command_context *cmd_ctx) { - - COMMAND_REGISTER(cmd_ctx, NULL, "targets", - handle_targets_command, COMMAND_EXEC, - "change current command line target (one parameter) " - "or list targets (no parameters)"); - register_jim(cmd_ctx, "target", jim_target, "configure target"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, target_command_handlers); } +static const struct command_registration target_exec_command_handlers[] = { + { + .name = "fast_load_image", + .handler = &handle_fast_load_image_command, + .mode = COMMAND_ANY, + .help = "Load image into memory, mainly for profiling purposes", + .usage = "<file> <address> ['bin'|'ihex'|'elf'|'s19'] " + "[min_address] [max_length]", + }, + { + .name = "fast_load", + .handler = &handle_fast_load_command, + .mode = COMMAND_ANY, + .help = "loads active fast load image to current target " + "- mainly for profiling purposes", + }, + { + .name = "profile", + .handler = &handle_profile_command, + .mode = COMMAND_EXEC, + .help = "profiling samples the CPU PC", + }, + /** @todo don't register virt2phys() unless target supports it */ + { + .name = "virt2phys", + .handler = &handle_virt2phys_command, + .mode = COMMAND_ANY, + .help = "translate a virtual address into a physical address", + }, + + { + .name = "reg", + .handler = &handle_reg_command, + .mode = COMMAND_EXEC, + .help = "display or set a register", + }, + + { + .name = "poll", + .handler = &handle_poll_command, + .mode = COMMAND_EXEC, + .help = "poll target state", + }, + { + .name = "wait_halt", + .handler = &handle_wait_halt_command, + .mode = COMMAND_EXEC, + .help = "wait for target halt", + .usage = "[time (s)]", + }, + { + .name = "halt", + .handler = &handle_halt_command, + .mode = COMMAND_EXEC, + .help = "halt target", + }, + { + .name = "resume", + .handler = &handle_resume_command, + .mode = COMMAND_EXEC, + .help = "resume target", + .usage = "[<address>]", + }, + { + .name = "reset", + .handler = &handle_reset_command, + .mode = COMMAND_EXEC, + .usage = "[run|halt|init]", + .help = "Reset all targets into the specified mode." + "Default reset mode is run, if not given.", + }, + { + .name = "soft_reset_halt", + .handler = &handle_soft_reset_halt_command, + .mode = COMMAND_EXEC, + .help = "halt the target and do a soft reset", + }, + { + + .name = "step", + .handler = &handle_step_command, + .mode = COMMAND_EXEC, + .help = "step one instruction from current PC or [addr]", + .usage = "[<address>]", + }, + { + + .name = "mdw", + .handler = &handle_md_command, + .mode = COMMAND_EXEC, + .help = "display memory words", + .usage = "[phys] <addr> [count]", + }, + { + .name = "mdh", + .handler = &handle_md_command, + .mode = COMMAND_EXEC, + .help = "display memory half-words", + .usage = "[phys] <addr> [count]", + }, + { + .name = "mdb", + .handler = &handle_md_command, + .mode = COMMAND_EXEC, + .help = "display memory bytes", + .usage = "[phys] <addr> [count]", + }, + { + + .name = "mww", + .handler = &handle_mw_command, + .mode = COMMAND_EXEC, + .help = "write memory word", + .usage = "[phys] <addr> <value> [count]", + }, + { + .name = "mwh", + .handler = &handle_mw_command, + .mode = COMMAND_EXEC, + .help = "write memory half-word", + .usage = "[phys] <addr> <value> [count]", + }, + { + .name = "mwb", + .handler = &handle_mw_command, + .mode = COMMAND_EXEC, + .help = "write memory byte", + .usage = "[phys] <addr> <value> [count]", + }, + { + + .name = "bp", + .handler = &handle_bp_command, + .mode = COMMAND_EXEC, + .help = "list or set breakpoint", + .usage = "[<address> <length> [hw]]", + }, + { + .name = "rbp", + .handler = &handle_rbp_command, + .mode = COMMAND_EXEC, + .help = "remove breakpoint", + .usage = "<address>", + }, + { + + .name = "wp", + .handler = &handle_wp_command, + .mode = COMMAND_EXEC, + .help = "list or set watchpoint", + .usage = "[<address> <length> <r/w/a> [value] [mask]]", + }, + { + .name = "rwp", + .handler = &handle_rwp_command, + .mode = COMMAND_EXEC, + .help = "remove watchpoint", + .usage = "<address>", + + }, + { + .name = "load_image", + .handler = &handle_load_image_command, + .mode = COMMAND_EXEC, + .usage = "<file> <address> ['bin'|'ihex'|'elf'|'s19'] " + "[min_address] [max_length]", + }, + { + .name = "dump_image", + .handler = &handle_dump_image_command, + .mode = COMMAND_EXEC, + .usage = "<file> <address> <size>", + }, + { + .name = "verify_image", + .handler = &handle_verify_image_command, + .mode = COMMAND_EXEC, + .usage = "<file> [offset] [type]", + }, + { + .name = "test_image", + .handler = &handle_test_image_command, + .mode = COMMAND_EXEC, + .usage = "<file> [offset] [type]", + }, + COMMAND_REGISTRATION_DONE +}; int target_register_user_commands(struct command_context *cmd_ctx) { int retval = ERROR_OK; @@ -4784,10 +4976,6 @@ int target_register_user_commands(struct command_context *cmd_ctx) if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK) return retval; - COMMAND_REGISTER(cmd_ctx, NULL, "profile", - handle_profile_command, COMMAND_EXEC, - "profiling samples the CPU PC"); - register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing " "<ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>"); @@ -4796,96 +4984,5 @@ int target_register_user_commands(struct command_context *cmd_ctx) "convert a TCL array to memory locations and write the values " "<ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>"); - COMMAND_REGISTER(cmd_ctx, NULL, "fast_load_image", - handle_fast_load_image_command, COMMAND_ANY, - "same CMD_ARGV as load_image, image stored in memory " - "- mainly for profiling purposes"); - - COMMAND_REGISTER(cmd_ctx, NULL, "fast_load", - handle_fast_load_command, COMMAND_ANY, - "loads active fast load image to current target " - "- mainly for profiling purposes"); - - /** @todo don't register virt2phys() unless target supports it */ - COMMAND_REGISTER(cmd_ctx, NULL, "virt2phys", - handle_virt2phys_command, COMMAND_ANY, - "translate a virtual address into a physical address"); - - COMMAND_REGISTER(cmd_ctx, NULL, "reg", - handle_reg_command, COMMAND_EXEC, - "display or set a register"); - - COMMAND_REGISTER(cmd_ctx, NULL, "poll", - handle_poll_command, COMMAND_EXEC, - "poll target state"); - COMMAND_REGISTER(cmd_ctx, NULL, "wait_halt", - handle_wait_halt_command, COMMAND_EXEC, - "wait for target halt [time (s)]"); - COMMAND_REGISTER(cmd_ctx, NULL, "halt", - handle_halt_command, COMMAND_EXEC, - "halt target"); - COMMAND_REGISTER(cmd_ctx, NULL, "resume", - handle_resume_command, COMMAND_EXEC, - "resume target [addr]"); - COMMAND_REGISTER(cmd_ctx, NULL, "reset", - handle_reset_command, COMMAND_EXEC, - "reset target [run | halt | init] - default is run"); - COMMAND_REGISTER(cmd_ctx, NULL, "soft_reset_halt", - handle_soft_reset_halt_command, COMMAND_EXEC, - "halt the target and do a soft reset"); - - COMMAND_REGISTER(cmd_ctx, NULL, "step", - handle_step_command, COMMAND_EXEC, - "step one instruction from current PC or [addr]"); - - COMMAND_REGISTER(cmd_ctx, NULL, "mdw", - handle_md_command, COMMAND_EXEC, - "display memory words [phys] <addr> [count]"); - COMMAND_REGISTER(cmd_ctx, NULL, "mdh", - handle_md_command, COMMAND_EXEC, - "display memory half-words [phys] <addr> [count]"); - COMMAND_REGISTER(cmd_ctx, NULL, "mdb", - handle_md_command, COMMAND_EXEC, - "display memory bytes [phys] <addr> [count]"); - - COMMAND_REGISTER(cmd_ctx, NULL, "mww", - handle_mw_command, COMMAND_EXEC, - "write memory word [phys] <addr> <value> [count]"); - COMMAND_REGISTER(cmd_ctx, NULL, "mwh", - handle_mw_command, COMMAND_EXEC, - "write memory half-word [phys] <addr> <value> [count]"); - COMMAND_REGISTER(cmd_ctx, NULL, "mwb", - handle_mw_command, COMMAND_EXEC, - "write memory byte [phys] <addr> <value> [count]"); - - COMMAND_REGISTER(cmd_ctx, NULL, "bp", - handle_bp_command, COMMAND_EXEC, - "list or set breakpoint [<address> <length> [hw]]"); - COMMAND_REGISTER(cmd_ctx, NULL, "rbp", - handle_rbp_command, COMMAND_EXEC, - "remove breakpoint <address>"); - - COMMAND_REGISTER(cmd_ctx, NULL, "wp", - handle_wp_command, COMMAND_EXEC, - "list or set watchpoint " - "[<address> <length> <r/w/a> [value] [mask]]"); - COMMAND_REGISTER(cmd_ctx, NULL, "rwp", - handle_rwp_command, COMMAND_EXEC, - "remove watchpoint <address>"); - - COMMAND_REGISTER(cmd_ctx, NULL, "load_image", - handle_load_image_command, COMMAND_EXEC, - "load_image <file> <address> " - "['bin'|'ihex'|'elf'|'s19'] [min_address] [max_length]"); - COMMAND_REGISTER(cmd_ctx, NULL, "dump_image", - handle_dump_image_command, COMMAND_EXEC, - "dump_image <file> <address> <size>"); - COMMAND_REGISTER(cmd_ctx, NULL, "verify_image", - handle_verify_image_command, COMMAND_EXEC, - "verify_image <file> [offset] [type]"); - COMMAND_REGISTER(cmd_ctx, NULL, "test_image", - handle_test_image_command, COMMAND_EXEC, - "test_image <file> [offset] [type]"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, target_exec_command_handlers); } commit c3800b5e674be3a9e1c7976925f9cfc52cba3ad5 Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 oocd_trace: use register_commands() diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c index 596a4d6..a34c63c 100644 --- a/src/target/oocd_trace.c +++ b/src/target/oocd_trace.c @@ -407,16 +407,38 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command) return ERROR_OK; } +static const struct command_registration oocd_trace_all_command_handlers[] = { + { + .name = "config", + .handler = &handle_oocd_trace_config_command, + .mode = COMMAND_CONFIG, + .usage = "<target>", + }, + { + .name = "status", + .handler = &handle_oocd_trace_status_command, + .mode = COMMAND_EXEC, + .help = "display OpenOCD + trace status", + }, + { + .name = "resync", + .handler = handle_oocd_trace_resync_command, + .mode = COMMAND_EXEC, + .help = "resync OpenOCD + trace capture clock", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration oocd_trace_command_handlers[] = { + { + .name = "oocd_trace", + .mode = COMMAND_ANY, + .help = "OpenOCD trace capture driver command group", + .chain = oocd_trace_all_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int oocd_trace_register_commands(struct command_context *cmd_ctx) { - struct command *oocd_trace_cmd; - - oocd_trace_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "oocd_trace", NULL, COMMAND_ANY, "OpenOCD + trace"); - - COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, "config", handle_oocd_trace_config_command, COMMAND_CONFIG, NULL); - - COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, "status", handle_oocd_trace_status_command, COMMAND_EXEC, "display OpenOCD + trace status"); - COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, "resync", handle_oocd_trace_resync_command, COMMAND_EXEC, "resync OpenOCD + trace capture clock"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, oocd_trace_command_handlers); } commit a17caa387c0fb08ee2604e066b436d90d9cf0a2f Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 etm_dummy: use register_commands() diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c index 2df8943..27a8eec 100644 --- a/src/target/etm_dummy.c +++ b/src/target/etm_dummy.c @@ -58,15 +58,28 @@ COMMAND_HANDLER(handle_etm_dummy_config_command) return ERROR_OK; } +static const struct command_registration etm_dummy_config_command_handlers[] = { + { + .name = "config", + .handler = &handle_etm_dummy_config_command, + .mode = COMMAND_CONFIG, + .usage = "<target>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration etm_dummy_command_handlers[] = { + { + .name = "etm_dummy", + .mode = COMMAND_ANY, + .help = "Dummy ETM capture driver command group", + .chain = etm_dummy_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int etm_dummy_register_commands(struct command_context *cmd_ctx) { - struct command *etm_dummy_cmd; - - etm_dummy_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "etm_dummy", NULL, COMMAND_ANY, "Dummy ETM capture driver"); - - COMMAND_REGISTER(cmd_ctx, etm_dummy_cmd, "config", handle_etm_dummy_config_command, COMMAND_CONFIG, NULL); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, etm_dummy_command_handlers); } static int etm_dummy_init(struct etm_context *etm_ctx) commit dd063d99147ff08ad817fc3fbd306425b6933d8d Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 07:43:06 2009 -0800 etm: use register_commands() diff --git a/src/target/etm.c b/src/target/etm.c index 6df354a..0f7b41e 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -221,8 +221,6 @@ static int etm_register_user_commands(struct command_context *cmd_ctx); static int etm_set_reg_w_exec(struct reg *reg, uint8_t *buf); static int etm_write_reg(struct reg *reg, uint32_t value); -static struct command *etm_cmd; - static const struct reg_arch_type etm_scan6_type = { .get = etm_get_reg, .set = etm_set_reg_w_exec, @@ -2095,45 +2093,99 @@ COMMAND_HANDLER(handle_etm_analyze_command) return retval; } +static const struct command_registration etm_config_command_handlers[] = { + { + .name = "config", + .handler = &handle_etm_config_command, + .mode = COMMAND_CONFIG, + .usage = "<target> <port_width> <port_mode> " + "<clocking> <capture_driver>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration etm_command_handlers[] = { + { + .name = "etm", + .mode = COMMAND_ANY, + .help = "Emebdded Trace Macrocell command group", + .chain = etm_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int etm_register_commands(struct command_context *cmd_ctx) { - etm_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "etm", NULL, COMMAND_ANY, "Embedded Trace Macrocell"); - - COMMAND_REGISTER(cmd_ctx, etm_cmd, "config", handle_etm_config_command, - COMMAND_CONFIG, "etm config <target> <port_width> <port_mode> <clocking> <capture_driver>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, etm_command_handlers); } +static const struct command_registration etm_exec_command_handlers[] = { + { + .name = "tracemode", handle_etm_tracemode_command, + .mode = COMMAND_EXEC, + .help = "configure/display trace mode", + .usage = "<none | data | address | all> " + "<context_id_bits> <cycle_accurate> <branch_output>", + }, + { + .name = "info", + .handler = &handle_etm_info_command, + .mode = COMMAND_EXEC, + .help = "display info about the current target's ETM", + }, + { + .name = "trigger_percent", + .handler = &handle_etm_trigger_percent_command, + .mode = COMMAND_EXEC, + .help = "amount (<percent>) of trace buffer " + "to be filled after the trigger occured", + }, + { + .name = "status", + .handler = &handle_etm_status_command, + .mode = COMMAND_EXEC, + .help = "display current target's ETM status", + }, + { + .name = "start", + .handler = &handle_etm_start_command, + .mode = COMMAND_EXEC, + .help = "start ETM trace collection", + }, + { + .name = "stop", + .handler = &handle_etm_stop_command, + .mode = COMMAND_EXEC, + .help = "stop ETM trace collection", + }, + { + .name = "analyze", + .handler = &handle_etm_analyze_command, + .mode = COMMAND_EXEC, + .help = "anaylze collected ETM trace", + }, + { + .name = "image", + .handler = &handle_etm_image_command, + .mode = COMMAND_EXEC, + .help = "load image from <file> [base address]", + }, + { + .name = "dump", + .handler = &handle_etm_dump_command, + .mode = COMMAND_EXEC, + .help = "dump captured trace data <file>", + }, + { + .name = "load", + .handler = &handle_etm_load_command, + .mode = COMMAND_EXEC, + .help = "load trace data for analysis <file>", + }, + COMMAND_REGISTRATION_DONE +}; + static int etm_register_user_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, etm_cmd, "tracemode", handle_etm_tracemode_command, - COMMAND_EXEC, "configure/display trace mode: " - "<none | data | address | all> " - "<context_id_bits> <cycle_accurate> <branch_output>"); - - COMMAND_REGISTER(cmd_ctx, etm_cmd, "info", handle_etm_info_command, - COMMAND_EXEC, "display info about the current target's ETM"); - - COMMAND_REGISTER(cmd_ctx, etm_cmd, "trigger_percent", handle_etm_trigger_percent_command, - COMMAND_EXEC, "amount (<percent>) of trace buffer to be filled after the trigger occured"); - COMMAND_REGISTER(cmd_ctx, etm_cmd, "status", handle_etm_status_command, - COMMAND_EXEC, "display current target's ETM status"); - COMMAND_REGISTER(cmd_ctx, etm_cmd, "start", handle_etm_start_command, - COMMAND_EXEC, "start ETM trace collection"); - COMMAND_REGISTER(cmd_ctx, etm_cmd, "stop", handle_etm_stop_command, - COMMAND_EXEC, "stop ETM trace collection"); - - COMMAND_REGISTER(cmd_ctx, etm_cmd, "analyze", handle_etm_analyze_command, - COMMAND_EXEC, "anaylze collected ETM t... [truncated message content] |
From: Zach W. <zw...@us...> - 2009-11-25 19:57:29
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 90d09e35e4be6f0b35899238b253154249f85cb6 (commit) via ad090413a8dfacccc993ff15b8376e0f2bd56712 (commit) via 6b9bb584a5edec4889b12ed3f99a1e2eeab1ada2 (commit) via b4e95c37205bae2c22d9c223a4e92bcea38bf7dd (commit) via 5e977b46c3a4688d9bf5091306ce3003f1bd6713 (commit) via dfa856ca186bd703b3c75f374b4f84dff372345c (commit) via f9606a6cb72d8bce8964b66e5aa5eec5d98a7b1d (commit) via 737f8f2735011256f9ca5a3988ee02167f2847a2 (commit) via 0ff0dbba497374dddac9641b466e97d67bb6678d (commit) via ccae9ae0200a66472409334d18108b309a9fae70 (commit) via 1bf7462edb89a79835e8bd42905d69282ba4ba17 (commit) via 7609e1091abfacfc1b62aca06c642e42003aa444 (commit) via 1cbe3ec6f105e35e641293cd7e62e6fefac1b271 (commit) via a12a29c28a92f51861957a09d86177625220483b (commit) via b90bf52be340d8ad2285f2f359174fbc1e31ce24 (commit) via 1765b103044179baa2d5036bb61710369ae59e70 (commit) via b595ab8b97ae15babe530a935bb5009cdb02fcd7 (commit) via c4aa2fd6e745d7d9fb82673f5845a09c98b10912 (commit) via bdae918dcd3bbcd1a90b2c5f65291908271727f7 (commit) via 2a4a94b7ac4401802832f37ef07b0500efc92f0e (commit) from 8d46720cda288f498787a706bb2518e6f852b9f1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 90d09e35e4be6f0b35899238b253154249f85cb6 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 06:24:19 2009 -0800 remove nand_controller->register_callbacks Replace flash_driver callback with pointer to command_registration. Eliminates all related routines and allows drivers to omit commands. diff --git a/src/flash/davinci_nand.c b/src/flash/davinci_nand.c index ebd9ba8..72cd378 100644 --- a/src/flash/davinci_nand.c +++ b/src/flash/davinci_nand.c @@ -78,11 +78,6 @@ static int halted(struct target *target, const char *label) return false; } -static int davinci_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - static int davinci_init(struct nand_device *nand) { struct davinci_nand *info = nand->controller_priv; @@ -747,7 +742,6 @@ fail: struct nand_flash_controller davinci_nand_controller = { .name = "davinci", .nand_device_command = davinci_nand_device_command, - .register_commands = davinci_register_commands, .init = davinci_init, .reset = davinci_reset, .command = davinci_command, diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 2dec3e1..146c843 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -893,15 +893,10 @@ static const struct command_registration lpc3180_command_handler[] = { COMMAND_REGISTRATION_DONE }; -static int lpc3180_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, lpc3180_command_handler); -} - struct nand_flash_controller lpc3180_nand_controller = { .name = "lpc3180", + .commands = lpc3180_command_handler, .nand_device_command = lpc3180_nand_device_command, - .register_commands = lpc3180_register_commands, .init = lpc3180_init, .reset = lpc3180_reset, .command = lpc3180_command, diff --git a/src/flash/mx3_nand.c b/src/flash/mx3_nand.c index 459e2a6..1dc4fcb 100644 --- a/src/flash/mx3_nand.c +++ b/src/flash/mx3_nand.c @@ -315,11 +315,6 @@ static int imx31_nand_ready (struct nand_device *nand, int timeout) return imx31_controller_ready (nand, timeout); } -static int imx31_register_commands (struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - static int imx31_reset (struct nand_device *nand) { /* @@ -871,7 +866,6 @@ static int do_data_output (struct nand_device *nand) struct nand_flash_controller imx31_nand_flash_controller = { .name = "imx31", .nand_device_command = &imx31_nand_device_command, - .register_commands = &imx31_register_commands, .init = &imx31_init, .reset = &imx31_reset, .command = &imx31_command, diff --git a/src/flash/nand.c b/src/flash/nand.c index bc0e350..1e28ba2 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -214,11 +214,12 @@ COMMAND_HANDLER(handle_nand_list_drivers) static COMMAND_HELPER(create_nand_device, const char *bank_name, struct nand_flash_controller *controller) { - int retval = controller->register_commands(CMD_CTX); - if (ERROR_OK != retval) + if (NULL != controller->commands) { - LOG_ERROR("couldn't register '%s' commands", controller->name); - return retval; + int retval = register_commands(CMD_CTX, NULL, + controller->commands); + if (ERROR_OK != retval) + return retval; } struct nand_device *c = malloc(sizeof(struct nand_device)); @@ -233,7 +234,7 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name, c->use_raw = 0; c->next = NULL; - retval = CALL_COMMAND_HANDLER(controller->nand_device_command, c); + int retval = CALL_COMMAND_HANDLER(controller->nand_device_command, c); if (ERROR_OK != retval) { LOG_ERROR("'%s' driver rejected nand flash", controller->name); diff --git a/src/flash/nand.h b/src/flash/nand.h index af52c77..b780f28 100644 --- a/src/flash/nand.h +++ b/src/flash/nand.h @@ -35,8 +35,8 @@ struct nand_device; struct nand_flash_controller { char *name; + const struct command_registration *commands; __NAND_DEVICE_COMMAND((*nand_device_command)); - int (*register_commands)(struct command_context *cmd_ctx); int (*init)(struct nand_device *nand); int (*reset)(struct nand_device *nand); int (*command)(struct nand_device *nand, uint8_t command); diff --git a/src/flash/orion_nand.c b/src/flash/orion_nand.c index c8fc969..77a03f2 100644 --- a/src/flash/orion_nand.c +++ b/src/flash/orion_nand.c @@ -120,11 +120,6 @@ static int orion_nand_controller_ready(struct nand_device *nand, int timeout) return 1; } -static int orion_nand_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - NAND_DEVICE_COMMAND_HANDLER(orion_nand_device_command) { struct orion_nand_controller *hw; @@ -180,7 +175,6 @@ struct nand_flash_controller orion_nand_controller = .reset = orion_nand_reset, .controller_ready = orion_nand_controller_ready, .nand_device_command = orion_nand_device_command, - .register_commands = orion_nand_register_commands, .init = orion_nand_init, }; diff --git a/src/flash/s3c2410_nand.c b/src/flash/s3c2410_nand.c index 6fe8bae..ca50c99 100644 --- a/src/flash/s3c2410_nand.c +++ b/src/flash/s3c2410_nand.c @@ -110,7 +110,6 @@ static int s3c2410_nand_ready(struct nand_device *nand, int timeout) struct nand_flash_controller s3c2410_nand_controller = { .name = "s3c2410", .nand_device_command = &s3c2410_nand_device_command, - .register_commands = &s3c24xx_register_commands, .init = &s3c2410_init, .reset = &s3c24xx_reset, .command = &s3c24xx_command, diff --git a/src/flash/s3c2412_nand.c b/src/flash/s3c2412_nand.c index 2ca4cd3..acc6d99 100644 --- a/src/flash/s3c2412_nand.c +++ b/src/flash/s3c2412_nand.c @@ -64,7 +64,6 @@ static int s3c2412_init(struct nand_device *nand) struct nand_flash_controller s3c2412_nand_controller = { .name = "s3c2412", .nand_device_command = &s3c2412_nand_device_command, - .register_commands = &s3c24xx_register_commands, .init = &s3c2412_init, .reset = &s3c24xx_reset, .command = &s3c24xx_command, diff --git a/src/flash/s3c2440_nand.c b/src/flash/s3c2440_nand.c index 65e5a51..556f6f1 100644 --- a/src/flash/s3c2440_nand.c +++ b/src/flash/s3c2440_nand.c @@ -156,7 +156,6 @@ int s3c2440_write_block_data(struct nand_device *nand, uint8_t *data, int data_s struct nand_flash_controller s3c2440_nand_controller = { .name = "s3c2440", .nand_device_command = &s3c2440_nand_device_command, - .register_commands = &s3c24xx_register_commands, .init = &s3c2440_init, .reset = &s3c24xx_reset, .command = &s3c24xx_command, diff --git a/src/flash/s3c2443_nand.c b/src/flash/s3c2443_nand.c index 5afb26f..311bb69 100644 --- a/src/flash/s3c2443_nand.c +++ b/src/flash/s3c2443_nand.c @@ -65,7 +65,6 @@ static int s3c2443_init(struct nand_device *nand) struct nand_flash_controller s3c2443_nand_controller = { .name = "s3c2443", .nand_device_command = &s3c2443_nand_device_command, - .register_commands = &s3c24xx_register_commands, .init = &s3c2443_init, .reset = &s3c24xx_reset, .command = &s3c24xx_command, diff --git a/src/flash/s3c24xx_nand.c b/src/flash/s3c24xx_nand.c index 262569e..e7afb48 100644 --- a/src/flash/s3c24xx_nand.c +++ b/src/flash/s3c24xx_nand.c @@ -52,11 +52,6 @@ S3C24XX_DEVICE_COMMAND() return ERROR_OK; } -int s3c24xx_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - int s3c24xx_reset(struct nand_device *nand) { struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv; diff --git a/src/flash/s3c24xx_nand.h b/src/flash/s3c24xx_nand.h index 4829c7c..fad33a0 100644 --- a/src/flash/s3c24xx_nand.h +++ b/src/flash/s3c24xx_nand.h @@ -59,8 +59,6 @@ S3C24XX_DEVICE_COMMAND(); return retval; \ } while (0) -int s3c24xx_register_commands(struct command_context *cmd_ctx); - int s3c24xx_reset(struct nand_device *nand); int s3c24xx_command(struct nand_device *nand, uint8_t command); commit ad090413a8dfacccc993ff15b8376e0f2bd56712 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 06:12:04 2009 -0800 remove flash_driver->register_callbacks Replace flash_driver callback with pointer to command_registration. Eliminates all related routines and allows drivers to omit commands. diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c index 75e8495..be17a5f 100644 --- a/src/flash/at91sam3.c +++ b/src/flash/at91sam3.c @@ -2501,14 +2501,9 @@ static const struct command_registration at91sam3_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int sam3_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, at91sam3_command_handlers); -} - struct flash_driver at91sam3_flash = { .name = "at91sam3", - .register_commands = &sam3_register_commands, + .commands = at91sam3_command_handlers, .flash_bank_command = &sam3_flash_bank_command, .erase = &sam3_erase, .protect = &sam3_protect, diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index 0204660..f9b87ba 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -1198,14 +1198,9 @@ static const struct command_registration at91sam7_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int at91sam7_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, at91sam7_command_handlers); -} - struct flash_driver at91sam7_flash = { .name = "at91sam7", - .register_commands = &at91sam7_register_commands, + .commands = at91sam7_command_handlers, .flash_bank_command = &at91sam7_flash_bank_command, .erase = &at91sam7_erase, .protect = &at91sam7_protect, diff --git a/src/flash/avrf.c b/src/flash/avrf.c index 9aea47d..1c48464 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -468,14 +468,9 @@ static const struct command_registration avrf_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int avrf_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, avrf_command_handlers); -} - struct flash_driver avr_flash = { .name = "avr", - .register_commands = &avrf_register_commands, + .commands = avrf_command_handlers, .flash_bank_command = &avrf_flash_bank_command, .erase = &avrf_erase, .protect = &avrf_protect, diff --git a/src/flash/cfi.c b/src/flash/cfi.c index b92ecbd..6dbffb9 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -589,11 +589,6 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size) return ERROR_OK; } -static int cfi_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - /* flash_bank cfi <base> <size> <chip_width> <bus_width> <target#> [options] */ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command) @@ -2623,7 +2618,6 @@ static int cfi_info(struct flash_bank *bank, char *buf, int buf_size) struct flash_driver cfi_flash = { .name = "cfi", - .register_commands = &cfi_register_commands, .flash_bank_command = &cfi_flash_bank_command, .erase = &cfi_erase, .protect = &cfi_protect, diff --git a/src/flash/ecos.c b/src/flash/ecos.c index f6f3307..7a0b26f 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -336,11 +336,6 @@ static int ecosflash_probe(struct flash_bank *bank) return ERROR_OK; } -static int ecosflash_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - #if 0 static void command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf) { @@ -437,7 +432,6 @@ static int ecosflash_handle_gpnvm_command(struct command_context *cmd_ctx, char struct flash_driver ecosflash_flash = { .name = "ecosflash", - .register_commands = &ecosflash_register_commands, .flash_bank_command = &ecosflash_flash_bank_command, .erase = &ecosflash_erase, .protect = &ecosflash_protect, diff --git a/src/flash/faux.c b/src/flash/faux.c index 558d7b0..adfc7bd 100644 --- a/src/flash/faux.c +++ b/src/flash/faux.c @@ -87,11 +87,6 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command) return ERROR_OK; } -static int faux_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - static int faux_erase(struct flash_bank *bank, int first, int last) { struct faux_flash_bank *info = bank->driver_priv; @@ -130,7 +125,6 @@ static int faux_probe(struct flash_bank *bank) struct flash_driver faux_flash = { .name = "faux", - .register_commands = &faux_register_commands, .flash_bank_command = &faux_flash_bank_command, .erase = &faux_erase, .protect = &faux_protect, diff --git a/src/flash/flash.c b/src/flash/flash.c index de95b62..4584c5d 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -263,15 +263,20 @@ COMMAND_HANDLER(handle_flash_bank_command) if (strcmp(driver_name, flash_drivers[i]->name) != 0) continue; - struct flash_bank *p, *c; - /* register flash specific commands */ - if (flash_drivers[i]->register_commands(CMD_CTX) != ERROR_OK) + if (NULL != flash_drivers[i]->commands) { - LOG_ERROR("couldn't register '%s' commands", driver_name); - return ERROR_FAIL; + int retval = register_commands(CMD_CTX, NULL, + flash_drivers[i]->commands); + if (ERROR_OK != retval) + { + LOG_ERROR("couldn't register '%s' commands", + driver_name); + return ERROR_FAIL; + } } + struct flash_bank *p, *c; c = malloc(sizeof(struct flash_bank)); c->name = strdup(bank_name); c->target = target; diff --git a/src/flash/flash.h b/src/flash/flash.h index ac1600e..92727bf 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -91,13 +91,11 @@ struct flash_driver char *name; /** - * Registers driver-specific commands. When called (during the - * "flash bank" command), the driver may register addition + * An array of driver-specific commands to register. When called + * during the "flash bank" command, the driver can register addition * commands to support new flash chip functions. - * - * @returns ERROR_OK if successful; otherwise, an error code. */ - int (*register_commands)(struct command_context *cmd_ctx); + const struct command_registration *commands; /** * Finish the "flash bank" command for @a bank. The diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index 896b794..418b5b0 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -795,14 +795,9 @@ static const struct command_registration lpc2000_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int lpc2000_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, lpc2000_command_handlers); -} - struct flash_driver lpc2000_flash = { .name = "lpc2000", - .register_commands = &lpc2000_register_commands, + .commands = lpc2000_command_handlers, .flash_bank_command = &lpc2000_flash_bank_command, .erase = &lpc2000_erase, .protect = &lpc2000_protect, diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c index 0d961e4..81e2def 100644 --- a/src/flash/lpc2900.c +++ b/src/flash/lpc2900.c @@ -1003,15 +1003,6 @@ static const struct command_registration lpc2900_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -/** - * Register private command handlers. - */ -static int lpc2900_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, lpc2900_command_handlers); -} - - /// Evaluate flash bank command. FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command) { @@ -1830,7 +1821,7 @@ static int lpc2900_info(struct flash_bank *bank, char *buf, int buf_size) struct flash_driver lpc2900_flash = { .name = "lpc2900", - .register_commands = lpc2900_register_commands, + .commands = lpc2900_command_handlers, .flash_bank_command = lpc2900_flash_bank_command, .erase = lpc2900_erase, .protect = lpc2900_protect, diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index 1950e05..9bb6c97 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -907,14 +907,9 @@ static const struct command_registration pic32mx_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int pic32mx_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, pic32mx_command_handlers); -} - struct flash_driver pic32mx_flash = { .name = "pic32mx", - .register_commands = &pic32mx_register_commands, + .commands = pic32mx_command_handlers, .flash_bank_command = &pic32mx_flash_bank_command, .erase = &pic32mx_erase, .protect = &pic32mx_protect, diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c index 1cff486..771f0a7 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -1180,15 +1180,9 @@ static const struct command_registration stellaris_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int stellaris_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, stellaris_command_handlers); -} - - struct flash_driver stellaris_flash = { .name = "stellaris", - .register_commands = &stellaris_register_commands, + .commands = stellaris_command_handlers, .flash_bank_command = &stellaris_flash_bank_command, .erase = &stellaris_erase, .protect = &stellaris_protect, diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index 808e32c..2f51aa5 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -1225,13 +1225,9 @@ static const struct command_registration stm32x_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int stm32x_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, stm32x_command_handlers); -} struct flash_driver stm32x_flash = { .name = "stm32x", - .register_commands = &stm32x_register_commands, + .commands = stm32x_command_handlers, .flash_bank_command = &stm32x_flash_bank_command, .erase = &stm32x_erase, .protect = &stm32x_protect, diff --git a/src/flash/str7x.c b/src/flash/str7x.c index e72946f..7edffac 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -691,14 +691,9 @@ static const struct command_registration str7x_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int str7x_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, str7x_command_handlers); -} - struct flash_driver str7x_flash = { .name = "str7x", - .register_commands = &str7x_register_commands, + .commands = str7x_command_handlers, .flash_bank_command = &str7x_flash_bank_command, .erase = &str7x_erase, .protect = &str7x_protect, diff --git a/src/flash/str9x.c b/src/flash/str9x.c index f6ad51a..98f15e7 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -696,14 +696,9 @@ static const struct command_registration str9x_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int str9x_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, str9x_command_handlers); -} - struct flash_driver str9x_flash = { .name = "str9x", - .register_commands = &str9x_register_commands, + .commands = str9x_command_handlers, .flash_bank_command = &str9x_flash_bank_command, .erase = &str9x_erase, .protect = &str9x_protect, diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index 7f6a29a..96e1259 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -1242,15 +1242,9 @@ static const struct command_registration str9xpec_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int str9xpec_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, str9xpec_command_handlers); -} - - struct flash_driver str9xpec_flash = { .name = "str9xpec", - .register_commands = &str9xpec_register_commands, + .commands = str9xpec_command_handlers, .flash_bank_command = &str9xpec_flash_bank_command, .erase = &str9xpec_erase, .protect = &str9xpec_protect, diff --git a/src/flash/tms470.c b/src/flash/tms470.c index 3f32b51..682013e 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -848,11 +848,6 @@ static const struct command_registration tms470_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int tms470_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, tms470_command_handlers); -} - /* ---------------------------------------------------------------------- */ static int tms470_erase(struct flash_bank *bank, int first, int last) @@ -1263,7 +1258,7 @@ FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command) struct flash_driver tms470_flash = { .name = "tms470", - .register_commands = &tms470_register_commands, + .commands = tms470_command_handlers, .flash_bank_command = &tms470_flash_bank_command, .erase = &tms470_erase, .protect = &tms470_protect, commit 6b9bb584a5edec4889b12ed3f99a1e2eeab1ada2 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 tms470: use register_commands() diff --git a/src/flash/tms470.c b/src/flash/tms470.c index bf58f1d..3f32b51 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -817,15 +817,40 @@ static int tms470_erase_sector(struct flash_bank *bank, int sector) Implementation of Flash Driver Interfaces ---------------------------------------------------------------------- */ +static const struct command_registration tms470_any_command_handlers[] = { + { + .name = "flash_keyset", + .handler = &tms470_handle_flash_keyset_command, + .mode = COMMAND_ANY, + .help = "tms470 flash_keyset <key0> <key1> <key2> <key3>", + }, + { + .name = "osc_megahertz", + .handler = &tms470_handle_osc_megahertz_command, + .mode = COMMAND_ANY, + .help = "tms470 osc_megahertz <MHz>", + }, + { + .name = "plldis", + .handler = &tms470_handle_plldis_command, + .mode = COMMAND_ANY, + .help = "tms470 plldis <0/1>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration tms470_command_handlers[] = { + { + .name = "tms470", + .mode = COMMAND_ANY, + .help = "TI tms470 flash command group", + .chain = tms470_any_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int tms470_register_commands(struct command_context *cmd_ctx) { - struct command *tms470_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); - - COMMAND_REGISTER(cmd_ctx, tms470_cmd, "flash_keyset", tms470_handle_flash_keyset_command, COMMAND_ANY, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); - COMMAND_REGISTER(cmd_ctx, tms470_cmd, "osc_megahertz", tms470_handle_osc_megahertz_command, COMMAND_ANY, "tms470 osc_megahertz <MHz>"); - COMMAND_REGISTER(cmd_ctx, tms470_cmd, "plldis", tms470_handle_plldis_command, COMMAND_ANY, "tms470 plldis <0/1>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, tms470_command_handlers); } /* ---------------------------------------------------------------------- */ commit b4e95c37205bae2c22d9c223a4e92bcea38bf7dd Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 str9xpec: use register_commands() diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index 7519413..7f6a29a 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -1163,48 +1163,91 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command) return ERROR_OK; } +static const struct command_registration str9xpec_config_command_handlers[] = { + { + .name = "enable_turbo", + .handler = str9xpec_handle_flash_enable_turbo_command, + .mode = COMMAND_EXEC, + .help = "enable str9xpec turbo mode", + }, + { + .name = "disable_turbo", + .handler = str9xpec_handle_flash_disable_turbo_command, + .mode = COMMAND_EXEC, + .help = "disable str9xpec turbo mode", + }, + { + .name = "options_cmap", + .handler = str9xpec_handle_flash_options_cmap_command, + .mode = COMMAND_EXEC, + .help = "configure str9xpec boot sector", + }, + { + .name = "options_lvdthd", + .handler = str9xpec_handle_flash_options_lvdthd_command, + .mode = COMMAND_EXEC, + .help = "configure str9xpec lvd threshold", + }, + { + .name = "options_lvdsel", + .handler = str9xpec_handle_flash_options_lvdsel_command, + .mode = COMMAND_EXEC, + .help = "configure str9xpec lvd selection", + }, + { + .name = "options_lvdwarn", + .handler = str9xpec_handle_flash_options_lvdwarn_command, + .mode = COMMAND_EXEC, + .help = "configure str9xpec lvd warning", + }, + { + .name = "options_read", + .handler = str9xpec_handle_flash_options_read_command, + .mode = COMMAND_EXEC, + .help = "read str9xpec options", + }, + { + .name = "options_write", + .handler = str9xpec_handle_flash_options_write_command, + .mode = COMMAND_EXEC, + .help = "write str9xpec options", + }, + { + .name = "lock", + .handler = str9xpec_handle_flash_lock_command, + .mode = COMMAND_EXEC, + .help = "lock str9xpec device", + }, + { + .name = "unlock", + .handler = str9xpec_handle_flash_unlock_command, + .mode = COMMAND_EXEC, + .help = "unlock str9xpec device", + }, + { + .name = "part_id", + .handler = str9xpec_handle_part_id_command, + .mode = COMMAND_EXEC, + .help = "print part id of str9xpec flash bank <num>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration str9xpec_command_handlers[] = { + { + .name = "str9xpec", + .mode = COMMAND_ANY, + .help = "str9xpec flash command group", + .chain = str9xpec_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int str9xpec_register_commands(struct command_context *cmd_ctx) { - struct command *str9xpec_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9xpec", - NULL, COMMAND_ANY, "str9xpec flash specific commands"); - - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "enable_turbo", - str9xpec_handle_flash_enable_turbo_command, - COMMAND_EXEC, "enable str9xpec turbo mode"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "disable_turbo", - str9xpec_handle_flash_disable_turbo_command, - COMMAND_EXEC, "disable str9xpec turbo mode"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_cmap", - str9xpec_handle_flash_options_cmap_command, - COMMAND_EXEC, "configure str9xpec boot sector"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdthd", - str9xpec_handle_flash_options_lvdthd_command, - COMMAND_EXEC, "configure str9xpec lvd threshold"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdsel", - str9xpec_handle_flash_options_lvdsel_command, - COMMAND_EXEC, "configure str9xpec lvd selection"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdwarn", - str9xpec_handle_flash_options_lvdwarn_command, - COMMAND_EXEC, "configure str9xpec lvd warning"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_read", - str9xpec_handle_flash_options_read_command, - COMMAND_EXEC, "read str9xpec options"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_write", - str9xpec_handle_flash_options_write_command, - COMMAND_EXEC, "write str9xpec options"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "lock", - str9xpec_handle_flash_lock_command, - COMMAND_EXEC, "lock str9xpec device"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "unlock", - str9xpec_handle_flash_unlock_command, - COMMAND_EXEC, "unlock str9xpec device"); - COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "part_id", - str9xpec_handle_part_id_command, - COMMAND_EXEC, "print part id of str9xpec flash bank <num>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, str9xpec_command_handlers); } + struct flash_driver str9xpec_flash = { .name = "str9xpec", .register_commands = &str9xpec_register_commands, commit 5e977b46c3a4688d9bf5091306ce3003f1bd6713 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 str9x: use register_commands() diff --git a/src/flash/str9x.c b/src/flash/str9x.c index 6d556d9..f6ad51a 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -676,16 +676,29 @@ COMMAND_HANDLER(str9x_handle_flash_config_command) return ERROR_OK; } +static const struct command_registration str9x_config_command_handlers[] = { + { + .name = "disable_jtag", + .handler = &str9x_handle_flash_config_command, + .mode = COMMAND_EXEC, + .help = "configure str9x flash controller", + .usage = "<bank_id> <BBSR> <NBBSR> <BBADR> <NBBADR>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration str9x_command_handlers[] = { + { + .name = "str9x", + .mode = COMMAND_ANY, + .help = "str9x flash command group", + .chain = str9x_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int str9x_register_commands(struct command_context *cmd_ctx) { - struct command *str9x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9x", - NULL, COMMAND_ANY, "str9x flash commands"); - - COMMAND_REGISTER(cmd_ctx, str9x_cmd, "flash_config", - str9x_handle_flash_config_command, COMMAND_EXEC, - "configure str9 flash controller"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, str9x_command_handlers); } struct flash_driver str9x_flash = { commit dfa856ca186bd703b3c75f374b4f84dff372345c Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 str7x: use register_commands() diff --git a/src/flash/str7x.c b/src/flash/str7x.c index b53ddf9..e72946f 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -672,16 +672,28 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command) return ERROR_OK; } +static const struct command_registration str7x_exec_command_handlers[] = { + { + .name = "disable_jtag", + .handler = &str7x_handle_disable_jtag_command, + .mode = COMMAND_EXEC, + .help = "disable jtag access", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration str7x_command_handlers[] = { + { + .name = "str7x", + .mode = COMMAND_ANY, + .help = "str7x flash command group", + .chain = str7x_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int str7x_register_commands(struct command_context *cmd_ctx) { - struct command *str7x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str7x", - NULL, COMMAND_ANY, "str7x flash specific commands"); - - COMMAND_REGISTER(cmd_ctx, str7x_cmd, "disable_jtag", - str7x_handle_disable_jtag_command, COMMAND_EXEC, - "disable jtag access"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, str7x_command_handlers); } struct flash_driver str7x_flash = { commit f9606a6cb72d8bce8964b66e5aa5eec5d98a7b1d Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 stm32x: use register_commands() diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index c628f18..808e32c 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -1182,30 +1182,53 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) return ERROR_OK; } +static const struct command_registration stm32x_exec_command_handlers[] = { + { + .name = "lock", + .handler = &stm32x_handle_lock_command, + .mode = COMMAND_EXEC, + .help = "lock device", + }, + { + .name = "unlock", + .handler = &stm32x_handle_unlock_command, + .mode = COMMAND_EXEC, + .help = "unlock protected device", + }, + { + .name = "mass_erase", + .handler = &stm32x_handle_mass_erase_command, + .mode = COMMAND_EXEC, + .help = "mass erase device", + }, + { + .name = "options_read", + .handler = &stm32x_handle_options_read_command, + .mode = COMMAND_EXEC, + .help = "read device option bytes", + }, + { + .name = "options_write", + .handler = &stm32x_handle_options_write_command, + .mode = COMMAND_EXEC, + .help = "write device option bytes", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration stm32x_command_handlers[] = { + { + .name = "stm32x", + .mode = COMMAND_ANY, + .help = "stm32x flash command group", + .chain = stm32x_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int stm32x_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stm32x", - NULL, COMMAND_ANY, "stm32x flash specific commands"); - - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "lock", - stm32x_handle_lock_command, COMMAND_EXEC, - "lock device"); - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "unlock", - stm32x_handle_unlock_command, COMMAND_EXEC, - "unlock protected device"); - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", - stm32x_handle_mass_erase_command, COMMAND_EXEC, - "mass erase device"); - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_read", - stm32x_handle_options_read_command, COMMAND_EXEC, - "read device option bytes"); - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_write", - stm32x_handle_options_write_command, COMMAND_EXEC, - "write device option bytes"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, stm32x_command_handlers); } - struct flash_driver stm32x_flash = { .name = "stm32x", .register_commands = &stm32x_register_commands, commit 737f8f2735011256f9ca5a3988ee02167f2847a2 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 stellaris: use register_commands() diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c index 2d653ec..1cff486 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -1161,15 +1161,28 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) return ERROR_OK; } +static const struct command_registration stellaris_exec_command_handlers[] = { + { + .name = "mass_erase", + .handler = &stellaris_handle_mass_erase_command, + .mode = COMMAND_EXEC, + .help = "erase entire device", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration stellaris_command_handlers[] = { + { + .name = "stellaris", + .mode = COMMAND_ANY, + .help = "Stellaris flash command group", + .chain = stellaris_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int stellaris_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stellaris", - NULL, COMMAND_ANY, "stellaris flash specific commands"); - - COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", - stellaris_handle_mass_erase_command, COMMAND_EXEC, - "mass erase device"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, stellaris_command_handlers); } commit 0ff0dbba497374dddac9641b466e97d67bb6678d Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 pic32mx: use register_commands() diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index c6d4615..1950e05 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -882,26 +882,34 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) return ERROR_OK; } +static const struct command_registration pic32mx_exec_command_handlers[] = { + { + .name = "chip_erase", + .handler = &pic32mx_handle_chip_erase_command, + .mode = COMMAND_EXEC, + .help = "erase device", + }, + { + .name = "pgm_word", + .handler = &pic32mx_handle_pgm_word_command, + .mode = COMMAND_EXEC, + .help = "program a word", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration pic32mx_command_handlers[] = { + { + .name = "pic32mx", + .mode = COMMAND_ANY, + .help = "pic32mx flash command group", + .chain = pic32mx_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; static int pic32mx_register_commands(struct command_context *cmd_ctx) { - struct command *pic32mx_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "pic32mx", - NULL, COMMAND_ANY, "pic32mx flash specific commands"); -#if 0 - COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "lock", - pic32mx_handle_lock_command, COMMAND_EXEC, - "lock device"); - COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "unlock", - pic32mx_handle_unlock_command, COMMAND_EXEC, - "unlock protected device"); -#endif - COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "chip_erase", - pic32mx_handle_chip_erase_command, COMMAND_EXEC, - "erase device"); - COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "pgm_word", - pic32mx_handle_pgm_word_command, COMMAND_EXEC, - "program a word"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, pic32mx_command_handlers); } struct flash_driver pic32mx_flash = { commit ccae9ae0200a66472409334d18108b309a9fae70 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 nand: use register_commands() Eliminates 'nand_cmd' global variable. diff --git a/src/flash/nand.c b/src/flash/nand.c index 2438ddd..bc0e350 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -63,7 +63,6 @@ static struct nand_flash_controller *nand_flash_controllers[] = /* configured NAND devices and NAND Flash command handler */ static struct nand_device *nand_devices = NULL; -static struct command *nand_cmd; /* Chip ID list * @@ -279,19 +278,34 @@ COMMAND_HANDLER(handle_nand_device_command) return CALL_COMMAND_HANDLER(handle_nand_list_drivers); } +static const struct command_registration nand_config_command_handlers[] = { + { + .name = "device", + .handler = &handle_nand_device_command, + .mode = COMMAND_CONFIG, + .help = "defines a new NAND bank", + }, + { + .name = "drivers", + .handler = &handle_nand_list_drivers, + .mode = COMMAND_ANY, + .help = "lists available NAND drivers", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration nand_command_handlers[] = { + { + .name = "nand", + .mode = COMMAND_ANY, + .help = "NAND flash command group", + .chain = nand_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int nand_register_commands(struct command_context *cmd_ctx) { - nand_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "nand", - NULL, COMMAND_ANY, "NAND specific commands"); - - COMMAND_REGISTER(cmd_ctx, nand_cmd, "device", - &handle_nand_device_command, COMMAND_CONFIG, - "defines a new NAND bank"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "drivers", - &handle_nand_list_drivers, COMMAND_ANY, - "lists available NAND drivers"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, nand_command_handlers); } struct nand_device *get_nand_device_by_name(const char *name) @@ -1700,43 +1714,80 @@ COMMAND_HANDLER(handle_nand_raw_access_command) return ERROR_OK; } +static const struct command_registration nand_exec_command_handlers[] = { + { + .name = "list", + .handler = &handle_nand_list_command, + .mode = COMMAND_EXEC, + .help = "list configured NAND flash devices", + }, + { + .name = "info", + .handler = &handle_nand_info_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "print info about a NAND flash device", + }, + { + .name = "probe", + .handler = &handle_nand_probe_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "identify NAND flash device <num>", + + }, + { + .name = "check_bad_blocks", + .handler = &handle_nand_check_bad_blocks_command, + .mode = COMMAND_EXEC, + .usage = "<bank> [<offset> <length>]", + .help = "check NAND flash device <num> for bad blocks", + }, + { + .name = "erase", + .handler = &handle_nand_erase_command, + .mode = COMMAND_EXEC, + .usage = "<bank> [<offset> <length>]", + .help = "erase blocks on NAND flash device", + }, + { + .name = "dump", + .handler = &handle_nand_dump_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <filename> <offset> <length> " + "[oob_raw | oob_only]", + .help = "dump from NAND flash device", + }, + { + .name = "verify", + .handler = &handle_nand_verify_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <filename> <offset> " + "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]", + .help = "verify NAND flash device", + }, + { + .name = "write", + .handler = &handle_nand_write_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <filename> <offset> " + "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]", + .help = "write to NAND flash device", + }, + { + .name = "raw_access", + .handler = &handle_nand_raw_access_command, + .mode = COMMAND_EXEC, + .usage = "<num> ['enable'|'disable']", + .help = "raw access to NAND flash device", + }, + COMMAND_REGISTRATION_DONE +}; + int nand_init(struct command_context *cmd_ctx) { if (!nand_devices) return ERROR_OK; - - COMMAND_REGISTER(cmd_ctx, nand_cmd, "list", - handle_nand_list_command, COMMAND_EXEC, - "list configured NAND flash devices"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "info", - handle_nand_info_command, COMMAND_EXEC, - "print info about NAND flash device <num>"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "probe", - handle_nand_probe_command, COMMAND_EXEC, - "identify NAND flash device <num>"); - - COMMAND_REGISTER(cmd_ctx, nand_cmd, "check_bad_blocks", - handle_nand_check_bad_blocks_command, COMMAND_EXEC, - "check NAND flash device <num> for bad blocks [<offset> <length>]"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "erase", - handle_nand_erase_command, COMMAND_EXEC, - "erase blocks on NAND flash device <num> [<offset> <length>]"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "dump", - handle_nand_dump_command, COMMAND_EXEC, - "dump from NAND flash device <num> <filename> " - "<offset> <length> [oob_raw | oob_only]"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "verify", - &handle_nand_verify_command, COMMAND_EXEC, - "verify NAND flash device <num> <filename> <offset> " - "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - COMMAND_REGISTER(cmd_ctx, nand_cmd, "write", - handle_nand_write_command, COMMAND_EXEC, - "write to NAND flash device <num> <filename> <offset> " - "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - - COMMAND_REGISTER(cmd_ctx, nand_cmd, "raw_access", - handle_nand_raw_access_command, COMMAND_EXEC, - "raw access to NAND flash device <num> ['enable'|'disable']"); - - return ERROR_OK; + struct command *parent = command_find_in_context(cmd_ctx, "nand"); + return register_commands(cmd_ctx, parent, nand_exec_command_handlers); } commit 1bf7462edb89a79835e8bd42905d69282ba4ba17 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 mflash: use register_commands() diff --git a/src/flash/mflash.c b/src/flash/mflash.c index a4a45dc..03a56e2 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -33,8 +33,6 @@ static int s3c2440_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val static int pxa270_set_gpio_to_output (struct mflash_gpio_num gpio); static int pxa270_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t val); -static struct command *mflash_cmd; - static struct mflash_bank *mflash_bank; static struct mflash_gpio_drv pxa270_gpio = { @@ -1268,19 +1266,42 @@ COMMAND_HANDLER(mg_config_cmd) } } +static const struct command_registration mflash_exec_command_handlers[] = { + { + .name = "probe", + .handler = &mg_probe_cmd, + .mode = COMMAND_EXEC, + .help = "Detect bank configuration information", + }, + { + .name = "write", + .handler = &mg_write_cmd, + .mode = COMMAND_EXEC, + .usage = "<num> <file> <address>", + .help = "Write a file at the specified address", + }, + { + .name = "dump", + .handler = &mg_dump_cmd, + .mode = COMMAND_EXEC, + .usage = "<num> <file> <address> <size>", + .help = "Dump to a file from the specified address", + }, + { + .name = "config", + .handler = &mg_config_cmd, + .mode = COMMAND_EXEC, + .usage = "<num> <stage>", + .help = "Dump to a file from the specified address", + }, + COMMAND_REGISTRATION_DONE +}; + int mflash_init_drivers(struct command_context *cmd_ctx) { - if (mflash_bank) { - COMMAND_REGISTER(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL); - COMMAND_REGISTER(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC, - "mflash write <num> <file> <address>"); - COMMAND_REGISTER(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC, - "mflash dump <num> <file> <address> <size>"); - COMMAND_REGISTER(cmd_ctx, mflash_cmd, "config", mg_config_cmd, - COMMAND_EXEC, "mflash config <num> <stage>"); - } - - return ERROR_OK; + if (!mflash_bank) + return ERROR_OK; + return register_commands(cmd_ctx, NULL, mflash_exec_command_handlers); } COMMAND_HANDLER(mg_bank_cmd) @@ -1323,10 +1344,26 @@ COMMAND_HANDLER(mg_bank_cmd) return ERROR_OK; } +static const struct command_registration mflash_config_command_handlers[] = { + { + .name = "bank", + .handler = &mg_bank_cmd, + .mode = COMMAND_CONFIG, + .help = "configure a mflash device bank", + .usage = "<soc> <base> <RST pin> <target #>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration mflash_command_handler[] = { + { + .name = "mflash", + .mode = COMMAND_ANY, + .help = "mflash command group", + .chain = mflash_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; int mflash_register_commands(struct command_context *cmd_ctx) { - mflash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL); - COMMAND_REGISTER(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG, - "mflash bank <soc> <base> <RST pin> <target #>"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, mflash_command_handler); } commit 7609e1091abfacfc1b62aca06c642e42003aa444 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 lpc3180_nand_controller: use register_commands() diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 801607d..2dec3e1 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -873,13 +873,29 @@ COMMAND_HANDLER(handle_lpc3180_select_command) return ERROR_OK; } +static const struct command_registration lpc3180_exec_command_handlers[] = { + { + .name = "select", + .handler = &handle_lpc3180_select_command, + .mode = COMMAND_EXEC, + .help = "select <'mlc'|'slc'> controller (default is mlc)", + .usage = "<device_id> (mlc|slc)", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration lpc3180_command_handler[] = { + { + .name = "lpc3180", + .mode = COMMAND_ANY, + .help = "LPC3180 NAND flash controller commands", + .chain = lpc3180_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int lpc3180_register_commands(struct command_context *cmd_ctx) { - struct command *lpc3180_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc3180", NULL, COMMAND_ANY, "commands specific to the LPC3180 NAND flash controllers"); - - COMMAND_REGISTER(cmd_ctx, lpc3180_cmd, "select", handle_lpc3180_select_command, COMMAND_EXEC, "select <'mlc'|'slc'> controller (default is mlc)"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, lpc3180_command_handler); } struct nand_flash_controller lpc3180_nand_controller = { commit 1cbe3ec6f105e35e641293cd7e62e6fefac1b271 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 lpc2900: use register_commands() diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c index c7f1b3a..0d961e4 100644 --- a/src/flash/lpc2900.c +++ b/src/flash/lpc2900.c @@ -948,46 +948,67 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command) /*********************** Flash interface functions **************************/ +static const struct command_registration lpc2900_exec_command_handlers[] = { + { + .name = "signature", + .handler = &lpc2900_handle_signature_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "print device signature of flash bank", + }, + { + .name = "read_custom", + .handler = &lpc2900_handle_read_custom_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <filename>", + .help = "read customer information from index sector to file", + }, + { + .name = "password", + .handler = &lpc2900_handle_password_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <password>", + .help = "enter password to enable 'dangerous' options", + }, + { + .name = "write_custom", + .handler = &lpc2900_handle_write_custom_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <filename> [<type>]", + .help = "write customer info from file to index sector", + }, + { + .name = "secure_sector", + .handler = &lpc2900_handle_secure_sector_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <first> <last>", + .help = "activate sector security for a range of sectors", + }, + { + .name = "secure_jtag", + .handler = &lpc2900_handle_secure_jtag_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <level>", + .help = "activate JTAG security", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration lpc2900_command_handlers[] = { + { + .name = "lpc2900", + .mode = COMMAND_ANY, + .help = "LPC2900 flash command group", + .chain = lpc2900_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; /** * Register private command handlers. */ static int lpc2900_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2900_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2900", - NULL, COMMAND_ANY, NULL); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "signature", - &lpc2900_handle_signature_command, COMMAND_EXEC, - "<bank> | " - "print device signature of flash bank"); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "read_custom", - &lpc2900_handle_read_custom_command, COMMAND_EXEC, - "<bank> <filename> | " - "read customer information from index sector to file"); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "password", - &lpc2900_handle_password_command, COMMAND_EXEC, - "<bank> <password> | " - "enter password to enable 'dangerous' options"); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "write_custom", - &lpc2900_handle_write_custom_command, COMMAND_EXEC, - "<bank> <filename> [<type>] | " - "write customer info from file to index sector"); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_sector", - &lpc2900_handle_secure_sector_command, COMMAND_EXEC, - "<bank> <first> <last> | " - "activate sector security for a range of sectors"); - - COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_jtag", - &lpc2900_handle_secure_jtag_command, COMMAND_EXEC, - "<bank> <level> | " - "activate JTAG security"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, lpc2900_command_handlers); } commit a12a29c28a92f51861957a09d86177625220483b Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 lpc2000: use register_commands() diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index 4a934c0..896b794 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -776,16 +776,28 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command) return ERROR_OK; } +static const struct command_registration lpc2000_exec_command_handlers[] = { + { + .name = "part_id", + .handler = &lpc2000_handle_part_id_command, + .mode = COMMAND_EXEC, + .help = "print part id of lpc2000 flash bank <num>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration lpc2000_command_handlers[] = { + { + .name = "lpc2000", + .mode = COMMAND_ANY, + .help = "lpc2000 flash command group", + .chain = lpc2000_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int lpc2000_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2000_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2000", - NULL, COMMAND_ANY, NULL); - - COMMAND_REGISTER(cmd_ctx, lpc2000_cmd, "part_id", - lpc2000_handle_part_id_command, COMMAND_EXEC, - "print part id of lpc2000 flash bank <num>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, lpc2000_command_handlers); } struct flash_driver lpc2000_flash = { commit b90bf52be340d8ad2285f2f359174fbc1e31ce24 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 flash: use register_commands() Eliminates 'flash_cmd' global variable. diff --git a/src/flash/flash.c b/src/flash/flash.c index 7bc74ab..de95b62 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -78,7 +78,6 @@ struct flash_driver *flash_drivers[] = { }; struct flash_bank *flash_banks; -static struct command *flash_cmd; /* wafer thin wrapper for invoking the flash driver */ static int flash_driver_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count) @@ -1272,64 +1271,132 @@ int default_flash_blank_check(struct flash_bank *bank) return ERROR_OK; } +static const struct command_registration flash_exec_command_handlers[] = { + { + .name = "probe", + .handler = &handle_flash_probe_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "identify flash bank", + }, + { + .name = "info", + .handler = &handle_flash_info_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "print bank information", + }, + { + .name = "erase_check", + .handler = &handle_flash_erase_check_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "check erase state of sectors", + }, + { + .name = "protect_check", + .handler = &handle_flash_protect_check_command, + .mode = COMMAND_EXEC, + .usage = "<bank>", + .help = "check protection state of sectors", + }, + { + .name = "erase_sector", + .handler = &handle_flash_erase_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <first> <last>", + .help = "erase sectors", + }, + { + .name = "erase_address", + .handler = &handle_flash_erase_address_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <address> <length>", + .help = "erase address range", + + }, + { + .name = "fillw", + .handler = &handle_flash_fill_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <address> <word_pattern> <count>", + .help = "fill with pattern (no autoerase)", + }, + { + .name = "fillh", + .handler = &handle_flash_fill_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <address> <halfword_pattern> <count>", + .help = "fill with pattern", + }, + { + .name = "fillb", + .handler = &handle_flash_fill_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <address> <byte_pattern> <count>", + .help = "fill with pattern", + + }, + { + .name = "write_bank", + .handler = &handle_flash_write_bank_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <file> <offset>", + .help = "write binary data", + }, + { + .name = "write_image", + .handler = &handle_flash_write_image_command, + .mode = COMMAND_EXEC, + .usage = "<bank> [erase] [unlock] <file> [offset] [type]", + .help = "write an image to flash" + }, + { + .name = "protect", + .handler = &handle_flash_protect_command, + .mode = COMMAND_EXEC, + .usage = "<bank> <first> <last> <on | off>", + .help = "set protection of sectors", + }, + COMMAND_REGISTRATION_DONE +}; + int flash_init_drivers(struct command_context *cmd_ctx) { register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks"); - if (!flash_banks) return ERROR_OK; - COMMAND_REGISTER(cmd_ctx, flash_cmd, "info", - handle_flash_info_command, COMMAND_EXEC, - "print info about flash bank <num>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "probe", - handle_flash_probe_command, COMMAND_EXEC, - "identify flash bank <num>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_check", - handle_flash_erase_check_command, COMMAND_EXEC, - "check erase state of sectors in flash bank <num>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect_check", - handle_flash_protect_check_command, COMMAND_EXEC, - "check protection state of sectors in flash bank <num>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_sector", - handle_flash_erase_command, COMMAND_EXEC, - "erase sectors at <bank> <first> <last>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_address", - handle_flash_erase_address_command, COMMAND_EXEC, - "erase address range <address> <length>"); - - COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillw", - handle_flash_fill_command, COMMAND_EXEC, - "fill with pattern (no autoerase) <address> <word_pattern> <count>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillh", - handle_flash_fill_command, COMMAND_EXEC, - "fill with pattern <address> <halfword_pattern> <count>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillb", - handle_flash_fill_command, COMMAND_EXEC, - "fill with pattern <address> <byte_pattern> <count>"); - - COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_bank", - handle_flash_write_bank_command, COMMAND_EXEC, - "write binary data to <bank> <file> <offset>"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_image", - handle_flash_write_image_command, COMMAND_EXEC, - "write_image [erase] [unlock] <file> [offset] [type]"); - COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect", - handle_flash_protect_command, COMMAND_EXEC, - "set protection of sectors at <bank> <first> <last> <on | off>"); - - return ERROR_OK; + struct command *parent = command_find_in_context(cmd_ctx, "flash"); + return register_commands(cmd_ctx, parent, flash_exec_command_handlers); } + +static const struct command_registration flash_config_command_handlers[] = { + { + .name = "bank", + .handler = &handle_flash_bank_command, + .mode = COMMAND_CONFIG, + .usage = "<name> <driver> <base> <size> " + "<chip_width> <bus_width> <target> " + "[driver_options ...]", + .help = "Define a new bank with the given name, " + "using the specified NOR flash driver.", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration flash_command_handlers[] = { + { + .name = "flash", + .mode = COMMAND_ANY, + .help = "NOR flash command group", + .chain = flash_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + int flash_register_commands(struct command_context *cmd_ctx) { - flash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "flash", - NULL, COMMAND_ANY, NULL); - - COMMAND_REGISTER(cmd_ctx, flash_cmd, "bank", - handle_flash_bank_command, COMMAND_CONFIG, - "flash bank <driver> <base> <size> " - "<chip_width> <bus_width> <target> [driver_options ...]"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, flash_command_handlers); } commit 1765b103044179baa2d5036bb61710369ae59e70 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 ecos: use register_commands() diff --git a/src/flash/ecos.c b/src/flash/ecos.c index 381f858..f6f3307 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -338,8 +338,6 @@ static int ecosflash_probe(struct flash_bank *bank) static int ecosflash_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); - return ERROR_OK; } commit b595ab8b97ae15babe530a935bb5009cdb02fcd7 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 04:13:56 2009 -0800 cfi: use register_commands() diff --git a/src/flash/cfi.c b/src/flash/cfi.c index e743fe9..b92ecbd 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -591,12 +591,6 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size) static int cfi_register_commands(struct command_context *cmd_ctx) { - /*struct c... [truncated message content] |
From: Zach W. <zw...@us...> - 2009-11-25 19:57:03
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 8d46720cda288f498787a706bb2518e6f852b9f1 (commit) via fc2d9f87615b7a5562cb9cd58fb95953e5d89818 (commit) via 355a67303206fb8954827ab7e413f1d882149c90 (commit) via 9a31d66b3ff4b877d1f1125d24cbf127234f153a (commit) via 339e08baa5d000b1efe8c85ddd516d0b967992b2 (commit) via b1d034bf2f665cfa5633c8c6b46570d7ce6064a4 (commit) via 779bdbe797b9c25b9f297b4f29500e847baf28c3 (commit) via 3ab599a7e43af7350b380e7ffcc5fdcd75b42a65 (commit) via 30be874de8ee9d8269ce3441c92a15b96c68a398 (commit) via 0af32bb9381c9fe3f6be425c7fedfc88d4590178 (commit) via 48429dcfad4c05dc03fd94484da1078b30afd4f3 (commit) from e2f23c54373097098ef0b59377299d7382f4c58a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 8d46720cda288f498787a706bb2518e6f852b9f1 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 22:01:59 2009 -0800 remove register_callbacks from jtag interface Changes the jtag_interface->register_callbacks field to a list of commands to be registered. Changes callback to invocation of register_commands() with that command registration list. Removes all JTAG interface driver register_command callback functions, which the previous commits had converted into identical calls. diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c index c3f3279..d26482a 100644 --- a/src/jtag/amt_jtagaccel.c +++ b/src/jtag/amt_jtagaccel.c @@ -558,14 +558,9 @@ static const struct command_registration amtjtagaccel_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int amt_jtagaccel_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, amtjtagaccel_command_handlers); -} - struct jtag_interface amt_jtagaccel_interface = { .name = "amt_jtagaccel", - .register_commands = &amt_jtagaccel_register_commands, + .commands = amtjtagaccel_command_handlers, .init = &amt_jtagaccel_init, .quit = &amt_jtagaccel_quit, .speed = &amt_jtagaccel_speed, diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c index ef2b04f..46c3107 100644 --- a/src/jtag/arm-jtag-ew.c +++ b/src/jtag/arm-jtag-ew.c @@ -512,17 +512,15 @@ static const struct command_registration armjtagew_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int armjtagew_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, armjtagew_command_handlers); -} - struct jtag_interface armjtagew_interface = { .name = "arm-jtag-ew", + + .commands = armjtagew_command_handlers, + .execute_queue = &armjtagew_execute_queue, .speed = &armjtagew_speed, .khz = &armjtagew_khz, - .register_commands = &armjtagew_register_commands, + .init = &armjtagew_init, .quit = &armjtagew_quit, }; diff --git a/src/jtag/dummy.c b/src/jtag/dummy.c index 0516790..11b6f71 100644 --- a/src/jtag/dummy.c +++ b/src/jtag/dummy.c @@ -134,11 +134,6 @@ static int dummy_speed(int speed) return ERROR_OK; } -static int dummy_register_commands(struct command_context *cmd_ctx) -{ - return ERROR_OK; -} - static int dummy_init(void) { bitbang_interface = &dummy_bitbang; @@ -160,7 +155,6 @@ struct jtag_interface dummy_interface = { .execute_queue = &bitbang_execute_queue, .speed = &dummy_speed, - .register_commands = &dummy_register_commands, .khz = &dummy_khz, .speed_div = &dummy_speed_div, diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index d145505..73cbaf3 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -4009,15 +4009,9 @@ static const struct command_registration ft2232_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int ft2232_register_commands(struct command_context* cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, ft2232_command_handlers); -} - - struct jtag_interface ft2232_interface = { .name = "ft2232", - .register_commands = &ft2232_register_commands, + .commands = ft2232_command_handlers, .init = &ft2232_init, .quit = &ft2232_quit, .speed = &ft2232_speed, diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c index 0e495f9..b827fd5 100644 --- a/src/jtag/gw16012.c +++ b/src/jtag/gw16012.c @@ -573,14 +573,9 @@ static const struct command_registration gw16012_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int gw16012_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, gw16012_command_handlers); -} - struct jtag_interface gw16012_interface = { .name = "gw16012", - .register_commands = &gw16012_register_commands, + .commands = gw16012_command_handlers, .init = &gw16012_init, .quit = &gw16012_quit, .speed = &gw16012_speed, diff --git a/src/jtag/interface.h b/src/jtag/interface.h index 05e4048..d55782a 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -204,10 +204,8 @@ struct jtag_interface { /** * The interface driver may register additional commands to expose * additional features not covered by the standard command set. - * @param cmd_ctx The context in which commands should be registered. - * @returns ERROR_OK on success, or an error code on failure. */ - int (*register_commands)(struct command_context* cmd_ctx); + const struct command_registration *commands; /** * Interface driver must initalize any resources and connect to a diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 24fb0e8..9b2326b 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -644,18 +644,16 @@ static const struct command_registration jlink_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int jlink_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, jlink_command_handlers); -} - struct jtag_interface jlink_interface = { .name = "jlink", + + .commands = jlink_command_handlers, + .execute_queue = &jlink_execute_queue, .speed = &jlink_speed, .speed_div = &jlink_speed_div, .khz = &jlink_khz, - .register_commands = &jlink_register_commands, + .init = &jlink_init, .quit = &jlink_quit, }; diff --git a/src/jtag/parport.c b/src/jtag/parport.c index abf0d29..e5f5611 100644 --- a/src/jtag/parport.c +++ b/src/jtag/parport.c @@ -517,19 +517,17 @@ static const struct command_registration parport_command_handlers[] = { COMMAND_REGISTRATION_DONE }; +struct jtag_interface parport_interface = { + .name = "parport", -static int parport_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, parport_command_handlers); -} + .commands = parport_command_handlers, -struct jtag_interface parport_interface = { - .name = "parport", - .register_commands = parport_register_commands, - .init = parport_init, - .quit = parport_quit, - .khz = parport_khz, - .speed_div = parport_speed_div, - .speed = parport_speed, - .execute_queue = bitbang_execute_queue, -}; + .init = &parport_init, + .quit = &parport_quit, + + .khz = &parport_khz, + .speed_div = &parport_speed_div, + .speed = &parport_speed, + + .execute_queue = &bitbang_execute_queue, + }; diff --git a/src/jtag/presto.c b/src/jtag/presto.c index dc40750..f4e689c 100644 --- a/src/jtag/presto.c +++ b/src/jtag/presto.c @@ -750,11 +750,6 @@ static const struct command_registration presto_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int presto_jtag_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, presto_command_handlers); -} - static int presto_jtag_init(void) { if (presto_open(presto_serial) != ERROR_OK) @@ -792,11 +787,14 @@ static int presto_jtag_quit(void) struct jtag_interface presto_interface = { .name = "presto", + + .commands = presto_command_handlers, + .execute_queue = &bitq_execute_queue, .speed = &presto_jtag_speed, .khz = &presto_jtag_khz, .speed_div = &presto_jtag_speed_div, - .register_commands = &presto_jtag_register_commands, + .init = &presto_jtag_init, .quit = &presto_jtag_quit, }; diff --git a/src/jtag/rlink/rlink.c b/src/jtag/rlink/rlink.c index 6fb721d..bb33ad8 100644 --- a/src/jtag/rlink/rlink.c +++ b/src/jtag/rlink/rlink.c @@ -1568,49 +1568,6 @@ int rlink_khz( } -#if 0 -static -int -handle_dtc_directory_command( - struct command_context *cmd_ctx, - char *cmd, - char **args, - int argc -) { - if (argc != 1) { - LOG_ERROR("expected exactly one argument to rlink_dtc_directory <directory-path>"); - return(ERROR_INVALID_ARGUMENTS); - } - - printf("handle_dtc_directory_command called with \"%s\"\n", args[0]); - - return(ERROR_OK); -} -#endif - - -static -int rlink_register_commands(struct command_context *cmd_ctx) -{ - -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("rlink_register_commands called with cmd_ctx=%p\n", cmd_ctx); -#endif - -#if 0 - register_command( - cmd_ctx, NULL, - "rlink_dtc_directory", - handle_dtc_directory_command, - COMMAND_CONFIG, - "The directory in which to search for DTC load images" -); -#endif - - return ERROR_OK; -} - - static int rlink_init(void) { @@ -1848,7 +1805,6 @@ struct jtag_interface rlink_interface = .name = "rlink", .init = rlink_init, .quit = rlink_quit, - .register_commands = rlink_register_commands, .speed = rlink_speed, .speed_div = rlink_speed_div, .khz = rlink_khz, diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 81dbdb5..6b42021 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -636,9 +636,10 @@ COMMAND_HANDLER(handle_interface_command) if (strcmp(CMD_ARGV[0], jtag_interfaces[i]->name) != 0) continue; - if (NULL != jtag_interfaces[i]->register_commands) + if (NULL != jtag_interfaces[i]->commands) { - int retval = jtag_interfaces[i]->register_commands(CMD_CTX); + int retval = register_commands(CMD_CTX, NULL, + jtag_interfaces[i]->commands); if (ERROR_OK != retval) return retval; } diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c index 8287e84..cc3308f 100644 --- a/src/jtag/vsllink.c +++ b/src/jtag/vsllink.c @@ -1890,14 +1890,10 @@ static const struct command_registration vsllink_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -static int vsllink_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, vsllink_command_handlers); -} - struct jtag_interface vsllink_interface = { .name = "vsllink", - .register_commands = &vsllink_register_commands, + .commands = vsllink_command_handlers, + .init = &vsllink_init, .quit = &vsllink_quit, .khz = &vsllink_khz, commit fc2d9f87615b7a5562cb9cd58fb95953e5d89818 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 21:06:28 2009 -0800 vsllink: use register_commands() Use register_commands() with command registration array. diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c index 3526198..8287e84 100644 --- a/src/jtag/vsllink.c +++ b/src/jtag/vsllink.c @@ -1856,28 +1856,43 @@ static void vsllink_debug_buffer(uint8_t *buffer, int length) } #endif // _DEBUG_USB_COMMS_ || _DEBUG_JTAG_IO_ +static const struct command_registration vsllink_command_handlers[] = { + { + .name = "vsllink_usb_vid", + .handler = &vsllink_handle_usb_vid_command, + .mode = COMMAND_CONFIG, + }, + { + .name = "vsllink_usb_pid", + .handler = &vsllink_handle_usb_pid_command, + .mode = COMMAND_CONFIG, + }, + { + .name = "vsllink_usb_bulkin", + .handler = &vsllink_handle_usb_bulkin_command, + .mode = COMMAND_CONFIG, + }, + { + .name = "vsllink_usb_bulkout", + .handler = &vsllink_handle_usb_bulkout_command, + .mode = COMMAND_CONFIG, + }, + { + .name = "vsllink_usb_interface", + .handler = &vsllink_handle_usb_interface_command, + .mode = COMMAND_CONFIG, + }, + { + .name = "vsllink_mode", + .handler = &vsllink_handle_mode_command, + .mode = COMMAND_CONFIG, + }, + COMMAND_REGISTRATION_DONE +}; + static int vsllink_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_usb_vid", - vsllink_handle_usb_vid_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_usb_pid", - vsllink_handle_usb_pid_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_usb_bulkin", - vsllink_handle_usb_bulkin_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_usb_bulkout", - vsllink_handle_usb_bulkout_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_usb_interface", - vsllink_handle_usb_interface_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "vsllink_mode", - vsllink_handle_mode_command, COMMAND_CONFIG, - NULL); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, vsllink_command_handlers); } struct jtag_interface vsllink_interface = { commit 355a67303206fb8954827ab7e413f1d882149c90 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 21:02:28 2009 -0800 jtag: use register_commands() Use register commands with command registration array. diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index bd672b6..81dbdb5 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1413,66 +1413,129 @@ COMMAND_HANDLER(handle_tms_sequence_command) return ERROR_OK; } +static const struct command_registration jtag_command_handlers[] = { + { + .name = "interface", + .handler = &handle_interface_command, + .mode = COMMAND_CONFIG, + .help = "select a JTAG interface", + .usage = "<driver_name>", + }, + { + .name = "interface_list", + .handler = &handle_interface_list_command, + .mode = COMMAND_ANY, + .help = "list all built-in interfaces", + }, + { + .name = "jtag_khz", + .handler = &handle_jtag_khz_command, + .mode = COMMAND_ANY, + .help = "set maximum jtag speed (if supported)", + .usage = "<khz:0=rtck>", + }, + { + .name = "jtag_rclk", + .handler = &handle_jtag_rclk_command, + .mode = COMMAND_ANY, + .help = "set JTAG speed to RCLK or use fallback speed", + .usage = "<fallback_speed_khz>", + }, + { + .name = "reset_config", + .handler = &handle_reset_config_command, + .mode = COMMAND_ANY, + .help = "configure JTAG reset behavior", + .usage = "[none|trst_only|srst_only|trst_and_srst] " + "[srst_pulls_trst|trst_pulls_srst|combined|separate] " + "[srst_gates_jtag|srst_nogate] " + "[trst_push_pull|trst_open_drain] " + "[srst_push_pull|srst_open_drain]", + }, + { + .name = "jtag_nsrst_delay", + .handler = &handle_jtag_nsrst_delay_command, + .mode = COMMAND_ANY, + .help = "delay after deasserting srst in ms", + .usage = "<ms>", + }, + { + .name = "jtag_ntrst_delay", + .handler = &handle_jtag_ntrst_delay_command, + .mode = COMMAND_ANY, + .help = "delay after deasserting trst in ms", + .usage = "<ms>" + }, + { + .name = "jtag_nsrst_assert_width", + .handler = &handle_jtag_nsrst_assert_width_command, + .mode = COMMAND_ANY, + .help = "delay after asserting srst in ms", + .usage = "<ms>" + }, + { + .name = "jtag_ntrst_assert_width", + .handler = &handle_jtag_ntrst_assert_width_command, + .mode = COMMAND_ANY, + .help = "delay after asserting trst in ms", + .usage = "<ms>" + }, + { + .name = "scan_chain", + .handler = &handle_scan_chain_command, + .mode = COMMAND_EXEC, + .help = "print current scan chain configuration", + }, + { + .name = "jtag_reset", + .handler = &handle_jtag_reset_command, + .mode = COMMAND_EXEC, + .help = "toggle reset lines", + .usage = "<trst> <srst>", + }, + { + .name = "runtest", + .handler = &handle_runtest_command, + .mode = COMMAND_EXEC, + .help = "move to Run-Test/Idle, and execute <num_cycles>", + .usage = "<num_cycles>" + }, + { + .name = "irscan", + .handler = &handle_irscan_command, + .mode = COMMAND_EXEC, + .help = "execute IR scan", + .usage = "<device> <instr> [dev2] [instr2] ...", + }, + { + .name = "verify_ircapture", + .handler = &handle_verify_ircapture_command, + .mode = COMMAND_ANY, + .help = "verify value captured during Capture-IR", + .usage = "<enable | disable>", + }, + { + .name = "verify_jtag", + .handler = &handle_verify_jtag_command, + .mode = COMMAND_ANY, + .help = "verify value capture", + .usage = "<enable | disable>", + }, + { + .name = "tms_sequence", + .handler = &handle_tms_sequence_command, + .mode = COMMAND_ANY, + .help = "choose short(default) or long tms_sequence", + .usage = "<short | long>", + }, + COMMAND_REGISTRATION_DONE +}; + int jtag_register_commands(struct command_context *cmd_ctx) { register_jim(cmd_ctx, "jtag", jim_jtag_command, "perform jtag tap actions"); - COMMAND_REGISTER(cmd_ctx, NULL, "interface", - handle_interface_command, COMMAND_CONFIG, - "try to configure interface"); - COMMAND_REGISTER(cmd_ctx, NULL, "interface_list", - &handle_interface_list_command, COMMAND_ANY, - "list all built-in interfaces"); - - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_khz", - handle_jtag_khz_command, COMMAND_ANY, - "set maximum jtag speed (if supported); " - "parameter is maximum khz, or 0 for adaptive clocking (RTCK)."); - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_rclk", - handle_jtag_rclk_command, COMMAND_ANY, - "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed"); - COMMAND_REGISTER(cmd_ctx, NULL, "reset_config", - handle_reset_config_command, COMMAND_ANY, - "reset_config " - "[none|trst_only|srst_only|trst_and_srst] " - "[srst_pulls_trst|trst_pulls_srst|combined|separate] " - "[srst_gates_jtag|srst_nogate] " - "[trst_push_pull|trst_open_drain] " - "[srst_push_pull|srst_open_drain]"); - - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_nsrst_delay", - handle_jtag_nsrst_delay_command, COMMAND_ANY, - "jtag_nsrst_delay <ms> " - "- delay after deasserting srst in ms"); - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_ntrst_delay", - handle_jtag_ntrst_delay_command, COMMAND_ANY, - "jtag_ntrst_delay <ms> " - "- delay after deasserting trst in ms"); - - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_nsrst_assert_width", - handle_jtag_nsrst_assert_width_command, COMMAND_ANY, - "jtag_nsrst_assert_width <ms> " - "- delay after asserting srst in ms"); - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_ntrst_assert_width", - handle_jtag_ntrst_assert_width_command, COMMAND_ANY, - "jtag_ntrst_assert_width <ms> " - "- delay after asserting trst in ms"); - - COMMAND_REGISTER(cmd_ctx, NULL, "scan_chain", - handle_scan_chain_command, COMMAND_EXEC, - "print current scan chain configuration"); - - COMMAND_REGISTER(cmd_ctx, NULL, "jtag_reset", - handle_jtag_reset_command, COMMAND_EXEC, - "toggle reset lines <trst> <srst>"); - COMMAND_REGISTER(cmd_ctx, NULL, "runtest", - handle_runtest_command, COMMAND_EXEC, - "move to Run-Test/Idle, and execute <num_cycles>"); - COMMAND_REGISTER(cmd_ctx, NULL, "irscan", - handle_irscan_command, COMMAND_EXEC, - "execute IR scan <device> <instr> [dev2] [instr2] ..."); - register_jim(cmd_ctx, "drscan", Jim_Command_drscan, "execute DR scan <device> " "<num_bits> <value> <num_bits1> <value2> ..."); @@ -1484,18 +1547,7 @@ int jtag_register_commands(struct command_context *cmd_ctx) "<state1>,<state2>,<state3>... " "- move JTAG to state1 then to state2, state3, etc."); - COMMAND_REGISTER(cmd_ctx, NULL, "verify_ircapture", - handle_verify_ircapture_command, COMMAND_ANY, - "verify value captured during Capture-IR <enable | disable>"); - COMMAND_REGISTER(cmd_ctx, NULL, "verify_jtag", - handle_verify_jtag_command, COMMAND_ANY, - "verify value capture <enable | disable>"); - - COMMAND_REGISTER(cmd_ctx, NULL, "tms_sequence", - handle_tms_sequence_command, COMMAND_ANY, - "choose short(default) or long tms_sequence <short | long>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, jtag_command_handlers); } commit 9a31d66b3ff4b877d1f1125d24cbf127234f153a Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 21:00:23 2009 -0800 presto: use register_commands() Use register_commands() with command registration array. diff --git a/src/jtag/presto.c b/src/jtag/presto.c index f22bd9e..dc40750 100644 --- a/src/jtag/presto.c +++ b/src/jtag/presto.c @@ -739,11 +739,20 @@ COMMAND_HANDLER(presto_handle_serial_command) return ERROR_OK; } +static const struct command_registration presto_command_handlers[] = { + { + .name = "presto_serial", + .handler = &presto_handle_serial_command, + .mode = COMMAND_CONFIG, + .help = "configure serial port", + .usage = "<devname>", + }, + COMMAND_REGISTRATION_DONE +}; + static int presto_jtag_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "presto_serial", presto_handle_serial_command, - COMMAND_CONFIG, NULL); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, presto_command_handlers); } static int presto_jtag_init(void) commit 339e08baa5d000b1efe8c85ddd516d0b967992b2 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 20:17:52 2009 -0800 parport: use register_commands() Use register_commands() with a command registration array. diff --git a/src/jtag/parport.c b/src/jtag/parport.c index 4b4df09..abf0d29 100644 --- a/src/jtag/parport.c +++ b/src/jtag/parport.c @@ -482,28 +482,45 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command) return ERROR_OK; } -static int parport_register_commands(struct command_context *cmd_ctx) -{ - COMMAND_REGISTER(cmd_ctx, NULL, "parport_port", - parport_handle_parport_port_command, COMMAND_CONFIG, - "either the address of the I/O port " - "or the number of the '/dev/parport' device"); - - COMMAND_REGISTER(cmd_ctx, NULL, "parport_cable", - parport_handle_parport_cable_command, COMMAND_CONFIG, - "the layout of the parallel port cable " - "used to connect to the target"); - - COMMAND_REGISTER(cmd_ctx, NULL, "parport_write_on_exit", - parport_handle_write_on_exit_command, COMMAND_CONFIG, - "configure the parallel driver to write " - "a known value to the parallel interface"); +static const struct command_registration parport_command_handlers[] = { + { + .name = "parport_port", + .handler = &parport_handle_parport_port_command, + .mode = COMMAND_CONFIG, + .help = "either the address of the I/O port " + "or the number of the '/dev/parport' device", + .usage = "[<port|devname>]", + }, + { + .name = "parport_cable", + .handler = &parport_handle_parport_cable_command, + .mode = COMMAND_CONFIG, + .help = "the layout of the parallel port cable " + "used to connect to the target", + .usage = "[<layout>]", + }, + { + .name = "parport_write_on_exit", + .handler = &parport_handle_write_on_exit_command, + .mode = COMMAND_CONFIG, + .help = "configure the parallel driver to write " + "a known value to the parallel interface", + .usage = "[<on|off>]", + }, + { + .name = "parport_toggling_time", + .handler = &parport_handle_parport_toggling_time_command, + .mode = COMMAND_CONFIG, + .help = "time <ns> it takes for the hardware to toggle TCK", + .usage = "[<ns>]", + }, + COMMAND_REGISTRATION_DONE +}; - COMMAND_REGISTER(cmd_ctx, NULL, "parport_toggling_time", - parport_handle_parport_toggling_time_command, COMMAND_ANY, - "time <ns> it takes for the hardware to toggle TCK"); - return ERROR_OK; +static int parport_register_commands(struct command_context *cmd_ctx) +{ + return register_commands(cmd_ctx, NULL, parport_command_handlers); } struct jtag_interface parport_interface = { commit b1d034bf2f665cfa5633c8c6b46570d7ce6064a4 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 20:12:21 2009 -0800 jlink: use register_commands() Use register_commands() with command registration array. diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 1ca9c39..24fb0e8 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -627,16 +627,26 @@ COMMAND_HANDLER(jlink_handle_jlink_hw_jtag_command) return ERROR_OK; } +static const struct command_registration jlink_command_handlers[] = { + { + .name = "jlink_info", + .handler = &jlink_handle_jlink_info_command, + .mode = COMMAND_EXEC, + .help = "show jlink info", + }, + { + .name = "jlink_hw_jtag", + .handler = &jlink_handle_jlink_hw_jtag_command, + .mode = COMMAND_EXEC, + .help = "access J-Link HW JTAG command version", + .usage = "[2|3]", + }, + COMMAND_REGISTRATION_DONE +}; + static int jlink_register_commands(struct command_context *cmd_ctx) { - - COMMAND_REGISTER(cmd_ctx, NULL, "jlink_info", - &jlink_handle_jlink_info_command, COMMAND_EXEC, - "query jlink info"); - COMMAND_REGISTER(cmd_ctx, NULL, "jlink_hw_jtag", - &jlink_handle_jlink_hw_jtag_command, COMMAND_EXEC, - "set/get jlink hw jtag command version [2 | 3]"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, jlink_command_handlers); } struct jtag_interface jlink_interface = { commit 779bdbe797b9c25b9f297b4f29500e847baf28c3 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 20:11:58 2009 -0800 gw16012: use register_commands() Use register_commands() with command registration array. diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c index bc0e472..0e495f9 100644 --- a/src/jtag/gw16012.c +++ b/src/jtag/gw16012.c @@ -562,13 +562,20 @@ COMMAND_HANDLER(gw16012_handle_parport_port_command) return ERROR_OK; } +static const struct command_registration gw16012_command_handlers[] = { + { + .name = "parport_port", + .handler = &gw16012_handle_parport_port_command, + .mode = COMMAND_CONFIG, + .help = "configure the parallel port to use", + .usage = "<port_num>", + }, + COMMAND_REGISTRATION_DONE +}; + static int gw16012_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "parport_port", - gw16012_handle_parport_port_command, COMMAND_CONFIG, - NULL); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, gw16012_command_handlers); } struct jtag_interface gw16012_interface = { commit 3ab599a7e43af7350b380e7ffcc5fdcd75b42a65 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 20:06:50 2009 -0800 ft2232: use register_commands() Use register_commands() with a command registration array. diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index e560b22..d145505 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -3969,26 +3969,49 @@ static void ktlink_blink(void) buffer_write(high_direction); } +static const struct command_registration ft2232_command_handlers[] = { + { + .name = "ft2232_device_desc", + .handler = &ft2232_handle_device_desc_command, + .mode = COMMAND_CONFIG, + .help = "set the USB device description of the FTDI FT2232 device", + .usage = "<description>", + }, + { + .name = "ft2232_serial", + .handler = &ft2232_handle_serial_command, + .mode = COMMAND_CONFIG, + .help = "set the serial number of the FTDI FT2232 device", + .usage = "<serial#>", + }, + { + .name = "ft2232_layout", + .handler = &ft2232_handle_layout_command, + .mode = COMMAND_CONFIG, + .help = "set the layout of the FT2232 GPIO signals used " + "to control output-enables and reset signals", + .usage = "<layout>", + }, + { + .name = "ft2232_vid_pid", + .handler = &ft2232_handle_vid_pid_command, + .mode = COMMAND_CONFIG, + .help = "the vendor ID and product ID of the FTDI FT2232 device", + .usage = "<vid> <pid> [...]", + }, + { + .name = "ft2232_latency", + .handler = &ft2232_handle_latency_command, + .mode = COMMAND_CONFIG, + .help = "set the FT2232 latency timer to a new value", + .usage = "<vid> <pid> [...]", + }, + COMMAND_REGISTRATION_DONE +}; + static int ft2232_register_commands(struct command_context* cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "ft2232_device_desc", - ft2232_handle_device_desc_command, COMMAND_CONFIG, - "the USB device description of the FTDI FT2232 device"); - COMMAND_REGISTER(cmd_ctx, NULL, "ft2232_serial", - ft2232_handle_serial_command, COMMAND_CONFIG, - "the serial number of the FTDI FT2232 device"); - COMMAND_REGISTER(cmd_ctx, NULL, "ft2232_layout", - ft2232_handle_layout_command, COMMAND_CONFIG, - "the layout of the FT2232 GPIO signals used " - "to control output-enables and reset signals"); - COMMAND_REGISTER(cmd_ctx, NULL, "ft2232_vid_pid", - ft2232_handle_vid_pid_command, COMMAND_CONFIG, - "the vendor ID and product ID of the FTDI FT2232 device"); - COMMAND_REGISTER(cmd_ctx, NULL, "ft2232_latency", - ft2232_handle_latency_command, COMMAND_CONFIG, - "set the FT2232 latency timer to a new value"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, ft2232_command_handlers); } commit 30be874de8ee9d8269ce3441c92a15b96c68a398 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 19:58:07 2009 -0800 at91rm9200: use register_commands() Use register_commands() with command registration array. --- This module was broken by previous changes, but no one has complained. Are there still users for this modules? diff --git a/src/jtag/at91rm9200.c b/src/jtag/at91rm9200.c index 024dd6d..ff9f7a4 100644 --- a/src/jtag/at91rm9200.c +++ b/src/jtag/at91rm9200.c @@ -200,11 +200,18 @@ static int at91rm9200_handle_device_command(struct command_context *cmd_ctx, cha return ERROR_OK; } +static const struct command_registration at91rm9200_command_handlers[] = { + { + .name = "at91rm9200_device", + .handler = &at91rm9200_handle_device_command, + .mode = COMMAND_CONFIG, + .help = "query armjtagew info", + }, +}; + static int at91rm9200_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "at91rm9200_device", at91rm9200_handle_device_command, - COMMAND_CONFIG, NULL); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, at91rm9200_command_handlers); } static int at91rm9200_init(void) commit 0af32bb9381c9fe3f6be425c7fedfc88d4590178 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 19:56:02 2009 -0800 arm-jtag-ew: use register_commands() Uses register_commands() with command registration array. diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c index f239371..ef2b04f 100644 --- a/src/jtag/arm-jtag-ew.c +++ b/src/jtag/arm-jtag-ew.c @@ -502,12 +502,19 @@ COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command) return ERROR_OK; } +static const struct command_registration armjtagew_command_handlers[] = { + { + .name = "armjtagew_info", + .handler = &armjtagew_handle_armjtagew_info_command, + .mode = COMMAND_EXEC, + .help = "query armjtagew info", + }, + COMMAND_REGISTRATION_DONE +}; + static int armjtagew_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "armjtagew_info", - &armjtagew_handle_armjtagew_info_command, COMMAND_EXEC, - "query armjtagew info"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, armjtagew_command_handlers); } struct jtag_interface armjtagew_interface = { commit 48429dcfad4c05dc03fd94484da1078b30afd4f3 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 19:53:28 2009 -0800 amt_jtagaccel: use register_commands() Use register_commands() with command_registration array. diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c index 0aabdc9..c3f3279 100644 --- a/src/jtag/amt_jtagaccel.c +++ b/src/jtag/amt_jtagaccel.c @@ -540,16 +540,27 @@ COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command) return ERROR_OK; } +static const struct command_registration amtjtagaccel_command_handlers[] = { + { + .name = "parport_port", + .handler = &amt_jtagaccel_handle_parport_port_command, + .mode = COMMAND_CONFIG, + .help = "configure the parallel port to use", + .usage = "<port_num>", + }, + { + .name = "parport_port", + .handler = &amt_jtagaccel_handle_rtck_command, + .mode = COMMAND_CONFIG, + .help = "enable RTCK", + .usage = "<enable|disable>", + }, + COMMAND_REGISTRATION_DONE +}; + static int amt_jtagaccel_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "parport_port", - amt_jtagaccel_handle_parport_port_command, COMMAND_CONFIG, - NULL); - COMMAND_REGISTER(cmd_ctx, NULL, "rtck", - amt_jtagaccel_handle_rtck_command, COMMAND_CONFIG, - NULL); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, amtjtagaccel_command_handlers); } struct jtag_interface amt_jtagaccel_interface = { ----------------------------------------------------------------------- Summary of changes: src/jtag/amt_jtagaccel.c | 30 +++++--- src/jtag/arm-jtag-ew.c | 21 +++-- src/jtag/at91rm9200.c | 13 +++- src/jtag/dummy.c | 6 -- src/jtag/ft2232.c | 63 ++++++++++------ src/jtag/gw16012.c | 20 +++-- src/jtag/interface.h | 4 +- src/jtag/jlink.c | 32 +++++--- src/jtag/parport.c | 73 +++++++++++------- src/jtag/presto.c | 21 ++++-- src/jtag/rlink/rlink.c | 44 ----------- src/jtag/tcl.c | 191 +++++++++++++++++++++++++++++----------------- src/jtag/vsllink.c | 59 +++++++++------ 13 files changed, 328 insertions(+), 249 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-25 19:56:45
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via e2f23c54373097098ef0b59377299d7382f4c58a (commit) via 76b89755c994faa8ff0f646c722373ccb876f744 (commit) via 75e37b5348161c97285b808e792976870c383f4c (commit) via b4c4b5f71ef069a641adad541b42ef79ca43ac60 (commit) via 29772ec37293e7fbc6f11cc8a73b5d4d820707c7 (commit) via 8de1e7bd9eb7f5e1db7ea2f4cb03e73f442a1a12 (commit) via 1595fd7c4b6ea2e2fcd5f82e89a1f46dc8e525e8 (commit) via 16e0404777581e55bb42b95f5c9208b2c411debe (commit) via e7fd1d3d5031a98e56503c46baa0c2f23ac7d88c (commit) from 62e56496009796497665c1d06819c163589a3877 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit e2f23c54373097098ef0b59377299d7382f4c58a Author: Zachary T Welch <zw...@su...> Date: Mon Nov 23 09:30:02 2009 -0800 pld: use static registration instead of callback Remove register_callbacks from pld_device structure, using an array of command_registration records instead. diff --git a/src/pld/pld.c b/src/pld/pld.c index 421fc61..24afd07 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -74,17 +74,22 @@ COMMAND_HANDLER(handle_pld_device_command) struct pld_device *p, *c; /* register pld specific commands */ - if (pld_drivers[i]->register_commands(CMD_CTX) != ERROR_OK) - { - LOG_ERROR("couldn't register '%s' commands", CMD_ARGV[0]); - exit(-1); + int retval; + if (pld_drivers[i]->commands) { + retval = register_commands(CMD_CTX, NULL, + pld_drivers[i]->commands); + if (ERROR_OK != retval) + { + LOG_ERROR("couldn't register '%s' commands", CMD_ARGV[0]); + return ERROR_FAIL; + } } c = malloc(sizeof(struct pld_device)); c->driver = pld_drivers[i]; c->next = NULL; - int retval = CALL_COMMAND_HANDLER(pld_drivers[i]->pld_device_command, c); + retval = CALL_COMMAND_HANDLER(pld_drivers[i]->pld_device_command, c); if (ERROR_OK != retval) { LOG_ERROR("'%s' driver rejected pld device", CMD_ARGV[0]); diff --git a/src/pld/pld.h b/src/pld/pld.h index b183e3e..1ae775c 100644 --- a/src/pld/pld.h +++ b/src/pld/pld.h @@ -31,7 +31,7 @@ struct pld_driver { char *name; __PLD_DEVICE_COMMAND((*pld_device_command)); - int (*register_commands)(struct command_context *cmd_ctx); + const struct command_registration *commands; int (*load)(struct pld_device *pld_device, const char *filename); }; diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index 1025e61..77eb866 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -253,14 +253,9 @@ static const struct command_registration virtex2_command_handler[] = { COMMAND_REGISTRATION_DONE }; -static int virtex2_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, virtex2_command_handler); -} - struct pld_driver virtex2_pld = { .name = "virtex2", - .register_commands = &virtex2_register_commands, + .commands = virtex2_command_handler, .pld_device_command = &virtex2_pld_device_command, .load = &virtex2_load, }; commit 76b89755c994faa8ff0f646c722373ccb876f744 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 01:50:22 2009 -0800 pld: use register_commands() Updates core PLD and virtex2 commands to use register_commands(). diff --git a/src/pld/pld.c b/src/pld/pld.c index 021a8e6..421fc61 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -37,7 +37,6 @@ static struct pld_driver *pld_drivers[] = }; static struct pld_device *pld_devices; -static struct command *pld_cmd; struct pld_device *get_pld_device_by_num(int num) { @@ -184,26 +183,52 @@ COMMAND_HANDLER(handle_pld_load_command) return ERROR_OK; } +static const struct command_registration pld_exec_command_handlers[] = { + { + .name = "devices", + .handler = &handle_pld_devices_command, + .mode = COMMAND_EXEC, + .help = "list configured pld devices", + }, + { + .name = "load", + .handler = &handle_pld_load_command, + .mode = COMMAND_EXEC, + .help = "load configuration file into PLD", + .usage = "<device#> <file>", + }, + COMMAND_REGISTRATION_DONE +}; int pld_init(struct command_context *cmd_ctx) { if (!pld_devices) return ERROR_OK; - COMMAND_REGISTER(cmd_ctx, pld_cmd, "devices", - handle_pld_devices_command, COMMAND_EXEC, - "list configured pld devices"); - COMMAND_REGISTER(cmd_ctx, pld_cmd, "load", - handle_pld_load_command, COMMAND_EXEC, - "load configuration <file> into programmable logic device"); - - return ERROR_OK; + struct command *parent = command_find_in_context(cmd_ctx, "pld"); + return register_commands(cmd_ctx, parent, pld_exec_command_handlers); } +static const struct command_registration pld_config_command_handlers[] = { + { + .name = "device", + .mode = COMMAND_CONFIG, + .handler = &handle_pld_device_command, + .help = "configure a PLD device", + .usage = "<driver> ...", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration pld_command_handler[] = { + { + .name = "pld", + .mode = COMMAND_ANY, + .help = "programmable logic device commands", + + .chain = pld_config_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; int pld_register_commands(struct command_context *cmd_ctx) { - pld_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "pld", NULL, COMMAND_ANY, "programmable logic device commands"); - - COMMAND_REGISTER(cmd_ctx, pld_cmd, "device", handle_pld_device_command, COMMAND_CONFIG, NULL); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, pld_command_handler); } diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index 527434a..1025e61 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -233,16 +233,29 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command) return ERROR_OK; } +static const struct command_registration virtex2_exec_command_handlers[] = { + { + .name = "read_stat", + .mode = COMMAND_EXEC, + .handler = &virtex2_handle_read_stat_command, + .help = "read status register", + .usage = "<device_id>", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration virtex2_command_handler[] = { + { + .name = "virtex2", + .mode = COMMAND_ANY, + .help = "Virtex-II specific commands", + .chain = virtex2_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + static int virtex2_register_commands(struct command_context *cmd_ctx) { - struct command *virtex2_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "virtex2", - NULL, COMMAND_ANY, "virtex2 specific commands"); - - COMMAND_REGISTER(cmd_ctx, virtex2_cmd, "read_stat", - &virtex2_handle_read_stat_command, COMMAND_EXEC, - "read Virtex-II status register"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, virtex2_command_handler); } struct pld_driver virtex2_pld = { commit 75e37b5348161c97285b808e792976870c383f4c Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 01:11:18 2009 -0800 {,x}svf: use register_commands() Use register_commands() for registering {,x}svf commands. diff --git a/src/svf/svf.c b/src/svf/svf.c index 1fc3835..e01b933 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -1460,11 +1460,18 @@ static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str) return ERROR_OK; } +static const struct command_registration svf_command_handlers[] = { + { + .name = "svf", + .handler = &handle_svf_command, + .mode = COMMAND_EXEC, + .help = "Runs a SVF file.", + .usage = "<file>", + }, + COMMAND_REGISTRATION_DONE +}; + int svf_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "svf", - &handle_svf_command, COMMAND_EXEC, - "run svf <file>"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, svf_command_handlers); } diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 82ddb84..f5c89d4 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -1050,13 +1050,23 @@ COMMAND_HANDLER(handle_xsvf_command) return ERROR_OK; } +static const struct command_registration xsvf_command_handlers[] = { + { + .name = "xsvf", + .handler = &handle_xsvf_command, + .mode = COMMAND_EXEC, + .help = "Runs a XSVF file. If 'virt2' is given, xruntest " + "counts are interpreted as TCK cycles rather than " + "as microseconds. Without the 'quiet' option, all " + "comments, retries, and mismatches will be reported.", + .usage = "<file> [virt2] [quiet]", + }, + COMMAND_REGISTRATION_DONE +}; + int xsvf_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "xsvf", - &handle_xsvf_command, COMMAND_EXEC, - "run xsvf <file> [virt2] [quiet]"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, xsvf_command_handlers); } #if 0 /* this comment style used to try and keep uncrustify from adding * at begin of line */ commit b4c4b5f71ef069a641adad541b42ef79ca43ac60 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 14:42:05 2009 -0800 server: use register_commands Converts server directory to use new command registration paradigm. diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index be1f8db..cb14cc3 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2326,27 +2326,55 @@ COMMAND_HANDLER(handle_gdb_breakpoint_override_command) return ERROR_OK; } -int gdb_register_commands(struct command_context *command_context) +static const struct command_registration gdb_command_handlers[] = { + { + .name = "gdb_sync", + .handler = &handle_gdb_sync_command, + .mode = COMMAND_ANY, + .help = "next stepi will return immediately allowing " + "GDB to fetch register state without affecting " + "target state", + }, + { + .name = "gdb_port", + .handler = &handle_gdb_port_command, + .mode = COMMAND_ANY, + .help = "daemon configuration command gdb_port", + .usage = "<port>", + }, + { + .name = "gdb_memory_map", + .handler = &handle_gdb_memory_map_command, + .mode = COMMAND_CONFIG, + .help = "enable or disable memory map", + .usage = "enable|disable" + }, + { + .name = "gdb_flash_program", + .handler = &handle_gdb_flash_program_command, + .mode = COMMAND_CONFIG, + .help = "enable or disable flash program", + .usage = "enable|disable" + }, + { + .name = "gdb_report_data_abort", + .handler = &handle_gdb_report_data_abort_command, + .mode = COMMAND_CONFIG, + .help = "enable or disable reporting data aborts", + .usage = "enable|disable" + }, + { + .name = "gdb_breakpoint_override", + .handler = &handle_gdb_breakpoint_override_command, + .mode = COMMAND_EXEC, + .help = "force type of breakpoint " + "used by gdb 'break' commands.", + .usage = "hard|soft|disable", + }, + COMMAND_REGISTRATION_DONE +}; + +int gdb_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(command_context, NULL, "gdb_sync", - handle_gdb_sync_command, COMMAND_ANY, - "next stepi will return immediately allowing GDB to " - "fetch register state without affecting target state"); - COMMAND_REGISTER(command_context, NULL, "gdb_port", - handle_gdb_port_command, COMMAND_ANY, - "daemon configuration command gdb_port"); - COMMAND_REGISTER(command_context, NULL, "gdb_memory_map", - handle_gdb_memory_map_command, COMMAND_CONFIG, - "enable or disable memory map"); - COMMAND_REGISTER(command_context, NULL, "gdb_flash_program", - handle_gdb_flash_program_command, COMMAND_CONFIG, - "enable or disable flash program"); - COMMAND_REGISTER(command_context, NULL, "gdb_report_data_abort", - handle_gdb_report_data_abort_command, COMMAND_CONFIG, - "enable or disable reporting data aborts"); - COMMAND_REGISTER(command_context, NULL, "gdb_breakpoint_override", - handle_gdb_breakpoint_override_command, COMMAND_EXEC, - "hard/soft/disable - force type of breakpoint " - "used by gdb 'break' commands."); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, gdb_command_handlers); } diff --git a/src/server/server.c b/src/server/server.c index 5be1316..50bc00e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -539,16 +539,21 @@ COMMAND_HANDLER(handle_shutdown_command) return ERROR_COMMAND_CLOSE_CONNECTION; } -int server_register_commands(struct command_context *context) +static const struct command_registration server_command_handlers[] = { + { + .name = "shutdown", + .handler = &handle_shutdown_command, + .mode = COMMAND_ANY, + .help = "shut the server down", + }, + COMMAND_REGISTRATION_DONE +}; + +int server_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(context, NULL, "shutdown", - handle_shutdown_command, COMMAND_ANY, - "shut the server down"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, server_command_handlers); } - SERVER_PORT_COMMAND() { switch (CMD_ARGC) { diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index a12176e..22469a4 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -175,10 +175,19 @@ COMMAND_HANDLER(handle_tcl_port_command) return CALL_COMMAND_HANDLER(server_port_command, &tcl_port); } +static const struct command_registration tcl_command_handlers[] = { + { + .name = "tcl_port", + .handler = &handle_tcl_port_command, + .mode = COMMAND_CONFIG, + .help = "port on which to listen " + "for incoming TCL syntax", + .usage = "<port>", + }, + COMMAND_REGISTRATION_DONE +}; + int tcl_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "tcl_port", - handle_tcl_port_command, COMMAND_CONFIG, - "port on which to listen for incoming TCL syntax"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, tcl_command_handlers); } diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index c52119d..8a86efa 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -616,17 +616,25 @@ COMMAND_HANDLER(handle_exit_command) return ERROR_COMMAND_CLOSE_CONNECTION; } -int telnet_register_commands(struct command_context *command_context) +static const struct command_registration telnet_command_handlers[] = { + { + .name = "exit", + .handler = &handle_exit_command, + .mode = COMMAND_EXEC, + .help = "exit telnet session", + }, + { + .name = "telnet_port", + .handler = &handle_telnet_port_command, + .mode = COMMAND_ANY, + .help = "port on which to listen " + "for incoming telnet connections", + .usage = "<port>", + }, + COMMAND_REGISTRATION_DONE +}; + +int telnet_register_commands(struct command_context *cmd_ctx) { - COMMAND_REGISTER(command_context, NULL, "exit", - &handle_exit_command, COMMAND_EXEC, - "exit telnet session"); - - COMMAND_REGISTER(command_context, NULL, "telnet_port", - &handle_telnet_port_command, COMMAND_ANY, - "port on which to listen for incoming telnet connections"); - - return ERROR_OK; + return register_commands(cmd_ctx, NULL, telnet_command_handlers); } - - commit 29772ec37293e7fbc6f11cc8a73b5d4d820707c7 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 15:52:18 2009 -0800 log: use register_commands() Use register_commands() for logging callbacks. Improve help and add proper usage. diff --git a/src/helper/log.c b/src/helper/log.c index b1352a3..3799fb3 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -316,15 +316,29 @@ COMMAND_HANDLER(handle_log_output_command) return ERROR_OK; } +static struct command_registration log_command_handlers[] = { + { + .name = "log_output", + .handler = &handle_log_output_command, + .mode = COMMAND_ANY, + .help = "redirect logging to a file (default: stderr)", + .usage = "<file_name>", + }, + { + .name = "debug_level", + .handler = &handle_debug_level_command, + .mode = COMMAND_ANY, + .help = "sets the verbosity level of debugging output", + .usage = "<level:0-3>", + }, + COMMAND_REGISTRATION_DONE +}; + int log_register_commands(struct command_context *cmd_ctx) { start = timeval_ms(); - COMMAND_REGISTER(cmd_ctx, NULL, "log_output", handle_log_output_command, - COMMAND_ANY, "redirect logging to <file> (default: stderr)"); - COMMAND_REGISTER(cmd_ctx, NULL, "debug_level", handle_debug_level_command, - COMMAND_ANY, "adjust debug level <0-3>"); - return ERROR_OK; + return register_commands(cmd_ctx, NULL, log_command_handlers); } int log_init(struct command_context *cmd_ctx) commit 8de1e7bd9eb7f5e1db7ea2f4cb03e73f442a1a12 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 15:47:08 2009 -0800 ioutil: use register_commands() Use table instead of individual calls. Add proper usage information. diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 52ecb9f..58521ee 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -643,27 +643,55 @@ static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, int argc, } +static const struct command_registration ioutil_command_handlers[] = { + { + .name = "rm", + .handler = &handle_rm_command, + .mode = COMMAND_ANY, + .help = "remove file", + .usage= "<file_name>", + }, + { + .name = "cat", + .handler = &handle_cat_command, + .mode = COMMAND_ANY, + .help = "display file content", + .usage= "<file_name>", + }, + { + .name = "trunc", + .handler = &handle_trunc_command, + .mode = COMMAND_ANY, + .help = "truncate a file 0 size", + .usage= "<file_name>", + }, + { + .name = "cp", + .handler = &handle_cp_command, + .mode = COMMAND_ANY, + .help = "copy a file", + .usage = "<src> <dst>", + }, + { + .name = "append_file", + .handler = &handle_append_command, + .mode = COMMAND_ANY, + .help = "append a variable number of strings to a file", + .usage= "<file_name> [<string> ...]", + }, + { + .name = "meminfo", + .handler = &handle_meminfo_command, + .mode = COMMAND_ANY, + .help = "display available ram memory", + }, + COMMAND_REGISTRATION_DONE +}; int ioutil_init(struct command_context *cmd_ctx) { - COMMAND_REGISTER(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY, - "remove file"); - - COMMAND_REGISTER(cmd_ctx, NULL, "cat", handle_cat_command, COMMAND_ANY, - "display file content"); - - COMMAND_REGISTER(cmd_ctx, NULL, "trunc", handle_trunc_command, COMMAND_ANY, - "truncate a file to 0 size"); - - COMMAND_REGISTER(cmd_ctx, NULL, "cp", handle_cp_command, - COMMAND_ANY, "copy a file <from> <to>"); - - COMMAND_REGISTER(cmd_ctx, NULL, "append_file", handle_append_command, - COMMAND_ANY, "append a variable number of strings to a file"); - - COMMAND_REGISTER(cmd_ctx, NULL, "meminfo", handle_meminfo_command, - COMMAND_ANY, "display available ram memory"); + register_commands(cmd_ctx, NULL, ioutil_command_handlers); Jim_CreateCommand(interp, "rm", zylinjtag_Jim_Command_rm, NULL, NULL); commit 1595fd7c4b6ea2e2fcd5f82e89a1f46dc8e525e8 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 16:58:45 2009 -0800 openocd: use register_commands() Use register_commands() for top-level version and init command. diff --git a/src/openocd.c b/src/openocd.c index 379373c..63289e4 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -159,6 +159,23 @@ COMMAND_HANDLER(handle_init_command) return ERROR_OK; } +static const struct command_registration openocd_command_handlers[] = { + { + .name = "version", + .handler = &handle_version_command, + .mode = COMMAND_EXEC, + .help = "show program version", + }, + { + .name = "init", + .handler = &handle_init_command, + .mode = COMMAND_ANY, + .help = "Initializes configured targets and servers. " + "If called more than once, does nothing.", + }, + COMMAND_REGISTRATION_DONE +}; + struct command_context *global_cmd_ctx; /// src/hello.c gives a simple example for writing new command modules @@ -171,9 +188,7 @@ struct command_context *setup_command_handler(void) global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl); - COMMAND_REGISTER(cmd_ctx, NULL, "version", handle_version_command, - COMMAND_EXEC, "show OpenOCD version"); - + register_commands(cmd_ctx, NULL, openocd_command_handlers); /* register subsystem commands */ hello_register_commands(cmd_ctx); server_register_commands(cmd_ctx); @@ -198,9 +213,6 @@ struct command_context *setup_command_handler(void) LOG_OUTPUT(OPENOCD_VERSION "\n"); - COMMAND_REGISTER(cmd_ctx, NULL, "init", handle_init_command, - COMMAND_ANY, "initializes target and servers - nop on subsequent invocations"); - return cmd_ctx; } commit 16e0404777581e55bb42b95f5c9208b2c411debe Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 15:52:12 2009 -0800 demonstrate chaining with foo commands Use the new command registration chaining capabilities to eliminate the foo_register_commands helper, folding its remaining command handler setup into the hello_command_handlers registration array. diff --git a/src/hello.c b/src/hello.c index 6f02494..9a1bf92 100644 --- a/src/hello.c +++ b/src/hello.c @@ -75,16 +75,6 @@ static const struct command_registration foo_command_handlers[] = { COMMAND_REGISTRATION_DONE }; -int foo_register_commands(struct command_context *cmd_ctx) -{ - // register several commands under the foo command - struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "foo", - NULL, COMMAND_ANY, "example command handler skeleton"); - - - return register_commands(cmd_ctx, cmd, foo_command_handlers); -} - static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name) { if (CMD_ARGC > 1) @@ -119,12 +109,17 @@ static const struct command_registration hello_command_handlers[] = { .help = "prints a warm welcome", .usage = "[<name>]", }, + { + .name = "foo", + .mode = COMMAND_ANY, + .help = "example command handler skeleton", + + .chain = foo_command_handlers, + }, COMMAND_REGISTRATION_DONE }; int hello_register_commands(struct command_context *cmd_ctx) { - foo_register_commands(cmd_ctx); - return register_commands(cmd_ctx, NULL, hello_command_handlers); } commit e7fd1d3d5031a98e56503c46baa0c2f23ac7d88c Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 13:49:00 2009 -0800 hello: use register_commands() Use new register_commands() with command registration table. diff --git a/src/hello.c b/src/hello.c index 8c97a40..6f02494 100644 --- a/src/hello.c +++ b/src/hello.c @@ -53,24 +53,36 @@ COMMAND_HANDLER(handle_flag_command) &foo_flag, "foo flag"); } +static const struct command_registration foo_command_handlers[] = { + { + .name = "bar", + .handler = &handle_foo_command, + .mode = COMMAND_ANY, + .help = "<address> [enable|disable] - an example command", + }, + { + .name = "baz", + .handler = &handle_foo_command, + .mode = COMMAND_ANY, + .help = "<address> [enable|disable] - a sample command", + }, + { + .name = "flag", + .handler = &handle_flag_command, + .mode = COMMAND_ANY, + .help = "[on|off] - set a flag", + }, + COMMAND_REGISTRATION_DONE +}; + int foo_register_commands(struct command_context *cmd_ctx) { // register several commands under the foo command struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "foo", - NULL, COMMAND_ANY, "foo: command handler skeleton"); + NULL, COMMAND_ANY, "example command handler skeleton"); - COMMAND_REGISTER(cmd_ctx, cmd, "bar", - &handle_foo_command, COMMAND_ANY, - "<address> [enable|disable] - an example command"); - COMMAND_REGISTER(cmd_ctx, cmd, "baz", - &handle_foo_command, COMMAND_ANY, - "<address> [enable|disable] - a sample command"); - COMMAND_REGISTER(cmd_ctx, cmd, "flag", - &handle_flag_command, COMMAND_ANY, - "[on|off] - set a flag"); - - return ERROR_OK; + return register_commands(cmd_ctx, cmd, foo_command_handlers); } static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name) @@ -99,12 +111,20 @@ COMMAND_HANDLER(handle_hello_command) return retval; } +static const struct command_registration hello_command_handlers[] = { + { + .name = "hello", + .handler = &handle_hello_command, + .mode = COMMAND_ANY, + .help = "prints a warm welcome", + .usage = "[<name>]", + }, + COMMAND_REGISTRATION_DONE +}; + int hello_register_commands(struct command_context *cmd_ctx) { foo_register_commands(cmd_ctx); - struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "hello", - &handle_hello_command, COMMAND_ANY, - "[<name>] - prints a warm welcome"); - return cmd ? ERROR_OK : -ENOMEM; + return register_commands(cmd_ctx, NULL, hello_command_handlers); } ----------------------------------------------------------------------- Summary of changes: src/hello.c | 65 ++++++++++++++++++++++++--------------- src/helper/ioutil.c | 62 +++++++++++++++++++++++++++---------- src/helper/log.c | 24 +++++++++++--- src/openocd.c | 24 +++++++++++---- src/pld/pld.c | 68 ++++++++++++++++++++++++++++++----------- src/pld/pld.h | 2 +- src/pld/virtex2.c | 32 ++++++++++++------- src/server/gdb_server.c | 72 ++++++++++++++++++++++++++++++------------- src/server/server.c | 19 +++++++---- src/server/tcl_server.c | 17 ++++++++-- src/server/telnet_server.c | 32 ++++++++++++------- src/svf/svf.c | 17 +++++++--- src/xsvf/xsvf.c | 20 +++++++++--- 13 files changed, 314 insertions(+), 140 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-25 19:56:16
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 62e56496009796497665c1d06819c163589a3877 (commit) via 769fbfa058946e1581d5f9ad75d17947d1ee9ff1 (commit) via 4c54c27da774f8035a04f3b091fcfc5661253a0e (commit) via 60ba4641d61ba65943ac7a8c800e82d6665ee11f (commit) via 607634f967cf25630860794847dea770eb17a8f4 (commit) via 25a7ac2c756c78603c9c99d06f55717440409a23 (commit) via d107f71c5079dbe2a023276367b805397d1245c4 (commit) via 2461855494cd045567c15c502ba215caffb37ce3 (commit) via 69076057dde9f4336b54fb4da677da8fe5da66bd (commit) via 833e7f5248778bcb31b4db1a1b91160995415203 (commit) via f7e1f2df74b599903a6fb2d2ace94c3f1ef06097 (commit) via 47cb10217a7bc4b97fa169a821db05f40bc2e51d (commit) from b6210907ea584095cdede663f695eb8afeecef14 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 62e56496009796497665c1d06819c163589a3877 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 19:55:50 2009 -0800 rewrite 'unknown' command dispatching in C Rewrite the magical 'unknown' command in C as a Jim handler, allowing it to dispatch commands to any level in the tree. diff --git a/src/helper/command.c b/src/helper/command.c index 54bfb96..dd10965 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -853,6 +853,70 @@ COMMAND_HANDLER(handle_usage_command) return CALL_COMMAND_HANDLER(command_help_show, c, 0, false); } +static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, + struct command *head, struct command **out) +{ + if (0 == argc) + return argc; + struct command *c = command_find(head, Jim_GetString(argv[0], NULL)); + if (NULL == c) + return argc; + *out = c; + return command_unknown_find(--argc, ++argv, (*out)->children, out); +} + +static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + const char *cmd_name = Jim_GetString(argv[0], NULL); + script_debug(interp, cmd_name, argc - 1, argv + 1); + + struct command_context *cmd_ctx = current_command_context(); + struct command *c = cmd_ctx->commands; + int remaining = command_unknown_find(argc - 1, argv + 1, c, &c); + // if nothing could be consumed, then it's really an unknown command + if (remaining == argc - 1) + { + const char *cmd = Jim_GetString(argv[1], NULL); + LOG_ERROR("Unknown command:\n %s", cmd); + return JIM_OK; + } + + bool found = true; + Jim_Obj *const *start; + unsigned count; + if (c->handler) + { + // include the command name in the list + count = remaining + 1; + start = argv + (argc - remaining - 1); + } + else + { + c = command_find(cmd_ctx->commands, "help"); + if (NULL == c) + { + LOG_ERROR("unknown command, but help is missing too"); + return JIM_ERR; + } + count = argc - remaining; + start = argv; + found = false; + } + + unsigned nwords; + const char **words = script_command_args_alloc(count, start, &nwords); + if (NULL == words) + return JIM_ERR; + + int retval = run_command(cmd_ctx, c, words, nwords); + + script_command_args_free(words, nwords); + + if (!found && ERROR_OK == retval) + retval = ERROR_FAIL; + + return retval; +} int help_add_command(struct command_context *cmd_ctx, struct command *parent, const char *cmd_name, const char *help_text, const char *usage) @@ -1032,6 +1096,7 @@ struct command_context* command_init(const char *startup_tcl) Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS", Jim_NewStringObj(interp, HostOs , strlen(HostOs))); + Jim_CreateCommand(interp, "unknown", &command_unknown, NULL, NULL); Jim_CreateCommand(interp, "ocd_find", jim_find, NULL, NULL); Jim_CreateCommand(interp, "echo", jim_echo, NULL, NULL); Jim_CreateCommand(interp, "capture", jim_capture, NULL, NULL); diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 845198a..ede8cdb 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -44,23 +44,6 @@ proc cmd_help {cmdname h indent} { } } -# If a fn is unknown to Tcl, we try to execute it as an OpenOCD command -# -# We also support two level commands. "flash banks" is translated to -# flash_banks -proc unknown {args} { - # do the name mangling from "flash banks" to "flash_banks" - if {[llength $args]>=2} { - set cmd_name "[lindex $args 0]_[lindex $args 1]" - if {[catch {info body $cmd_name}]==0} { - # the command exists, try it... - return [eval "$cmd_name [lrange $args 2 end]"] - } - } - # This really is an unknown command. - return -code error "Unknown command: $args" -} - # Try flipping / and \ to find file if the filename does not # match the precise spelling proc find {filename} { commit 769fbfa058946e1581d5f9ad75d17947d1ee9ff1 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 01:48:55 2009 -0800 add public API for locating commands Allow other modules to find a command, primarily for the purpose of registering and unregistering subcommands. diff --git a/src/helper/command.c b/src/helper/command.c index af481cd..54bfb96 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -193,6 +193,16 @@ static struct command *command_find(struct command *head, const char *name) } return NULL; } +struct command *command_find_in_context(struct command_context *cmd_ctx, + const char *name) +{ + return command_find(cmd_ctx->commands, name); +} +struct command *command_find_in_parent(struct command *parent, + const char *name) +{ + return command_find(parent->children, name); +} /** * Add the command into the linked list, sorted by name. diff --git a/src/helper/command.h b/src/helper/command.h index 6e3e93a..2edeca9 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -281,6 +281,11 @@ int unregister_command(struct command_context *cmd_ctx, int unregister_all_commands(struct command_context *cmd_ctx, struct command *parent); +struct command *command_find_in_context(struct command_context *cmd_ctx, + const char *name); +struct command *command_find_in_parent(struct command *parent, + const char *name); + void command_set_output_handler(struct command_context* context, command_output_handler_t output_handler, void *priv); commit 4c54c27da774f8035a04f3b091fcfc5661253a0e Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 20:00:37 2009 -0800 refactor script_command context grabbing Move command context acquisition to current_command_context() for re-use. diff --git a/src/helper/command.c b/src/helper/command.c index b81d2d1..af481cd 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -108,11 +108,24 @@ static const char **script_command_args_alloc( return words; } +static struct command_context *current_command_context(void) +{ + /* grab the command context from the associated data */ + struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); + if (NULL == cmd_ctx) + { + /* Tcl can invoke commands directly instead of via command_run_line(). This would + * happen when the Jim Tcl interpreter is provided by eCos. + */ + cmd_ctx = global_cmd_ctx; + } + return cmd_ctx; +} + static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { /* the private data is stashed in the interp structure */ struct command *c; - struct command_context *context; int retval; /* DANGER!!!! be careful what we invoke here, since interp->cmdPrivData might @@ -136,16 +149,6 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (NULL == words) return JIM_ERR; - /* grab the command context from the associated data */ - context = Jim_GetAssocData(interp, "context"); - if (context == NULL) - { - /* Tcl can invoke commands directly instead of via command_run_line(). This would - * happen when the Jim Tcl interpreter is provided by eCos. - */ - context = global_cmd_ctx; - } - /* capture log output and return it */ Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); /* a garbage collect can happen, so we need a reference count to this object */ @@ -153,7 +156,8 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) log_add_callback(tcl_output, tclOutput); - retval = run_command(context, c, (const char **)words, nwords); + struct command_context *cmd_ctx = current_command_context(); + retval = run_command(cmd_ctx, c, (const char **)words, nwords); log_remove_callback(tcl_output, tclOutput); commit 60ba4641d61ba65943ac7a8c800e82d6665ee11f Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 13:59:51 2009 -0800 add command registration chaining Adds the ability to chain registration structures. Modules can define a command with the 'chain' and 'num_chain' fields defined in their registration table, and the register_commands() function will initialize these commands. If the registration record creates a new command, then the chained commands are created under it; otherwise, they are created in the same context as the other commands (i.e. the parent argument). diff --git a/src/helper/command.c b/src/helper/command.c index 9cc996c..b81d2d1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -331,18 +331,36 @@ struct command* register_command(struct command_context *context, int register_commands(struct command_context *cmd_ctx, struct command *parent, const struct command_registration *cmds) { + int retval = ERROR_OK; unsigned i; - for (i = 0; cmds[i].name; i++) + for (i = 0; cmds[i].name || cmds[i].chain; i++) { - struct command *c = register_command(cmd_ctx, parent, cmds + i); - if (NULL != c) - continue; + const struct command_registration *cr = cmds + i; + struct command *c = NULL; + if (NULL != cr->name) + { + c = register_command(cmd_ctx, parent, cr); + if (NULL == c) + { + retval = ERROR_FAIL; + break; + } + } + if (NULL != cr->chain) + { + struct command *p = c ? : parent; + retval = register_commands(cmd_ctx, p, cr->chain); + if (ERROR_OK != retval) + break; + } + } + if (ERROR_OK != retval) + { for (unsigned j = 0; j < i; j++) unregister_command(cmd_ctx, parent, cmds[j].name); - return ERROR_FAIL; } - return ERROR_OK; + return retval; } int unregister_all_commands(struct command_context *context, diff --git a/src/helper/command.h b/src/helper/command.h index 7baa92d..6e3e93a 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -202,10 +202,18 @@ struct command_registration { const char *help; /// a string listing the options and arguments, required or optional const char *usage; + + /** + * If non-NULL, the commands in @c chain will be registered in + * the same context and scope of this registration record. + * This allows modules to inherit lists commands from other + * modules. + */ + const struct command_registration *chain; }; /// Use this as the last entry in an array of command_registration records. -#define COMMAND_REGISTRATION_DONE { .name = NULL } +#define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL } /** * Register a command @c handler that can be called from scripts during @@ -238,7 +246,10 @@ struct command* register_command(struct command_context *cmd_ctx, /** * Register one or more commands in the specified context, as children - * of @c parent (or top-level commends, if NULL). + * of @c parent (or top-level commends, if NULL). In a registration's + * record contains a non-NULL @c chain member and name is NULL, the + * commands on the chain will be registered in the same context. + * Otherwise, the chained commands are added as children of the command. * * @param cmd_ctx The command_context in which to register the command. * @param parent Register this command as a child of this, or NULL to commit 607634f967cf25630860794847dea770eb17a8f4 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 13:33:32 2009 -0800 more command registration refactoring Split out the handler registration into its own function, and add a few obviously missing NULL pointer error checking. diff --git a/src/helper/command.c b/src/helper/command.c index 28952fd..9cc996c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -266,6 +266,38 @@ static void command_free(struct command *c) free(c); } +static int register_command_handler(struct command *c) +{ + int retval = -ENOMEM; + const char *full_name = command_name(c, '_'); + if (NULL == full_name) + return retval; + + const char *ocd_name = alloc_printf("ocd_%s", full_name); + if (NULL == full_name) + goto free_full_name; + + Jim_CreateCommand(interp, ocd_name, script_command, c, NULL); + free((void *)ocd_name); + + /* we now need to add an overrideable proc */ + const char *override_name = alloc_printf("proc %s {args} {" + "if {[catch {eval ocd_%s $args}] == 0} " + "{return \"\"} else {return -code error}}", + full_name, full_name); + if (NULL == full_name) + goto free_full_name; + + Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__); + free((void *)override_name); + + retval = ERROR_OK; + +free_full_name: + free((void *)full_name); + return retval; +} + struct command* register_command(struct command_context *context, struct command *parent, const struct command_registration *cr) { @@ -287,22 +319,12 @@ struct command* register_command(struct command_context *context, if (NULL == c || NULL == c->handler) return c; - const char *full_name = command_name(c, '_'); - - const char *ocd_name = alloc_printf("ocd_%s", full_name); - Jim_CreateCommand(interp, ocd_name, script_command, c, NULL); - free((void *)ocd_name); - - /* we now need to add an overrideable proc */ - const char *override_name = alloc_printf("proc %s {args} {" - "if {[catch {eval ocd_%s $args}] == 0} " - "{return \"\"} else {return -code error}}", - full_name, full_name); - Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__); - free((void *)override_name); - - free((void *)full_name); - + int retval = register_command_handler(c); + if (ERROR_OK != retval) + { + unregister_command(context, parent, name); + c = NULL; + } return c; } commit 25a7ac2c756c78603c9c99d06f55717440409a23 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 13:36:07 2009 -0800 command: use register_commands for handlers Use register_commands() to register low-level command handlers, adding a builtin_command_handlers declaration that is easy to understand. Splits help and usage information into their appropriate fields. diff --git a/src/helper/command.c b/src/helper/command.c index df4667b..28952fd 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -900,6 +900,39 @@ COMMAND_HANDLER(handle_sleep_command) return ERROR_OK; } +static const struct command_registration command_builtin_handlers[] = { + { + .name = "add_help_text", + .handler = &handle_help_add_command, + .mode = COMMAND_ANY, + .help = "add new command help text", + .usage = "<command> [...] <help_text>]", + }, + { + .name = "sleep", + .handler = &handle_sleep_command, + .mode = COMMAND_ANY, + .help = "sleep for n milliseconds. " + "\"busy\" will busy wait", + .usage = "<n> [busy]", + }, + { + .name = "help", + .handler = &handle_help_command, + .mode = COMMAND_ANY, + .help = "show built-in command help", + .usage = "[<command_name> ...]", + }, + { + .name = "usage", + .handler = &handle_usage_command, + .mode = COMMAND_ANY, + .help = "show command usage", + .usage = "[<command_name> ...]", + }, + COMMAND_REGISTRATION_DONE +}; + struct command_context* command_init(const char *startup_tcl) { struct command_context* context = malloc(sizeof(struct command_context)); @@ -959,10 +992,7 @@ struct command_context* command_init(const char *startup_tcl) interp->cb_fflush = openocd_jim_fflush; interp->cb_fgets = openocd_jim_fgets; - COMMAND_REGISTER(context, NULL, "add_help_text", - handle_help_add_command, COMMAND_ANY, - "<command> [...] <help_text>] - " - "add new command help text"); + register_commands(context, NULL, command_builtin_handlers); #if !BUILD_ECOSBOARD Jim_EventLoopOnLoad(interp); @@ -976,19 +1006,6 @@ struct command_context* command_init(const char *startup_tcl) } Jim_DeleteAssocData(interp, "context"); - COMMAND_REGISTER(context, NULL, "sleep", - handle_sleep_command, COMMAND_ANY, - "<n> [busy] - sleep for n milliseconds. " - "\"busy\" means busy wait"); - - COMMAND_REGISTER(context, NULL, "help", - &handle_help_command, COMMAND_ANY, - "[<command_name> ...] - show built-in command help"); - COMMAND_REGISTER(context, NULL, "usage", - &handle_usage_command, COMMAND_ANY, - "[<command_name> ...] | " - "show command usage"); - return context; } commit d107f71c5079dbe2a023276367b805397d1245c4 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 14:07:28 2009 -0800 add command usage, separate from help Adds the usage command, to display usage information for commands. The output for this command will remain erronenously empty until commands are updated to use these new coventions. diff --git a/src/helper/command.c b/src/helper/command.c index 51b3f9f..df4667b 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -226,7 +226,7 @@ static struct command **command_list_for_parent( static struct command *command_new(struct command_context *cmd_ctx, struct command *parent, const char *name, command_handler_t handler, enum command_mode mode, - const char *help) + const char *help, const char *usage) { assert(name); @@ -236,6 +236,8 @@ static struct command *command_new(struct command_context *cmd_ctx, c->name = strdup(name); if (help) c->help = strdup(help); + if (usage) + c->usage = strdup(usage); c->parent = parent; c->handler = handler; c->mode = mode; @@ -259,6 +261,8 @@ static void command_free(struct command *c) free(c->name); if (c->help) free((void*)c->help); + if (c->usage) + free((void*)c->usage); free(c); } @@ -278,7 +282,7 @@ struct command* register_command(struct command_context *context, return c; } - c = command_new(context, parent, name, cr->handler, cr->mode, cr->help); + c = command_new(context, parent, name, cr->handler, cr->mode, cr->help, cr->usage); /* if allocation failed or it is a placeholder (no handler), we're done */ if (NULL == c || NULL == c->handler) return c; @@ -737,41 +741,67 @@ static COMMAND_HELPER(command_help_find, struct command *head, return CALL_COMMAND_HANDLER(command_help_find, (*out)->children, out); } -static COMMAND_HELPER(command_help_show, struct command *c, unsigned n); +static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, + bool show_help); -static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n) +static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n, + bool show_help) { for (struct command *c = head; NULL != c; c = c->next) - CALL_COMMAND_HANDLER(command_help_show, c, n); + CALL_COMMAND_HANDLER(command_help_show, c, n, show_help); return ERROR_OK; } -static COMMAND_HELPER(command_help_show, struct command *c, unsigned n) +static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, + bool show_help) { - command_run_linef(CMD_CTX, "cmd_help {%s} {%s} %d", command_name(c, ' '), - c->help ? : "no help available", n); + const char *usage = c->usage ? : ""; + const char *help = ""; + const char *sep = ""; + if (show_help && c->help) + { + help = c->help ? : ""; + sep = c->usage ? " | " : ""; + } + command_run_linef(CMD_CTX, "cmd_help {%s} {%s%s%s} %d", + command_name(c, ' '), usage, sep, help, n); if (++n >= 2) return ERROR_OK; - return CALL_COMMAND_HANDLER(command_help_show_list, c->children, n); + return CALL_COMMAND_HANDLER(command_help_show_list, + c->children, n, show_help); } COMMAND_HANDLER(handle_help_command) { struct command *c = CMD_CTX->commands; if (0 == CMD_ARGC) - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0); + return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, true); + + int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); + if (ERROR_OK != retval) + return retval; + + return CALL_COMMAND_HANDLER(command_help_show, c, 0, true); +} + +COMMAND_HANDLER(handle_usage_command) +{ + struct command *c = CMD_CTX->commands; + + if (0 == CMD_ARGC) + return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, false); int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); if (ERROR_OK != retval) return retval; - return CALL_COMMAND_HANDLER(command_help_show, c, 0); + return CALL_COMMAND_HANDLER(command_help_show, c, 0, false); } int help_add_command(struct command_context *cmd_ctx, struct command *parent, - const char *cmd_name, const char *help_text) + const char *cmd_name, const char *help_text, const char *usage) { struct command **head = command_list_for_parent(cmd_ctx, parent); struct command *nc = command_find(*head, cmd_name); @@ -782,6 +812,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, .name = cmd_name, .mode = COMMAND_ANY, .help = help_text, + .usage = usage, }; nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) @@ -830,7 +861,7 @@ COMMAND_HANDLER(handle_help_add_command) if (ERROR_OK != retval) return retval; } - return help_add_command(CMD_CTX, c, cmd_name, help_text); + return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL); } /* sleep command sleeps for <n> miliseconds @@ -953,6 +984,10 @@ struct command_context* command_init(const char *startup_tcl) COMMAND_REGISTER(context, NULL, "help", &handle_help_command, COMMAND_ANY, "[<command_name> ...] - show built-in command help"); + COMMAND_REGISTER(context, NULL, "usage", + &handle_usage_command, COMMAND_ANY, + "[<command_name> ...] | " + "show command usage"); return context; } @@ -989,7 +1024,7 @@ void register_jim(struct command_context *cmd_ctx, const char *name, Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, name, -1)); - help_add_command(cmd_ctx, NULL, name, help); + help_add_command(cmd_ctx, NULL, name, help, NULL); } #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \ diff --git a/src/helper/command.h b/src/helper/command.h index 1afaeea..7baa92d 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -160,6 +160,7 @@ struct command { char *name; const char *help; + const char *usage; struct command *parent; struct command *children; command_handler_t handler; @@ -199,6 +200,8 @@ struct command_registration { command_handler_t handler; enum command_mode mode; const char *help; + /// a string listing the options and arguments, required or optional + const char *usage; }; /// Use this as the last entry in an array of command_registration records. commit 2461855494cd045567c15c502ba215caffb37ce3 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 12:46:06 2009 -0800 add register_commands for batch registration The register_commands API takes multiple commands in one call, allowing modules to declare and pass a much simpler (and more explicit) array of command_registration records. diff --git a/src/helper/command.c b/src/helper/command.c index 3df60b6..51b3f9f 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -302,6 +302,23 @@ struct command* register_command(struct command_context *context, return c; } +int register_commands(struct command_context *cmd_ctx, struct command *parent, + const struct command_registration *cmds) +{ + unsigned i; + for (i = 0; cmds[i].name; i++) + { + struct command *c = register_command(cmd_ctx, parent, cmds + i); + if (NULL != c) + continue; + + for (unsigned j = 0; j < i; j++) + unregister_command(cmd_ctx, parent, cmds[j].name); + return ERROR_FAIL; + } + return ERROR_OK; +} + int unregister_all_commands(struct command_context *context, struct command *parent) { diff --git a/src/helper/command.h b/src/helper/command.h index b57ca75..1afaeea 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -201,6 +201,9 @@ struct command_registration { const char *help; }; +/// Use this as the last entry in an array of command_registration records. +#define COMMAND_REGISTRATION_DONE { .name = NULL } + /** * Register a command @c handler that can be called from scripts during * the execution @c mode specified. @@ -231,6 +234,22 @@ struct command* register_command(struct command_context *cmd_ctx, }) /** + * Register one or more commands in the specified context, as children + * of @c parent (or top-level commends, if NULL). + * + * @param cmd_ctx The command_context in which to register the command. + * @param parent Register this command as a child of this, or NULL to + * register a top-level command. + * @param cmds Pointer to an array of command_registration records that + * contains the desired command parameters. The last record must have + * NULL for all fields. + * @returns ERROR_OK on success; ERROR_FAIL if any registration fails. + */ +int register_commands(struct command_context *cmd_ctx, struct command *parent, + const struct command_registration *cmds); + + +/** * Unregisters command @c name from the given context, @c cmd_ctx. * @param cmd_ctx The context of the registered command. * @param parent The parent of the given command, or NULL. commit 69076057dde9f4336b54fb4da677da8fe5da66bd Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 11:23:34 2009 -0800 add struct command_registration Add a structure to encapsulate command registration information, rather than passing them all as parameters. Enables further API changes that require additional required or optional parameters. Updates the register_command API and COMMAND_REGISTER macro to use it, along with their documentation. diff --git a/src/helper/command.c b/src/helper/command.c index 0561c6c..3df60b6 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -263,13 +263,12 @@ static void command_free(struct command *c) } struct command* register_command(struct command_context *context, - struct command *parent, const char *name, - command_handler_t handler, enum command_mode mode, - const char *help) + struct command *parent, const struct command_registration *cr) { - if (!context || !name) + if (!context || !cr->name) return NULL; + const char *name = cr->name; struct command **head = command_list_for_parent(context, parent); struct command *c = command_find(*head, name); if (NULL != c) @@ -279,7 +278,7 @@ struct command* register_command(struct command_context *context, return c; } - c = command_new(context, parent, name, handler, mode, help); + c = command_new(context, parent, name, cr->handler, cr->mode, cr->help); /* if allocation failed or it is a placeholder (no handler), we're done */ if (NULL == c || NULL == c->handler) return c; @@ -762,8 +761,12 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (NULL == nc) { // add a new command with help text - nc = register_command(cmd_ctx, parent, cmd_name, - NULL, COMMAND_ANY, help_text); + struct command_registration cr = { + .name = cmd_name, + .mode = COMMAND_ANY, + .help = help_text, + }; + nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) { LOG_ERROR("failed to add '%s' help text", cmd_name); diff --git a/src/helper/command.h b/src/helper/command.h index 25c0501..b57ca75 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -177,13 +177,9 @@ struct command */ char *command_name(struct command *c, char delim); -/** - * Register a command @c handler that can be called from scripts during - * the execution @c mode specified. - * - * If @c parent is non-NULL, the new command will be registered as a - * sub-command under it; otherwise, it will be available as a top-level - * command. +/* + * Commands should be registered by filling in one or more of these + * structures and passing them to register_command(). * * A conventioal format should be used for help strings, to provide both * usage and basic information: @@ -191,25 +187,48 @@ char *command_name(struct command *c, char delim); * "@<options@> ... - some explanation text" * @endcode * - * @param cmd_ctx The command_context in which to register the command. - * @param parent Register this command as a child of this, or NULL to - * register a top-level command. * @param name The name of the command to register, which must not have - * been registered previously. + * been registered previously in the intended context. * @param handler The callback function that will be called. If NULL, * then the command serves as a placeholder for its children or a script. * @param mode The command mode(s) in which this command may be run. * @param help The help text that will be displayed to the user. + */ +struct command_registration { + const char *name; + command_handler_t handler; + enum command_mode mode; + const char *help; +}; + +/** + * Register a command @c handler that can be called from scripts during + * the execution @c mode specified. + * + * If @c parent is non-NULL, the new command will be registered as a + * sub-command under it; otherwise, it will be available as a top-level + * command. + * + * @param cmd_ctx The command_context in which to register the command. + * @param parent Register this command as a child of this, or NULL to + * register a top-level command. + * @param rec A command_registration record that contains the desired + * command parameters. * @returns The new command, if successful; otherwise, NULL. */ struct command* register_command(struct command_context *cmd_ctx, - struct command *parent, const char *name, - command_handler_t handler, enum command_mode mode, - const char *help); + struct command *parent, const struct command_registration *rec); -// provide a simple shim, for now; allows parameters to be migrated #define COMMAND_REGISTER(_cmd_ctx, _parent, _name, _handler, _mode, _help) \ - register_command(_cmd_ctx, _parent, _name, _handler, _mode, _help) + ({ \ + struct command_registration cr = { \ + .name = _name, \ + .handler = _handler, \ + .mode = _mode, \ + .help = _help, \ + }; \ + register_command(_cmd_ctx, _parent, &cr); \ + }) /** * Unregisters command @c name from the given context, @c cmd_ctx. commit 833e7f5248778bcb31b4db1a1b91160995415203 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 11:26:35 2009 -0800 use COMMAND_REGISTER macro Replaces direct calls to register_command() with a macro, to allow its parameters to be changed and callers updated in phases. diff --git a/src/ecosboard.c b/src/ecosboard.c index 58520c3..2789464 100644 --- a/src/ecosboard.c +++ b/src/ecosboard.c @@ -1091,7 +1091,7 @@ int main(int argc, char *argv[]) #ifdef CYGPKG_PROFILE_GPROF - register_command(cmd_ctx, NULL, "ecosboard_profile", eCosBoard_handle_eCosBoard_profile_command, + COMMAND_REGISTER(cmd_ctx, NULL, "ecosboard_profile", eCosBoard_handle_eCosBoard_profile_command, COMMAND_ANY, NULL); #endif diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c index 195da91..d8460b0 100644 --- a/src/flash/at91sam3.c +++ b/src/flash/at91sam3.c @@ -2478,18 +2478,18 @@ sam3_register_commands(struct command_context *cmd_ctx) if (!sam3_registered) { sam3_registered++; - pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, pCmd, + pCmd = COMMAND_REGISTER(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, pCmd, "gpnvm", sam3_handle_gpnvm_command, COMMAND_EXEC, "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set | clear BIT"); - register_command(cmd_ctx, pCmd, + COMMAND_REGISTER(cmd_ctx, pCmd, "info", sam3_handle_info_command, COMMAND_EXEC, "at91sam3 info - print information about the current sam3 chip"); - register_command(cmd_ctx, pCmd, + COMMAND_REGISTER(cmd_ctx, pCmd, "slowclk", sam3_handle_slowclk_command, COMMAND_EXEC, diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index 3e5dbdd..1665b91 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -1180,10 +1180,10 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) static int at91sam7_register_commands(struct command_context *cmd_ctx) { - struct command *at91sam7_cmd = register_command(cmd_ctx, NULL, "at91sam7", + struct command *at91sam7_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "at91sam7", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, at91sam7_cmd, "gpnvm", + COMMAND_REGISTER(cmd_ctx, at91sam7_cmd, "gpnvm", at91sam7_handle_gpnvm_command, COMMAND_EXEC, "at91sam7 gpnvm <bit> set | clear, " "set or clear one gpnvm bit"); diff --git a/src/flash/avrf.c b/src/flash/avrf.c index 356c404..692992f 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -451,10 +451,10 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command) static int avrf_register_commands(struct command_context *cmd_ctx) { - struct command *avr_cmd = register_command(cmd_ctx, NULL, "avr", + struct command *avr_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "avr", NULL, COMMAND_ANY, "avr flash specific commands"); - register_command(cmd_ctx, avr_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, avr_cmd, "mass_erase", avrf_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); diff --git a/src/flash/cfi.c b/src/flash/cfi.c index 59c9c6c..e743fe9 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -592,9 +592,9 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size) static int cfi_register_commands(struct command_context *cmd_ctx) { /*struct command *cfi_cmd = */ - register_command(cmd_ctx, NULL, "cfi", NULL, COMMAND_ANY, "flash bank cfi <base> <size> <chip_width> <bus_width> <targetNum> [jedec_probe/x16_as_x8]"); + COMMAND_REGISTER(cmd_ctx, NULL, "cfi", NULL, COMMAND_ANY, "flash bank cfi <base> <size> <chip_width> <bus_width> <targetNum> [jedec_probe/x16_as_x8]"); /* - register_command(cmd_ctx, cfi_cmd, "part_id", cfi_handle_part_id_command, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, cfi_cmd, "part_id", cfi_handle_part_id_command, COMMAND_EXEC, "print part id of cfi flash bank <num>"); */ return ERROR_OK; diff --git a/src/flash/ecos.c b/src/flash/ecos.c index 863c12b..381f858 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -338,7 +338,7 @@ static int ecosflash_probe(struct flash_bank *bank) static int ecosflash_register_commands(struct command_context *cmd_ctx) { - register_command(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); return ERROR_OK; } diff --git a/src/flash/flash.c b/src/flash/flash.c index e2136b7..7bc74ab 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -1280,42 +1280,42 @@ int flash_init_drivers(struct command_context *cmd_ctx) if (!flash_banks) return ERROR_OK; - register_command(cmd_ctx, flash_cmd, "info", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC, "print info about flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "probe", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC, "identify flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "erase_check", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_check", handle_flash_erase_check_command, COMMAND_EXEC, "check erase state of sectors in flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "protect_check", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect_check", handle_flash_protect_check_command, COMMAND_EXEC, "check protection state of sectors in flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "erase_sector", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_sector", handle_flash_erase_command, COMMAND_EXEC, "erase sectors at <bank> <first> <last>"); - register_command(cmd_ctx, flash_cmd, "erase_address", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_address", handle_flash_erase_address_command, COMMAND_EXEC, "erase address range <address> <length>"); - register_command(cmd_ctx, flash_cmd, "fillw", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillw", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern (no autoerase) <address> <word_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "fillh", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillh", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern <address> <halfword_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "fillb", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillb", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern <address> <byte_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "write_bank", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_bank", handle_flash_write_bank_command, COMMAND_EXEC, "write binary data to <bank> <file> <offset>"); - register_command(cmd_ctx, flash_cmd, "write_image", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC, "write_image [erase] [unlock] <file> [offset] [type]"); - register_command(cmd_ctx, flash_cmd, "protect", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC, "set protection of sectors at <bank> <first> <last> <on | off>"); @@ -1324,10 +1324,10 @@ int flash_init_drivers(struct command_context *cmd_ctx) int flash_register_commands(struct command_context *cmd_ctx) { - flash_cmd = register_command(cmd_ctx, NULL, "flash", + flash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, flash_cmd, "bank", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash bank <driver> <base> <size> " "<chip_width> <bus_width> <target> [driver_options ...]"); diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index b60c6cf..4a934c0 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -778,10 +778,10 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command) static int lpc2000_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2000_cmd = register_command(cmd_ctx, NULL, "lpc2000", + struct command *lpc2000_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2000", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, lpc2000_cmd, "part_id", + COMMAND_REGISTER(cmd_ctx, lpc2000_cmd, "part_id", lpc2000_handle_part_id_command, COMMAND_EXEC, "print part id of lpc2000 flash bank <num>"); diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c index 465d776..c7f1b3a 100644 --- a/src/flash/lpc2900.c +++ b/src/flash/lpc2900.c @@ -954,60 +954,36 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command) */ static int lpc2900_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2900_cmd = register_command(cmd_ctx, NULL, "lpc2900", + struct command *lpc2900_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2900", NULL, COMMAND_ANY, NULL); - register_command( - cmd_ctx, - lpc2900_cmd, - "signature", - lpc2900_handle_signature_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "signature", + &lpc2900_handle_signature_command, COMMAND_EXEC, "<bank> | " - "print device signature of flash bank"); - - register_command( - cmd_ctx, - lpc2900_cmd, - "read_custom", - lpc2900_handle_read_custom_command, - COMMAND_EXEC, + "print device signature of flash bank"); + + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "read_custom", + &lpc2900_handle_read_custom_command, COMMAND_EXEC, "<bank> <filename> | " "read customer information from index sector to file"); - register_command( - cmd_ctx, - lpc2900_cmd, - "password", - lpc2900_handle_password_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "password", + &lpc2900_handle_password_command, COMMAND_EXEC, "<bank> <password> | " "enter password to enable 'dangerous' options"); - register_command( - cmd_ctx, - lpc2900_cmd, - "write_custom", - lpc2900_handle_write_custom_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "write_custom", + &lpc2900_handle_write_custom_command, COMMAND_EXEC, "<bank> <filename> [<type>] | " "write customer info from file to index sector"); - register_command( - cmd_ctx, - lpc2900_cmd, - "secure_sector", - lpc2900_handle_secure_sector_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_sector", + &lpc2900_handle_secure_sector_command, COMMAND_EXEC, "<bank> <first> <last> | " "activate sector security for a range of sectors"); - register_command( - cmd_ctx, - lpc2900_cmd, - "secure_jtag", - lpc2900_handle_secure_jtag_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_jtag", + &lpc2900_handle_secure_jtag_command, COMMAND_EXEC, "<bank> <level> | " "activate JTAG security"); diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 61bef90..801607d 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -875,9 +875,9 @@ COMMAND_HANDLER(handle_lpc3180_select_command) static int lpc3180_register_commands(struct command_context *cmd_ctx) { - struct command *lpc3180_cmd = register_command(cmd_ctx, NULL, "lpc3180", NULL, COMMAND_ANY, "commands specific to the LPC3180 NAND flash controllers"); + struct command *lpc3180_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc3180", NULL, COMMAND_ANY, "commands specific to the LPC3180 NAND flash controllers"); - register_command(cmd_ctx, lpc3180_cmd, "select", handle_lpc3180_select_command, COMMAND_EXEC, "select <'mlc'|'slc'> controller (default is mlc)"); + COMMAND_REGISTER(cmd_ctx, lpc3180_cmd, "select", handle_lpc3180_select_command, COMMAND_EXEC, "select <'mlc'|'slc'> controller (default is mlc)"); return ERROR_OK; } diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 2a1fbe5..a4a45dc 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -1271,12 +1271,12 @@ COMMAND_HANDLER(mg_config_cmd) int mflash_init_drivers(struct command_context *cmd_ctx) { if (mflash_bank) { - register_command(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL); - register_command(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL); + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC, "mflash write <num> <file> <address>"); - register_command(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC, "mflash dump <num> <file> <address> <size>"); - register_command(cmd_ctx, mflash_cmd, "config", mg_config_cmd, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "config", mg_config_cmd, COMMAND_EXEC, "mflash config <num> <stage>"); } @@ -1325,8 +1325,8 @@ COMMAND_HANDLER(mg_bank_cmd) int mflash_register_commands(struct command_context *cmd_ctx) { - mflash_cmd = register_command(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG, + mflash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG, "mflash bank <soc> <base> <RST pin> <target #>"); return ERROR_OK; } diff --git a/src/flash/nand.c b/src/flash/nand.c index 77aa3e5..2438ddd 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -281,13 +281,13 @@ COMMAND_HANDLER(handle_nand_device_command) int nand_register_commands(struct command_context *cmd_ctx) { - nand_cmd = register_command(cmd_ctx, NULL, "nand", + nand_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands"); - register_command(cmd_ctx, nand_cmd, "device", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "device", &handle_nand_device_command, COMMAND_CONFIG, "defines a new NAND bank"); - register_command(cmd_ctx, nand_cmd, "drivers", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "drivers", &handle_nand_list_drivers, COMMAND_ANY, "lists available NAND drivers"); @@ -1705,36 +1705,36 @@ int nand_init(struct command_context *cmd_ctx) if (!nand_devices) return ERROR_OK; - register_command(cmd_ctx, nand_cmd, "list", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "list", handle_nand_list_command, COMMAND_EXEC, "list configured NAND flash devices"); - register_command(cmd_ctx, nand_cmd, "info", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "info", handle_nand_info_command, COMMAND_EXEC, "print info about NAND flash device <num>"); - register_command(cmd_ctx, nand_cmd, "probe", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "probe", handle_nand_probe_command, COMMAND_EXEC, "identify NAND flash device <num>"); - register_command(cmd_ctx, nand_cmd, "check_bad_blocks", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "check_bad_blocks", handle_nand_check_bad_blocks_command, COMMAND_EXEC, "check NAND flash device <num> for bad blocks [<offset> <length>]"); - register_command(cmd_ctx, nand_cmd, "erase", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "erase", handle_nand_erase_command, COMMAND_EXEC, "erase blocks on NAND flash device <num> [<offset> <length>]"); - register_command(cmd_ctx, nand_cmd, "dump", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "dump", handle_nand_dump_command, COMMAND_EXEC, "dump from NAND flash device <num> <filename> " "<offset> <length> [oob_raw | oob_only]"); - register_command(cmd_ctx, nand_cmd, "verify", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "verify", &handle_nand_verify_command, COMMAND_EXEC, "verify NAND flash device <num> <filename> <offset> " "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - register_command(cmd_ctx, nand_cmd, "write", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "write", handle_nand_write_command, COMMAND_EXEC, "write to NAND flash device <num> <filename> <offset> " "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - register_command(cmd_ctx, nand_cmd, "raw_access", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "raw_access", handle_nand_raw_access_command, COMMAND_EXEC, "raw access to NAND flash device <num> ['enable'|'disable']"); diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index fa5a4d6..c6d4615 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -885,20 +885,20 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) static int pic32mx_register_commands(struct command_context *cmd_ctx) { - struct command *pic32mx_cmd = register_command(cmd_ctx, NULL, "pic32mx", + struct command *pic32mx_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "pic32mx", NULL, COMMAND_ANY, "pic32mx flash specific commands"); #if 0 - register_command(cmd_ctx, pic32mx_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "lock", pic32mx_handle_lock_command, COMMAND_EXEC, "lock device"); - register_command(cmd_ctx, pic32mx_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "unlock", pic32mx_handle_unlock_command, COMMAND_EXEC, "unlock protected device"); #endif - register_command(cmd_ctx, pic32mx_cmd, "chip_erase", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "chip_erase", pic32mx_handle_chip_erase_command, COMMAND_EXEC, "erase device"); - register_command(cmd_ctx, pic32mx_cmd, "pgm_word", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "pgm_word", pic32mx_handle_pgm_word_command, COMMAND_EXEC, "program a word"); return ERROR_OK; diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c index 32fa415..2d653ec 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -1163,10 +1163,10 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) static int stellaris_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = register_command(cmd_ctx, NULL, "stellaris", + struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stellaris", NULL, COMMAND_ANY, "stellaris flash specific commands"); - register_command(cmd_ctx, stm32x_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", stellaris_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); return ERROR_OK; diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index c96b49d..c628f18 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -1184,22 +1184,22 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) static int stm32x_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = register_command(cmd_ctx, NULL, "stm32x", + struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stm32x", NULL, COMMAND_ANY, "stm32x flash specific commands"); - register_command(cmd_ctx, stm32x_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "lock", stm32x_handle_lock_command, COMMAND_EXEC, "lock device"); - register_command(cmd_ctx, stm32x_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "unlock", stm32x_handle_unlock_command, COMMAND_EXEC, "unlock protected device"); - register_command(cmd_ctx, stm32x_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", stm32x_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); - register_command(cmd_ctx, stm32x_cmd, "options_read", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_read", stm32x_handle_options_read_command, COMMAND_EXEC, "read device option bytes"); - register_command(cmd_ctx, stm32x_cmd, "options_write", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_write", stm32x_handle_options_write_command, COMMAND_EXEC, "write device option bytes"); diff --git a/src/flash/str7x.c b/src/flash/str7x.c index b79dd17..b53ddf9 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -674,10 +674,10 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command) static int str7x_register_commands(struct command_context *cmd_ctx) { - struct command *str7x_cmd = register_command(cmd_ctx, NULL, "str7x", + struct command *str7x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str7x", NULL, COMMAND_ANY, "str7x flash specific commands"); - register_command(cmd_ctx, str7x_cmd, "disable_jtag", + COMMAND_REGISTER(cmd_ctx, str7x_cmd, "disable_jtag", str7x_handle_disable_jtag_command, COMMAND_EXEC, "disable jtag access"); diff --git a/src/flash/str9x.c b/src/flash/str9x.c index 3bb8970..6d556d9 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -678,10 +678,10 @@ COMMAND_HANDLER(str9x_handle_flash_config_command) static int str9x_register_commands(struct command_context *cmd_ctx) { - struct command *str9x_cmd = register_command(cmd_ctx, NULL, "str9x", + struct command *str9x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9x", NULL, COMMAND_ANY, "str9x flash commands"); - register_command(cmd_ctx, str9x_cmd, "flash_config", + COMMAND_REGISTER(cmd_ctx, str9x_cmd, "flash_config", str9x_handle_flash_config_command, COMMAND_EXEC, "configure str9 flash controller"); diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index f7c705e..7519413 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -1165,40 +1165,40 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command) static int str9xpec_register_commands(struct command_context *cmd_ctx) { - struct command *str9xpec_cmd = register_command(cmd_ctx, NULL, "str9xpec", + struct command *str9xpec_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9xpec", NULL, COMMAND_ANY, "str9xpec flash specific commands"); - register_command(cmd_ctx, str9xpec_cmd, "enable_turbo", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "enable_turbo", str9xpec_handle_flash_enable_turbo_command, COMMAND_EXEC, "enable str9xpec turbo mode"); - register_command(cmd_ctx, str9xpec_cmd, "disable_turbo", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "disable_turbo", str9xpec_handle_flash_disable_turbo_command, COMMAND_EXEC, "disable str9xpec turbo mode"); - register_command(cmd_ctx, str9xpec_cmd, "options_cmap", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_cmap", str9xpec_handle_flash_options_cmap_command, COMMAND_EXEC, "configure str9xpec boot sector"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdthd", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdthd", str9xpec_handle_flash_options_lvdthd_command, COMMAND_EXEC, "configure str9xpec lvd threshold"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdsel", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdsel", str9xpec_handle_flash_options_lvdsel_command, COMMAND_EXEC, "configure str9xpec lvd selection"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdwarn", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdwarn", str9xpec_handle_flash_options_lvdwarn_command, COMMAND_EXEC, "configure str9xpec lvd warning"); - register_command(cmd_ctx, str9xpec_cmd, "options_read", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_read", str9xpec_handle_flash_options_read_command, COMMAND_EXEC, "read str9xpec options"); - register_command(cmd_ctx, str9xpec_cmd, "options_write", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_write", str9xpec_handle_flash_options_write_command, COMMAND_EXEC, "write str9xpec options"); - register_command(cmd_ctx, str9xpec_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "lock", str9xpec_handle_flash_lock_command, COMMAND_EXEC, "lock str9xpec device"); - register_command(cmd_ctx, str9xpec_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "unlock", str9xpec_handle_flash_unlock_command, COMMAND_EXEC, "unlock str9xpec device"); - register_command(cmd_ctx, str9xpec_cmd, "part_id", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "part_id", str9xpec_handle_part_id_command, COMMAND_EXEC, "print part id of str9xpec flash bank <num>"); diff --git a/src/flash/tms470.c b/src/flash/tms470.c index f6f3900..bf58f1d 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -819,11 +819,11 @@ static int tms470_erase_sector(struct flash_bank *bank, int sector) static int tms470_register_commands(struct command_context *cmd_ctx) { - struct command *tms470_cmd = register_command(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); + struct command *tms470_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); - register_command(cmd_ctx, tms470_cmd, "flash_keyset", tms470_handle_flash_keyset_command, COMMAND_ANY, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); - register_command(cmd_ctx, tms470_cmd, "osc_megahertz", tms470_handle_osc_megahertz_command, COMMAND_ANY, "tms470 osc_megahertz <MHz>"); - register_command(cmd_ctx, tms470_cmd, "plldis", tms470_handle_plldis_command, COMMAND_ANY, "tms470 plldis <0/1>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "flash_keyset", tms470_handle_flash_keyset_command, COMMAND_ANY, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "osc_megahertz", tms470_handle_osc_megahertz_command, COMMAND_ANY, "tms470 osc_megahertz <MHz>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "plldis", tms470_handle_plldis_command, COMMAND_ANY, "tms470 plldis <0/1>"); return ERROR_OK; } diff --git a/src/hello.c b/src/hello.c index 2ab7eb5..8c97a40 100644 --- a/src/hello.c +++ b/src/hello.c @@ -56,17 +56,17 @@ COMMAND_HANDLER(handle_flag_command) int foo_register_commands(struct command_context *cmd_ctx) { // register several commands under the foo command - struct command *cmd = register_command(cmd_ctx, NULL, "foo", + struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "foo", NULL, COMMAND_ANY, "foo: command handler skeleton"); - register_command(cmd_ctx, cmd, "bar", + COMMAND_REGISTER(cmd_ctx, cmd, "bar", &handle_foo_command, COMMAND_ANY, "<address> [enable|disable] - an example command"); - register_command(cmd_ctx, cmd, "baz", + COMMAND_REGISTER(cmd_ctx, cmd, "baz", &handle_foo_command, COMMAND_ANY, "<address> [enable|disable] - a sample command"); - register_command(cmd_ctx, cmd, "flag", + COMMAND_REGISTER(cmd_ctx, cmd, "flag", &handle_flag_command, COMMAND_ANY, "[on|off] - set a flag"); @@ -103,7 +103,7 @@ int hello_register_commands(struct command_context *cmd_ctx) { foo_register_commands(cmd_ctx); - struct command *cmd = register_command(cmd_ctx, NULL, "hello", + struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "hello", &handle_hello_command, COMMAND_ANY, "[<name>] - prints a warm welcome"); return cmd ? ERROR_OK : -ENOMEM; diff --git a/src/helper/command.c b/src/helper/command.c index f6c6b2d..0561c6c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -908,7 +908,7 @@ struct command_context* command_init(const char *startup_tcl) interp->cb_fflush = openocd_jim_fflush; interp->cb_fgets = openocd_jim_fgets; - register_command(context, NULL, "add_help_text", + COMMAND_REGISTER(context, NULL, "add_help_text", handle_help_add_command, COMMAND_ANY, "<command> [...] <help_text>] - " "add new command help text"); @@ -925,12 +925,12 @@ struct command_context* command_init(const char *startup_tcl) } Jim_DeleteAssocData(interp, "context"); - register_command(context, NULL, "sleep", + COMMAND_REGISTER(context, NULL, "sleep", handle_sleep_command, COMMAND_ANY, "<n> [busy] - sleep for n milliseconds. " "\"busy\" means busy wait"); - register_command(context, NULL, "help", + COMMAND_REGISTER(context, NULL, "help", &handle_help_command, COMMAND_ANY, "[<command_name> ...] - show built-in command help"); diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 3fb3014..52ecb9f 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -647,22 +647,22 @@ static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, int argc, int ioutil_init(struct command_context *cmd_ctx) { - register_command(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY, "remove file"); - register_command(cmd_ctx, NULL, "cat", handle_cat_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "cat", handle_cat_command, COMMAND_ANY, "display file content"); - register_command(cmd_ctx, NULL, "trunc", handle_trunc_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "trunc", handle_trunc_command, COMMAND_ANY, "truncate a file to 0 size"); - register_command(cmd_ctx, NULL, "cp", handle_cp_command, + COMMAND_REGISTER(cmd_ctx, NULL, "cp", handle_cp_command, COMMAND_ANY, "copy a file <from> <to>"); - register_command(cmd_ctx, NULL, "append_file", handle_append_command, + COMMAND_REGISTER(cmd_ctx, NULL, "append_file", handle_append_command, COMMAND_ANY, "append a variable number of strings to a file"); - register_command(cmd_ctx, NULL, "meminfo", handle_meminfo_command, + COMMAND_REGISTER(cmd_ctx, NULL, "meminfo", handle_meminfo_command, COMMAND_ANY, "display available ram memory"); Jim_CreateCommand(interp, "rm", zylinjtag_Jim_Command_rm, NULL, NULL); diff --git a/src/helper/log.c b/src/helper/log.c index 2dcf7bb..b1352a3 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -319,9 +319,9 @@ COMMAND_HANDLER(handle_log_output_command) int log_register_commands(struct command_context *cmd_ctx) { start = timeval_ms(); - register_command(cmd_ctx, NULL, "log_output", handle_log_output_command, + COMMAND_REGISTER(cmd_ctx, NULL, "log_output", handle_log_output_command, COMMAND_ANY, "redirect logging to <file> (default: stderr)"); - register_command(cmd_ctx... [truncated message content] |
From: David B. <dbr...@us...> - 2009-11-25 06:25:03
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via b6210907ea584095cdede663f695eb8afeecef14 (commit) via e109bb6af211d3916e4006127945d128b138529b (commit) via c008d30fe85a674842632e32d732e22e0a91b95d (commit) via 991daa03ebbc69829be4a3899b77efb981254038 (commit) from 338a674faa96ae321560efa3f1b1e8122d61aac4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b6210907ea584095cdede663f695eb8afeecef14 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 21:24:44 2009 -0800 Cortex-A8: avoid DSCR reads There was a lot of needless handshaking overhead in the current Cortex-A8 DCC/ITR operations, since the status read by each step was discarded rather than letting the next step know it. This shrinks the handshaking by: (a) passing status along from previous steps, avoiding re-fetching; which enables the big win (b) relying on a useful invariant: that the DSCR_INSTR_COMP bit is set after every call to a DPM method. A "reg sp_usr" call previously took 17 flushes; now it takes just 9. This visibly speeds common operations like entry to debug state and stepping, as well as "arm reg" and so on. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index 299eb3c..08e5460 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -89,20 +89,25 @@ static int cortex_a8_init_debug_access(struct target *target) return retval; } -/* FIXME we waste a *LOT* of round-trips with needless DSCR reads, which - * slows down operations considerably. One good way to start reducing - * them would pass current values into and out of this routine. That - * should also help synch DCC read/write. +/* To reduce needless round-trips, pass in a pointer to the current + * DSCR value. Initialize it to zero if you just need to know the + * value on return from this function; or (1 << DSCR_INSTR_COMP) if + * you happen to know that no instruction is pending. */ -static int cortex_a8_exec_opcode(struct target *target, uint32_t opcode) +static int cortex_a8_exec_opcode(struct target *target, + uint32_t opcode, uint32_t *dscr_p) { uint32_t dscr; int retval; struct armv7a_common *armv7a = target_to_armv7a(target); struct swjdp_common *swjdp = &armv7a->swjdp_info; + dscr = dscr_p ? *dscr_p : 0; + LOG_DEBUG("exec opcode 0x%08" PRIx32, opcode); - do + + /* Wait for InstrCompl bit to be set */ + while ((dscr & (1 << DSCR_INSTR_COMP)) == 0) { retval = mem_ap_read_atomic_u32(swjdp, armv7a->debug_base + CPUDBG_DSCR, &dscr); @@ -112,7 +117,6 @@ static int cortex_a8_exec_opcode(struct target *target, uint32_t opcode) return retval; } } - while ((dscr & (1 << DSCR_INSTR_COMP)) == 0); /* Wait for InstrCompl bit to be set */ mem_ap_write_u32(swjdp, armv7a->debug_base + CPUDBG_ITR, opcode); @@ -128,6 +132,9 @@ static int cortex_a8_exec_opcode(struct target *target, uint32_t opcode) } while ((dscr & (1 << DSCR_INSTR_COMP)) == 0); /* Wait for InstrCompl bit to be set */ + if (dscr_p) + *dscr_p = dscr; + return retval; } @@ -144,7 +151,7 @@ static int cortex_a8_read_regs_through_mem(struct target *target, uint32_t addre cortex_a8_dap_read_coreregister_u32(target, regfile, 0); cortex_a8_dap_write_coreregister_u32(target, address, 0); - cortex_a8_exec_opcode(target, ARMV4_5_STMIA(0, 0xFFFE, 0, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_STMIA(0, 0xFFFE, 0, 0), NULL); dap_ap_select(swjdp, swjdp_memoryap); mem_ap_read_buf_u32(swjdp, (uint8_t *)(®file[1]), 4*15, address); dap_ap_select(swjdp, swjdp_debugap); @@ -158,10 +165,15 @@ static int cortex_a8_read_cp(struct target *target, uint32_t *value, uint8_t CP, int retval; struct armv7a_common *armv7a = target_to_armv7a(target); struct swjdp_common *swjdp = &armv7a->swjdp_info; + uint32_t dscr = 0; + + /* MRC(...) to read coprocessor register into r0 */ + cortex_a8_exec_opcode(target, ARMV4_5_MRC(CP, op1, 0, CRn, CRm, op2), + &dscr); - cortex_a8_exec_opcode(target, ARMV4_5_MRC(CP, op1, 0, CRn, CRm, op2)); /* Move R0 to DTRTX */ - cortex_a8_exec_opcode(target, ARMV4_5_MCR(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MCR(14, 0, 0, 0, 5, 0), + &dscr); /* Read DCCTX */ retval = mem_ap_read_atomic_u32(swjdp, @@ -187,16 +199,21 @@ static int cortex_a8_write_cp(struct target *target, uint32_t value, { LOG_ERROR("DSCR_DTR_RX_FULL, dscr 0x%08" PRIx32, dscr); /* Clear DCCRX with MCR(p14, 0, Rd, c0, c5, 0), opcode 0xEE000E15 */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); } + /* Write DTRRX ... sets DSCR.DTRRXfull but exec_opcode() won't care */ retval = mem_ap_write_u32(swjdp, armv7a->debug_base + CPUDBG_DTRRX, value); + /* Move DTRRX to r0 */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), &dscr); - cortex_a8_exec_opcode(target, ARMV4_5_MCR(CP, op1, 0, CRn, CRm, op2)); - return retval; + /* MCR(...) to write r0 to coprocessor */ + return cortex_a8_exec_opcode(target, + ARMV4_5_MCR(CP, op1, 0, CRn, CRm, op2), + &dscr); } static int cortex_a8_read_cp15(struct target *target, uint32_t op1, uint32_t op2, @@ -238,7 +255,7 @@ static int cortex_a8_dap_read_coreregister_u32(struct target *target, { int retval = ERROR_OK; uint8_t reg = regnum&0xFF; - uint32_t dscr; + uint32_t dscr = 0; struct armv7a_common *armv7a = target_to_armv7a(target); struct swjdp_common *swjdp = &armv7a->swjdp_info; @@ -248,30 +265,35 @@ static int cortex_a8_dap_read_coreregister_u32(struct target *target, if (reg < 15) { /* Rn to DCCTX, "MCR p14, 0, Rn, c0, c5, 0" 0xEE00nE15 */ - cortex_a8_exec_opcode(target, ARMV4_5_MCR(14, 0, reg, 0, 5, 0)); + cortex_a8_exec_opcode(target, + ARMV4_5_MCR(14, 0, reg, 0, 5, 0), + &dscr); } else if (reg == 15) { /* "MOV r0, r15"; then move r0 to DCCTX */ - cortex_a8_exec_opcode(target, 0xE1A0000F); - cortex_a8_exec_opcode(target, ARMV4_5_MCR(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, 0xE1A0000F, &dscr); + cortex_a8_exec_opcode(target, + ARMV4_5_MCR(14, 0, 0, 0, 5, 0), + &dscr); } else { /* "MRS r0, CPSR" or "MRS r0, SPSR" * then move r0 to DCCTX */ - cortex_a8_exec_opcode(target, ARMV4_5_MRS(0, reg & 1)); - cortex_a8_exec_opcode(target, ARMV4_5_MCR(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MRS(0, reg & 1), &dscr); + cortex_a8_exec_opcode(target, + ARMV4_5_MCR(14, 0, 0, 0, 5, 0), + &dscr); } - /* Read DTRRTX */ - do + /* Wait for DTRRXfull then read DTRRTX */ + while ((dscr & (1 << DSCR_DTR_TX_FULL)) == 0) { retval = mem_ap_read_atomic_u32(swjdp, armv7a->debug_base + CPUDBG_DSCR, &dscr); } - while ((dscr & (1 << DSCR_DTR_TX_FULL)) == 0); /* Wait for DTRRXfull */ retval = mem_ap_read_atomic_u32(swjdp, armv7a->debug_base + CPUDBG_DTRTX, value); @@ -298,13 +320,14 @@ static int cortex_a8_dap_write_coreregister_u32(struct target *target, { LOG_ERROR("DSCR_DTR_RX_FULL, dscr 0x%08" PRIx32, dscr); /* Clear DCCRX with MCR(p14, 0, Rd, c0, c5, 0), opcode 0xEE000E15 */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); } if (Rd > 17) return retval; - /* Write to DCCRX */ + /* Write DTRRX ... sets DSCR.DTRRXfull but exec_opcode() won't care */ LOG_DEBUG("write DCC 0x%08" PRIx32, value); retval = mem_ap_write_u32(swjdp, armv7a->debug_base + CPUDBG_DTRRX, value); @@ -312,28 +335,33 @@ static int cortex_a8_dap_write_coreregister_u32(struct target *target, if (Rd < 15) { /* DCCRX to Rn, "MCR p14, 0, Rn, c0, c5, 0", 0xEE00nE15 */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, Rd, 0, 5, 0)); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, Rd, 0, 5, 0), + &dscr); } else if (Rd == 15) { /* DCCRX to R0, "MCR p14, 0, R0, c0, c5, 0", 0xEE000E15 * then "mov r15, r0" */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); - cortex_a8_exec_opcode(target, 0xE1A0F000); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); + cortex_a8_exec_opcode(target, 0xE1A0F000, &dscr); } else { /* DCCRX to R0, "MCR p14, 0, R0, c0, c5, 0", 0xEE000E15 * then "MSR CPSR_cxsf, r0" or "MSR SPSR_cxsf, r0" (all fields) */ - cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); - cortex_a8_exec_opcode(target, ARMV4_5_MSR_GP(0, 0xF, Rd & 1)); + cortex_a8_exec_opcode(target, ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); + cortex_a8_exec_opcode(target, ARMV4_5_MSR_GP(0, 0xF, Rd & 1), + &dscr); /* "Prefetch flush" after modifying execution status in CPSR */ if (Rd == 16) cortex_a8_exec_opcode(target, - ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); + ARMV4_5_MCR(15, 0, 0, 7, 5, 4), + &dscr); } return retval; @@ -354,6 +382,9 @@ static int cortex_a8_dap_write_memap_register_u32(struct target *target, uint32_ /* * Cortex-A8 implementation of Debug Programmer's Model * + * NOTE the invariant: these routines return with DSCR_INSTR_COMP set, + * so there's no need to poll for it before executing an instruction. + * * NOTE that in several of these cases the "stall" mode might be useful. * It'd let us queue a few operations together... prepare/finish might * be the places to enable/disable that mode. @@ -371,23 +402,30 @@ static int cortex_a8_write_dcc(struct cortex_a8_common *a8, uint32_t data) a8->armv7a_common.debug_base + CPUDBG_DTRRX, data); } -static int cortex_a8_read_dcc(struct cortex_a8_common *a8, uint32_t *data) +static int cortex_a8_read_dcc(struct cortex_a8_common *a8, uint32_t *data, + uint32_t *dscr_p) { struct swjdp_common *swjdp = &a8->armv7a_common.swjdp_info; - uint32_t dscr; + uint32_t dscr = 1 << DSCR_INSTR_COMP; int retval; + if (dscr_p) + dscr = *dscr_p; + /* Wait for DTRRXfull */ - do { + while ((dscr & (1 << DSCR_DTR_TX_FULL)) == 0) { retval = mem_ap_read_atomic_u32(swjdp, a8->armv7a_common.debug_base + CPUDBG_DSCR, &dscr); - } while ((dscr & (1 << DSCR_DTR_TX_FULL)) == 0); + } retval = mem_ap_read_atomic_u32(swjdp, a8->armv7a_common.debug_base + CPUDBG_DTRTX, data); LOG_DEBUG("read DCC 0x%08" PRIx32, *data); + if (dscr_p) + *dscr_p = dscr; + return retval; } @@ -398,9 +436,12 @@ static int cortex_a8_dpm_prepare(struct arm_dpm *dpm) uint32_t dscr; int retval; - retval = mem_ap_read_atomic_u32(swjdp, - a8->armv7a_common.debug_base + CPUDBG_DSCR, - &dscr); + /* set up invariant: INSTR_COMP is set after ever DPM operation */ + do { + retval = mem_ap_read_atomic_u32(swjdp, + a8->armv7a_common.debug_base + CPUDBG_DSCR, + &dscr); + } while ((dscr & (1 << DSCR_INSTR_COMP)) == 0); /* this "should never happen" ... */ if (dscr & (1 << DSCR_DTR_RX_FULL)) { @@ -408,7 +449,8 @@ static int cortex_a8_dpm_prepare(struct arm_dpm *dpm) /* Clear DCCRX */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); } return retval; @@ -425,18 +467,21 @@ static int cortex_a8_instr_write_data_dcc(struct arm_dpm *dpm, { struct cortex_a8_common *a8 = dpm_to_a8(dpm); int retval; + uint32_t dscr = 1 << DSCR_INSTR_COMP; retval = cortex_a8_write_dcc(a8, data); return cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - opcode); + opcode, + &dscr); } static int cortex_a8_instr_write_data_r0(struct arm_dpm *dpm, uint32_t opcode, uint32_t data) { struct cortex_a8_common *a8 = dpm_to_a8(dpm); + uint32_t dscr = 1 << DSCR_INSTR_COMP; int retval; retval = cortex_a8_write_dcc(a8, data); @@ -444,12 +489,14 @@ static int cortex_a8_instr_write_data_r0(struct arm_dpm *dpm, /* DCCRX to R0, "MCR p14, 0, R0, c0, c5, 0", 0xEE000E15 */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + ARMV4_5_MRC(14, 0, 0, 0, 5, 0), + &dscr); /* then the opcode, taking data from R0 */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - opcode); + opcode, + &dscr); return retval; } @@ -457,9 +504,12 @@ static int cortex_a8_instr_write_data_r0(struct arm_dpm *dpm, static int cortex_a8_instr_cpsr_sync(struct arm_dpm *dpm) { struct target *target = dpm->arm->target; + uint32_t dscr = 1 << DSCR_INSTR_COMP; /* "Prefetch flush" after modifying execution status in CPSR */ - return cortex_a8_exec_opcode(target, ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); + return cortex_a8_exec_opcode(target, + ARMV4_5_MCR(15, 0, 0, 7, 5, 4), + &dscr); } static int cortex_a8_instr_read_data_dcc(struct arm_dpm *dpm, @@ -467,13 +517,15 @@ static int cortex_a8_instr_read_data_dcc(struct arm_dpm *dpm, { struct cortex_a8_common *a8 = dpm_to_a8(dpm); int retval; + uint32_t dscr = 1 << DSCR_INSTR_COMP; /* the opcode, writing data to DCC */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - opcode); + opcode, + &dscr); - return cortex_a8_read_dcc(a8, data); + return cortex_a8_read_dcc(a8, data, &dscr); } @@ -481,19 +533,22 @@ static int cortex_a8_instr_read_data_r0(struct arm_dpm *dpm, uint32_t opcode, uint32_t *data) { struct cortex_a8_common *a8 = dpm_to_a8(dpm); + uint32_t dscr = 1 << DSCR_INSTR_COMP; int retval; /* the opcode, writing data to R0 */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - opcode); + opcode, + &dscr); /* write R0 to DCC */ retval = cortex_a8_exec_opcode( a8->armv7a_common.armv4_5_common.target, - ARMV4_5_MCR(14, 0, 0, 0, 5, 0)); + ARMV4_5_MCR(14, 0, 0, 0, 5, 0), + &dscr); - return cortex_a8_read_dcc(a8, data); + return cortex_a8_read_dcc(a8, data, &dscr); } static int cortex_a8_dpm_setup(struct cortex_a8_common *a8, uint32_t didr) commit e109bb6af211d3916e4006127945d128b138529b Author: David Brownell <dbr...@us...> Date: Tue Nov 24 21:24:44 2009 -0800 Cortex-A8: hook up DPM This replaces two versions of register access functions. One was commented out, and seemed to have uncertain intent. The other was fairly new, and helped motivate the DPM framework once I observed that the ARM11 was doing the very same ops. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index 28c75b5..299eb3c 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -496,8 +496,7 @@ static int cortex_a8_instr_read_data_r0(struct arm_dpm *dpm, return cortex_a8_read_dcc(a8, data); } -// static -int cortex_a8_dpm_setup(struct cortex_a8_common *a8, uint32_t didr) +static int cortex_a8_dpm_setup(struct cortex_a8_common *a8, uint32_t didr) { struct arm_dpm *dpm = &a8->armv7a_common.dpm; @@ -806,12 +805,7 @@ static int cortex_a8_debug_entry(struct target *target) /* First load register acessible through core debug port*/ if (!regfile_working_area) { - /* FIXME we don't actually need all these registers; - * reading them slows us down. Just R0, PC, CPSR... - */ - for (i = 0; i <= 15; i++) - cortex_a8_dap_read_coreregister_u32(target, - ®file[i], i); + retval = arm_dpm_read_current_registers(&armv7a->dpm); } else { @@ -820,44 +814,41 @@ static int cortex_a8_debug_entry(struct target *target) regfile_working_area->address, regfile); dap_ap_select(swjdp, swjdp_memoryap); target_free_working_area(target, regfile_working_area); - } - /* read Current PSR */ - cortex_a8_dap_read_coreregister_u32(target, &cpsr, 16); - pc = regfile[15]; - dap_ap_select(swjdp, swjdp_debugap); - LOG_DEBUG("cpsr: %8.8" PRIx32, cpsr); + /* read Current PSR */ + cortex_a8_dap_read_coreregister_u32(target, &cpsr, 16); + pc = regfile[15]; + dap_ap_select(swjdp, swjdp_debugap); + LOG_DEBUG("cpsr: %8.8" PRIx32, cpsr); - arm_set_cpsr(armv4_5, cpsr); + arm_set_cpsr(armv4_5, cpsr); - /* update cache */ - for (i = 0; i <= ARM_PC; i++) - { - reg = arm_reg_current(armv4_5, i); + /* update cache */ + for (i = 0; i <= ARM_PC; i++) + { + reg = arm_reg_current(armv4_5, i); - buf_set_u32(reg->value, 0, 32, regfile[i]); - reg->valid = 1; - reg->dirty = 0; - } + buf_set_u32(reg->value, 0, 32, regfile[i]); + reg->valid = 1; + reg->dirty = 0; + } - /* Fixup PC Resume Address */ - if (cpsr & (1 << 5)) - { - // T bit set for Thumb or ThumbEE state - regfile[ARM_PC] -= 4; - } - else - { - // ARM state - regfile[ARM_PC] -= 8; - } + /* Fixup PC Resume Address */ + if (cpsr & (1 << 5)) + { + // T bit set for Thumb or ThumbEE state + regfile[ARM_PC] -= 4; + } + else + { + // ARM state + regfile[ARM_PC] -= 8; + } - reg = armv4_5->core_cache->reg_list + 15; - buf_set_u32(reg->value, 0, 32, regfile[ARM_PC]); - reg->dirty = reg->valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 15) - .dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).valid; + reg = armv4_5->core_cache->reg_list + 15; + buf_set_u32(reg->value, 0, 32, regfile[ARM_PC]); + reg->dirty = reg->valid; + } #if 0 /* TODO, Move this */ @@ -992,83 +983,14 @@ static int cortex_a8_step(struct target *target, int current, uint32_t address, static int cortex_a8_restore_context(struct target *target) { - uint32_t value; struct armv7a_common *armv7a = target_to_armv7a(target); - struct reg_cache *cache = armv7a->armv4_5_common.core_cache; - unsigned max = cache->num_regs; - struct reg *r; - bool flushed, flush_cpsr = false; LOG_DEBUG(" "); if (armv7a->pre_restore_context) armv7a->pre_restore_context(target); - /* Flush all dirty registers from the cache, one mode at a time so - * that we write CPSR as little as possible. Save CPSR and R0 for - * last; they're used to change modes and write other registers. - * - * REVISIT be smarter: save eventual mode for last loop, don't - * need to write CPSR an extra time. - */ - do { - enum armv4_5_mode mode = ARMV4_5_MODE_ANY; - unsigned i; - - flushed = false; - - /* write dirty non-{R0,CPSR} registers sharing the same mode */ - for (i = max - 1, r = cache->reg_list + 1; i > 0; i--, r++) { - struct arm_reg *reg; - - if (!r->dirty || r == armv7a->armv4_5_common.cpsr) - continue; - reg = r->arch_info; - - /* TODO Check return values */ - - /* Pick a mode and update CPSR; else ignore this - * register if it's for a different mode than what - * we're handling on this pass. - * - * REVISIT don't distinguish SYS and USR modes. - * - * FIXME if we restore from FIQ mode, R8..R12 will - * get wrongly flushed onto FIQ shadows... - */ - if (mode == ARMV4_5_MODE_ANY) { - mode = reg->mode; - if (mode != ARMV4_5_MODE_ANY) { - cortex_a8_dap_write_coreregister_u32( - target, mode, 16); - flush_cpsr = true; - } - } else if (mode != reg->mode) - continue; - - /* Write this register */ - value = buf_get_u32(r->value, 0, 32); - cortex_a8_dap_write_coreregister_u32(target, value, - (reg->num == 16) ? 17 : reg->num); - r->dirty = false; - flushed = true; - } - - } while (flushed); - - /* now flush CPSR if needed ... */ - r = armv7a->armv4_5_common.cpsr; - if (flush_cpsr || r->dirty) { - value = buf_get_u32(r->value, 0, 32); - cortex_a8_dap_write_coreregister_u32(target, value, 16); - r->dirty = false; - } - - /* ... and R0 always (it was dirtied when we saved context) */ - r = cache->reg_list + 0; - value = buf_get_u32(r->value, 0, 32); - cortex_a8_dap_write_coreregister_u32(target, value, 0); - r->dirty = false; + arm_dpm_write_dirty_registers(&armv7a->dpm); if (armv7a->post_restore_context) armv7a->post_restore_context(target); @@ -1077,204 +999,6 @@ static int cortex_a8_restore_context(struct target *target) } -#if 0 -/* - * Cortex-A8 Core register functions - */ -static int cortex_a8_load_core_reg_u32(struct target *target, int num, - armv4_5_mode_t mode, uint32_t * value) -{ - int retval; - struct arm *armv4_5 = target_to_armv4_5(target); - - if ((num <= ARM_CPSR)) - { - /* read a normal core register */ - retval = cortex_a8_dap_read_coreregister_u32(target, value, num); - - if (retval != ERROR_OK) - { - LOG_ERROR("JTAG failure %i", retval); - return ERROR_JTAG_DEVICE_ERROR; - } - LOG_DEBUG("load from core reg %i value 0x%" PRIx32, num, *value); - } - else - { - return ERROR_INVALID_ARGUMENTS; - } - - /* Register other than r0 - r14 uses r0 for access */ - if (num > 14) - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 0).dirty = - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 0).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).dirty = - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).valid; - - return ERROR_OK; -} - -static int cortex_a8_store_core_reg_u32(struct target *target, int num, - armv4_5_mode_t mode, uint32_t value) -{ - int retval; -// uint32_t reg; - struct arm *armv4_5 = target_to_armv4_5(target); - -#ifdef ARMV7_GDB_HACKS - /* If the LR register is being modified, make sure it will put us - * in "thumb" mode, or an INVSTATE exception will occur. This is a - * hack to deal with the fact that gdb will sometimes "forge" - * return addresses, and doesn't set the LSB correctly (i.e., when - * printing expressions containing function calls, it sets LR=0.) */ - - if (num == 14) - value |= 0x01; -#endif - - if ((num <= ARM_CPSR)) - { - retval = cortex_a8_dap_write_coreregister_u32(target, value, num); - if (retval != ERROR_OK) - { - LOG_ERROR("JTAG failure %i", retval); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, num).dirty = - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, num).valid; - return ERROR_JTAG_DEVICE_ERROR; - } - LOG_DEBUG("write core reg %i value 0x%" PRIx32, num, value); - } - else - { - return ERROR_INVALID_ARGUMENTS; - } - - return ERROR_OK; -} -#endif - - -static int cortex_a8_write_core_reg(struct target *target, struct reg *r, - int num, enum armv4_5_mode mode, uint32_t value); - -static int cortex_a8_read_core_reg(struct target *target, struct reg *r, - int num, enum armv4_5_mode mode) -{ - uint32_t value; - int retval; - struct arm *armv4_5 = target_to_armv4_5(target); - struct reg *cpsr_r = NULL; - uint32_t cpsr = 0; - unsigned cookie = num; - - /* avoid some needless mode changes - * FIXME move some of these to shared ARM code... - */ - if (mode != armv4_5->core_mode) { - if ((armv4_5->core_mode == ARMV4_5_MODE_SYS) - && (mode == ARMV4_5_MODE_USR)) - mode = ARMV4_5_MODE_ANY; - else if ((mode != ARMV4_5_MODE_FIQ) && (num <= 12)) - mode = ARMV4_5_MODE_ANY; - - if (mode != ARMV4_5_MODE_ANY) { - cpsr_r = armv4_5->cpsr; - cpsr = buf_get_u32(cpsr_r->value, 0, 32); - cortex_a8_write_core_reg(target, cpsr_r, - 16, ARMV4_5_MODE_ANY, mode); - } - } - - if (num == 16) { - switch (mode) { - case ARMV4_5_MODE_USR: - case ARMV4_5_MODE_SYS: - case ARMV4_5_MODE_ANY: - /* CPSR */ - break; - default: - /* SPSR */ - cookie++; - break; - } - } - - cortex_a8_dap_read_coreregister_u32(target, &value, cookie); - retval = jtag_execute_queue(); - if (retval == ERROR_OK) { - r->valid = 1; - r->dirty = 0; - buf_set_u32(r->value, 0, 32, value); - } - - if (cpsr_r) - cortex_a8_write_core_reg(target, cpsr_r, - 16, ARMV4_5_MODE_ANY, cpsr); - return retval; -} - -static int cortex_a8_write_core_reg(struct target *target, struct reg *r, - int num, enum armv4_5_mode mode, uint32_t value) -{ - int retval; - struct arm *armv4_5 = target_to_armv4_5(target); - struct reg *cpsr_r = NULL; - uint32_t cpsr = 0; - unsigned cookie = num; - - /* avoid some needless mode changes - * FIXME move some of these to shared ARM code... - */ - if (mode != armv4_5->core_mode) { - if ((armv4_5->core_mode == ARMV4_5_MODE_SYS) - && (mode == ARMV4_5_MODE_USR)) - mode = ARMV4_5_MODE_ANY; - else if ((mode != ARMV4_5_MODE_FIQ) && (num <= 12)) - mode = ARMV4_5_MODE_ANY; - - if (mode != ARMV4_5_MODE_ANY) { - cpsr_r = armv4_5->cpsr; - cpsr = buf_get_u32(cpsr_r->value, 0, 32); - cortex_a8_write_core_reg(target, cpsr_r, - 16, ARMV4_5_MODE_ANY, mode); - } - } - - - if (num == 16) { - switch (mode) { - case ARMV4_5_MODE_USR: - case ARMV4_5_MODE_SYS: - case ARMV4_5_MODE_ANY: - /* CPSR */ - break; - default: - /* SPSR */ - cookie++; - break; - } - } - - cortex_a8_dap_write_coreregister_u32(target, value, cookie); - if ((retval = jtag_execute_queue()) == ERROR_OK) { - buf_set_u32(r->value, 0, 32, value); - r->valid = 1; - r->dirty = 0; - } - - if (cpsr_r) - cortex_a8_write_core_reg(target, cpsr_r, - 16, ARMV4_5_MODE_ANY, cpsr); - return retval; -} - - /* * Cortex-A8 Breakpoint and watchpoint fuctions */ @@ -1696,6 +1420,8 @@ static int cortex_a8_examine_first(struct target *target) LOG_DEBUG("ttypr = 0x%08" PRIx32, ttypr); LOG_DEBUG("didr = 0x%08" PRIx32, didr); + cortex_a8_dpm_setup(cortex_a8, didr); + /* Setup Breakpoint Register Pairs */ cortex_a8->brp_num = ((didr >> 24) & 0x0F) + 1; cortex_a8->brp_num_context = ((didr >> 20) & 0x0F) + 1; @@ -1752,21 +1478,10 @@ static int cortex_a8_examine(struct target *target) * Cortex-A8 target creation and initialization */ -static void cortex_a8_build_reg_cache(struct target *target) -{ - struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); - struct arm *armv4_5 = target_to_armv4_5(target); - - armv4_5->core_type = ARM_MODE_MON; - - (*cache_p) = armv4_5_build_reg_cache(target, armv4_5); -} - - static int cortex_a8_init_target(struct command_context *cmd_ctx, struct target *target) { - cortex_a8_build_reg_cache(target); + /* examine_first() does a bunch of this */ return ERROR_OK; } @@ -1818,9 +1533,6 @@ static int cortex_a8_init_arch_info(struct target *target, // arm7_9->handle_target_request = cortex_a8_handle_target_request; - armv4_5->read_core_reg = cortex_a8_read_core_reg; - armv4_5->write_core_reg = cortex_a8_write_core_reg; - /* REVISIT v7a setup should be in a v7a-specific routine */ armv4_5_init_arch_info(target, armv4_5); armv7a->common_magic = ARMV7_COMMON_MAGIC; commit c008d30fe85a674842632e32d732e22e0a91b95d Author: David Brownell <dbr...@us...> Date: Tue Nov 24 21:24:44 2009 -0800 Cortex-A8: implement DPM This implements the DPM interface for Cortex-A8 cores. It also adds a synchronization operation to the DPM framework, which is needed by the Cortex-A8 after CPSR writes. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm_dpm.c b/src/target/arm_dpm.c index 18a9dcc..b8107d7 100644 --- a/src/target/arm_dpm.c +++ b/src/target/arm_dpm.c @@ -52,10 +52,8 @@ static int dpm_modeswitch(struct arm_dpm *dpm, enum armv4_5_mode mode) retval = dpm->instr_write_data_r0(dpm, ARMV4_5_MSR_GP(0, 0xf, 0), cpsr); - /* REVISIT on Cortex-A8, we need a Prefetch Flush operation too ... - cortex_a8_exec_opcode(target, - ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); - */ + if (dpm->instr_cpsr_sync) + retval = dpm->instr_cpsr_sync(dpm); return retval; } @@ -142,11 +140,8 @@ static int dpm_write_reg(struct arm_dpm *dpm, struct reg *r, unsigned regnum) ARMV4_5_MSR_GP(0, 0xf, regnum & 1), value); - /* REVISIT on Cortex-A8, we need a Prefetch Flush operation - * after writing CPSR ... - cortex_a8_exec_opcode(target, - ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); - */ + if (regnum == 16 && dpm->instr_cpsr_sync) + retval = dpm->instr_cpsr_sync(dpm); break; } diff --git a/src/target/arm_dpm.h b/src/target/arm_dpm.h index 06b548e..67ce218 100644 --- a/src/target/arm_dpm.h +++ b/src/target/arm_dpm.h @@ -61,6 +61,9 @@ struct arm_dpm { int (*instr_write_data_r0)(struct arm_dpm *, uint32_t opcode, uint32_t data); + /** Optional core-specific operation invoked after CPSR writes. */ + int (*instr_cpsr_sync)(struct arm_dpm *dpm); + /* READ FROM CPU */ /** Runs one instruction, reading data from dcc after execution. */ diff --git a/src/target/armv7a.h b/src/target/armv7a.h index 51f7b45..942bf8b 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -23,6 +23,7 @@ #include "armv4_5.h" #include "armv4_5_mmu.h" #include "armv4_5_cache.h" +#include "arm_dpm.h" enum { @@ -53,6 +54,7 @@ struct armv7a_common struct swjdp_common swjdp_info; /* Core Debug Unit */ + struct arm_dpm dpm; uint32_t debug_base; uint8_t debug_ap; uint8_t memory_ap; diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index f549fb3..28c75b5 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -352,6 +352,173 @@ static int cortex_a8_dap_write_memap_register_u32(struct target *target, uint32_ } /* + * Cortex-A8 implementation of Debug Programmer's Model + * + * NOTE that in several of these cases the "stall" mode might be useful. + * It'd let us queue a few operations together... prepare/finish might + * be the places to enable/disable that mode. + */ + +static inline struct cortex_a8_common *dpm_to_a8(struct arm_dpm *dpm) +{ + return container_of(dpm, struct cortex_a8_common, armv7a_common.dpm); +} + +static int cortex_a8_write_dcc(struct cortex_a8_common *a8, uint32_t data) +{ + LOG_DEBUG("write DCC 0x%08" PRIx32, data); + return mem_ap_write_u32(&a8->armv7a_common.swjdp_info, + a8->armv7a_common.debug_base + CPUDBG_DTRRX, data); +} + +static int cortex_a8_read_dcc(struct cortex_a8_common *a8, uint32_t *data) +{ + struct swjdp_common *swjdp = &a8->armv7a_common.swjdp_info; + uint32_t dscr; + int retval; + + /* Wait for DTRRXfull */ + do { + retval = mem_ap_read_atomic_u32(swjdp, + a8->armv7a_common.debug_base + CPUDBG_DSCR, + &dscr); + } while ((dscr & (1 << DSCR_DTR_TX_FULL)) == 0); + + retval = mem_ap_read_atomic_u32(swjdp, + a8->armv7a_common.debug_base + CPUDBG_DTRTX, data); + LOG_DEBUG("read DCC 0x%08" PRIx32, *data); + + return retval; +} + +static int cortex_a8_dpm_prepare(struct arm_dpm *dpm) +{ + struct cortex_a8_common *a8 = dpm_to_a8(dpm); + struct swjdp_common *swjdp = &a8->armv7a_common.swjdp_info; + uint32_t dscr; + int retval; + + retval = mem_ap_read_atomic_u32(swjdp, + a8->armv7a_common.debug_base + CPUDBG_DSCR, + &dscr); + + /* this "should never happen" ... */ + if (dscr & (1 << DSCR_DTR_RX_FULL)) { + LOG_ERROR("DSCR_DTR_RX_FULL, dscr 0x%08" PRIx32, dscr); + /* Clear DCCRX */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + } + + return retval; +} + +static int cortex_a8_dpm_finish(struct arm_dpm *dpm) +{ + /* REVISIT what could be done here? */ + return ERROR_OK; +} + +static int cortex_a8_instr_write_data_dcc(struct arm_dpm *dpm, + uint32_t opcode, uint32_t data) +{ + struct cortex_a8_common *a8 = dpm_to_a8(dpm); + int retval; + + retval = cortex_a8_write_dcc(a8, data); + + return cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + opcode); +} + +static int cortex_a8_instr_write_data_r0(struct arm_dpm *dpm, + uint32_t opcode, uint32_t data) +{ + struct cortex_a8_common *a8 = dpm_to_a8(dpm); + int retval; + + retval = cortex_a8_write_dcc(a8, data); + + /* DCCRX to R0, "MCR p14, 0, R0, c0, c5, 0", 0xEE000E15 */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + ARMV4_5_MRC(14, 0, 0, 0, 5, 0)); + + /* then the opcode, taking data from R0 */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + opcode); + + return retval; +} + +static int cortex_a8_instr_cpsr_sync(struct arm_dpm *dpm) +{ + struct target *target = dpm->arm->target; + + /* "Prefetch flush" after modifying execution status in CPSR */ + return cortex_a8_exec_opcode(target, ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); +} + +static int cortex_a8_instr_read_data_dcc(struct arm_dpm *dpm, + uint32_t opcode, uint32_t *data) +{ + struct cortex_a8_common *a8 = dpm_to_a8(dpm); + int retval; + + /* the opcode, writing data to DCC */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + opcode); + + return cortex_a8_read_dcc(a8, data); +} + + +static int cortex_a8_instr_read_data_r0(struct arm_dpm *dpm, + uint32_t opcode, uint32_t *data) +{ + struct cortex_a8_common *a8 = dpm_to_a8(dpm); + int retval; + + /* the opcode, writing data to R0 */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + opcode); + + /* write R0 to DCC */ + retval = cortex_a8_exec_opcode( + a8->armv7a_common.armv4_5_common.target, + ARMV4_5_MCR(14, 0, 0, 0, 5, 0)); + + return cortex_a8_read_dcc(a8, data); +} + +// static +int cortex_a8_dpm_setup(struct cortex_a8_common *a8, uint32_t didr) +{ + struct arm_dpm *dpm = &a8->armv7a_common.dpm; + + dpm->arm = &a8->armv7a_common.armv4_5_common; + dpm->didr = didr; + + dpm->prepare = cortex_a8_dpm_prepare; + dpm->finish = cortex_a8_dpm_finish; + + dpm->instr_write_data_dcc = cortex_a8_instr_write_data_dcc; + dpm->instr_write_data_r0 = cortex_a8_instr_write_data_r0; + dpm->instr_cpsr_sync = cortex_a8_instr_cpsr_sync; + + dpm->instr_read_data_dcc = cortex_a8_instr_read_data_dcc; + dpm->instr_read_data_r0 = cortex_a8_instr_read_data_r0; + + return arm_dpm_setup(dpm); +} + + +/* * Cortex-A8 Run control */ commit 991daa03ebbc69829be4a3899b77efb981254038 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 21:24:44 2009 -0800 Cortex-A8: minor cleanup Make various functions static, add some comments, report vector catch as a flavor of DBG_REASON_BREAKPOINT, get rid of needless/undesirable ARMV4_5_CORE_REG_MODE, etc. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index b006e81..f549fb3 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -89,7 +89,12 @@ static int cortex_a8_init_debug_access(struct target *target) return retval; } -int cortex_a8_exec_opcode(struct target *target, uint32_t opcode) +/* FIXME we waste a *LOT* of round-trips with needless DSCR reads, which + * slows down operations considerably. One good way to start reducing + * them would pass current values into and out of this routine. That + * should also help synch DCC read/write. + */ +static int cortex_a8_exec_opcode(struct target *target, uint32_t opcode) { uint32_t dscr; int retval; @@ -592,6 +597,12 @@ static int cortex_a8_debug_entry(struct target *target) /* Enable the ITR execution once we are in debug mode */ mem_ap_read_atomic_u32(swjdp, armv7a->debug_base + CPUDBG_DSCR, &dscr); + + /* REVISIT see A8 TRM 12.11.4 steps 2..3 -- make sure that any + * imprecise data aborts get discarded by issuing a Data + * Synchronization Barrier: ARMV4_5_MCR(15, 0, 0, 7, 10, 4). + */ + dscr |= (1 << DSCR_EXT_INT_EN); retval = mem_ap_write_atomic_u32(swjdp, armv7a->debug_base + CPUDBG_DSCR, dscr); @@ -599,22 +610,28 @@ static int cortex_a8_debug_entry(struct target *target) /* Examine debug reason */ switch ((cortex_a8->cpudbg_dscr >> 2)&0xF) { - case 0: - case 4: + case 0: /* DRCR[0] write */ + case 4: /* EDBGRQ */ target->debug_reason = DBG_REASON_DBGRQ; break; - case 1: - case 3: + case 1: /* HW breakpoint */ + case 3: /* SW BKPT */ + case 5: /* vector catch */ target->debug_reason = DBG_REASON_BREAKPOINT; break; - case 10: + case 10: /* precise watchpoint */ target->debug_reason = DBG_REASON_WATCHPOINT; + /* REVISIT could collect WFAR later, to see just + * which instruction triggered the watchpoint. + */ break; default: target->debug_reason = DBG_REASON_UNDEFINED; break; } + /* REVISIT fast_reg_read is never set ... */ + /* Examine target state and mode */ if (cortex_a8->fast_reg_read) target_alloc_working_area(target, 64, ®file_working_area); @@ -738,6 +755,7 @@ static int cortex_a8_step(struct target *target, int current, uint32_t address, struct arm *armv4_5 = &armv7a->armv4_5_common; struct breakpoint *breakpoint = NULL; struct breakpoint stepbreakpoint; + struct reg *r; int timeout = 100; @@ -748,17 +766,14 @@ static int cortex_a8_step(struct target *target, int current, uint32_t address, } /* current = 1: continue on current pc, otherwise continue at <address> */ + r = armv4_5->core_cache->reg_list + 15; if (!current) { - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, ARM_PC).value, - 0, 32, address); + buf_set_u32(r->value, 0, 32, address); } else { - address = buf_get_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, ARM_PC).value, - 0, 32); + address = buf_get_u32(r->value, 0, 32); } /* The front-end may request us not to handle breakpoints. @@ -767,11 +782,7 @@ static int cortex_a8_step(struct target *target, int current, uint32_t address, */ handle_breakpoints = 1; if (handle_breakpoints) { - breakpoint = breakpoint_find(target, - buf_get_u32(ARMV4_5_CORE_REG_MODE( - armv4_5->core_cache, - armv4_5->core_mode, 15).value, - 0, 32)); + breakpoint = breakpoint_find(target, address); if (breakpoint) cortex_a8_unset_breakpoint(target, breakpoint); } @@ -1235,7 +1246,8 @@ static int cortex_a8_unset_breakpoint(struct target *target, struct breakpoint * return ERROR_OK; } -int cortex_a8_add_breakpoint(struct target *target, struct breakpoint *breakpoint) +static int cortex_a8_add_breakpoint(struct target *target, + struct breakpoint *breakpoint) { struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target); @@ -1346,7 +1358,7 @@ static int cortex_a8_read_memory(struct target *target, uint32_t address, return retval; } -int cortex_a8_write_memory(struct target *target, uint32_t address, +static int cortex_a8_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer) { struct armv7a_common *armv7a = target_to_armv7a(target); @@ -1591,7 +1603,7 @@ static int cortex_a8_init_target(struct command_context *cmd_ctx, return ERROR_OK; } -int cortex_a8_init_arch_info(struct target *target, +static int cortex_a8_init_arch_info(struct target *target, struct cortex_a8_common *cortex_a8, struct jtag_tap *tap) { struct armv7a_common *armv7a = &cortex_a8->armv7a_common; @@ -1605,7 +1617,7 @@ int cortex_a8_init_arch_info(struct target *target, /* prepare JTAG information for the new target */ cortex_a8->jtag_info.tap = tap; cortex_a8->jtag_info.scann_size = 4; -LOG_DEBUG(" "); + swjdp->dp_select_value = -1; swjdp->ap_csw_value = -1; swjdp->ap_tar_value = -1; diff --git a/src/target/cortex_a8.h b/src/target/cortex_a8.h index 393a310..1cb0e57 100644 --- a/src/target/cortex_a8.h +++ b/src/target/cortex_a8.h @@ -85,7 +85,7 @@ struct cortex_a8_brp int type; uint32_t value; uint32_t control; - uint8_t BRPn; + uint8_t BRPn; }; struct cortex_a8_wrp @@ -94,7 +94,7 @@ struct cortex_a8_wrp int type; uint32_t value; uint32_t control; - uint8_t WRPn; + uint8_t WRPn; }; struct cortex_a8_common @@ -140,7 +140,4 @@ target_to_cortex_a8(struct target *target) armv7a_common.armv4_5_common); } -int cortex_a8_init_arch_info(struct target *target, - struct cortex_a8_common *cortex_a8, struct jtag_tap *tap); - #endif /* CORTEX_A8_H */ ----------------------------------------------------------------------- Summary of changes: src/target/arm_dpm.c | 13 +- src/target/arm_dpm.h | 3 + src/target/armv7a.h | 2 + src/target/cortex_a8.c | 682 ++++++++++++++++++++++-------------------------- src/target/cortex_a8.h | 7 +- 5 files changed, 325 insertions(+), 382 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-24 22:16:52
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 338a674faa96ae321560efa3f1b1e8122d61aac4 (commit) from 5507b5f430e3d6bef00a7ffcd51df29c13d7477e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 338a674faa96ae321560efa3f1b1e8122d61aac4 Author: Andreas Fritiofson <and...@gm...> Date: Tue Nov 24 21:24:06 2009 +0100 improve alloc_vprintf The previous implementation was unnecessarily complex. Get rid of the loops, let vsnprintf() tell us directly how much storage we need and allocate that. A second pass writes the actual string. Also add a va_end() that was missing. This should be much faster for large strings and less wasteful for small ones. A quirk that has been retained is that some callers patch in a newline at the end of the returned string and depend on alloc_vprintf to allocate at least one byte extra. Signed-off-by: Andreas Fritiofson <and...@gm...> Signed-off-by: Zachary T Welch <zw...@su...> diff --git a/src/helper/log.c b/src/helper/log.c index caaed42..2dcf7bb 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -395,37 +395,26 @@ int log_remove_callback(log_callback_fn fn, void *priv) /* return allocated string w/printf() result */ char *alloc_vprintf(const char *fmt, va_list ap) { - /* no buffer at the beginning, force realloc to do the job */ - char *string = NULL; - - /* start with buffer size suitable for typical messages */ - int size = 128; - - for (;;) - { - char *t = string; - va_list ap_copy; - int ret; - string = realloc(string, size); - if (string == NULL) - { - if (t != NULL) - free(t); - return NULL; - } + va_list ap_copy; + int len; + char *string; - va_copy(ap_copy, ap); + /* determine the length of the buffer needed */ + va_copy(ap_copy, ap); + len = vsnprintf(NULL, 0, fmt, ap_copy); + va_end(ap_copy); - ret = vsnprintf(string, size, fmt, ap_copy); - /* NB! The result of the vsnprintf() might be an *EMPTY* string! */ - if ((ret >= 0) && ((ret + 1) < size)) - break; + /* allocate and make room for terminating zero. */ + /* FIXME: The old version always allocated at least one byte extra and + * other code depend on that. They should be probably be fixed, but for + * now reserve the extra byte. */ + string = malloc(len + 2); + if (string == NULL) + return NULL; - /* there was just enough or not enough space, allocate more in the next round */ - size *= 2; /* double the buffer size */ - } + /* do the real work */ + vsnprintf(string, len + 1, fmt, ap); - /* the returned buffer is by principle guaranteed to be at least one character longer */ return string; } ----------------------------------------------------------------------- Summary of changes: src/helper/log.c | 43 ++++++++++++++++--------------------------- 1 files changed, 16 insertions(+), 27 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-24 20:24:36
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 5507b5f430e3d6bef00a7ffcd51df29c13d7477e (commit) from 96f0ab894adf606526325cd0b0d0c25413d448b8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5507b5f430e3d6bef00a7ffcd51df29c13d7477e Author: Zachary T Welch <zw...@su...> Date: Tue Nov 24 08:59:45 2009 -0800 fix doxygen build Update build rules to skip the PDF unless the TeX has been created. Also, fixes a warning regarding pattern rules being a GNU make trick. diff --git a/Makefile.am b/Makefile.am index c067712..fab4704 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,9 +35,14 @@ THE_MANUAL = doxygen/latex/refman.pdf doxygen:: $(MAKE) Doxyfile doxygen Doxyfile 2>&1 | perl $(srcdir)/tools/logger.pl > doxygen.log - $(MAKE) $(THE_MANUAL) - -%.pdf: %.tex + @if [ -f doxygen/latex/refman.tex ]; then \ + echo "Creating $(THE_MANUAL)..."; \ + $(MAKE) $(THE_MANUAL); \ + else \ + echo "Skipping Doxygen PDF..."; \ + fi + +$(THE_MANUAL): %.pdf: %.tex -cd $$(dirname $*) && pdflatex $$(basename $*) -cd $$(dirname $*) && pdflatex $$(basename $*) ----------------------------------------------------------------------- Summary of changes: Makefile.am | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Zach W. <zw...@us...> - 2009-11-24 18:04:38
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 96f0ab894adf606526325cd0b0d0c25413d448b8 (commit) via 31fc1586a064b8631956095cb029290e1dc6625f (commit) via 9a21ef7614d6de4b3c03db625eca07c0eed045c3 (commit) via ec5e484fd60d1f4ea1f476b57520f4e7e73e8de4 (commit) via de9a182ca6e29611181fec95cff539fd329bdd2e (commit) via 0f544f4310dcd9e056f668f5ddceaad5d7725801 (commit) via d836b079b413e8cbd30267a741f09b6c6f44f378 (commit) via 3a660e229301c905392a0b2826e5ebf08c4e01b9 (commit) from 3efc99b34a934cb4d657ec27a164769c46c10f28 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 96f0ab894adf606526325cd0b0d0c25413d448b8 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:57:32 2009 -0800 jlink: rewrite to use jtag_usb_open Rewrite jlink_usb_open to use jtag_usb_open helper. diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 8f1d112..f173ed7 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -27,8 +27,7 @@ #include "interface.h" #include "commands.h" - -#include <usb.h> +#include "usb_common.h" #define VID 0x1366 @@ -818,53 +817,17 @@ static int jlink_tap_execute(void) return ERROR_OK; } -static struct usb_device* find_jlink_device(void) -{ - struct usb_bus *busses; - struct usb_bus *bus; - struct usb_device *dev; - - usb_find_busses(); - usb_find_devices(); - - busses = usb_get_busses(); - - /* find jlink device in usb bus */ - - for (bus = busses; bus; bus = bus->next) - { - for (dev = bus->devices; dev; dev = dev->next) - { - if ((dev->descriptor.idVendor == VID) && (dev->descriptor.idProduct == PID)) { - return dev; - } - } - } - - return NULL; -} - /*****************************************************************************/ /* JLink USB low-level functions */ static struct jlink* jlink_usb_open() { - struct usb_device *dev; - - struct jlink *result; - - result = (struct jlink*) malloc(sizeof(struct jlink)); - usb_init(); - if ((dev = find_jlink_device()) == NULL) { - free(result); - return NULL; - } - - result->usb_handle = usb_open(dev); - - if (NULL == result->usb_handle) + const uint16_t vids[] = { VID, 0 }; + const uint16_t pids[] = { PID, 0 }; + struct usb_dev_handle *dev; + if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) return NULL; /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS @@ -880,15 +843,15 @@ static struct jlink* jlink_usb_open() #if IS_WIN32 == 0 - usb_reset(result->usb_handle); + usb_reset(dev); #if IS_DARWIN == 0 int timeout = 5; - /* reopen jlink after usb_reset * on win32 this may take a second or two to re-enumerate */ - while ((dev = find_jlink_device()) == NULL) + int retval; + while ((retval = jtag_usb_open(vids, pids, &dev)) != ERROR_OK) { usleep(1000); timeout--; @@ -896,27 +859,16 @@ static struct jlink* jlink_usb_open() break; } } - - if (dev == NULL) - { - free(result); + if (ERROR_OK != retval) return NULL; - } - - result->usb_handle = usb_open(dev); #endif #endif - if (NULL == result->usb_handle) - { - free(result); - return NULL; - } - /* usb_set_configuration required under win32 */ - usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue); - usb_claim_interface(result->usb_handle, 0); + struct usb_device *udev = usb_device(dev); + usb_set_configuration(dev, udev->config[0].bConfigurationValue); + usb_claim_interface(dev, 0); #if 0 /* @@ -925,7 +877,7 @@ static struct jlink* jlink_usb_open() */ usb_set_altinterface(result->usb_handle, 0); #endif - struct usb_interface *iface = dev->config->interface; + struct usb_interface *iface = udev->config->interface; struct usb_interface_descriptor *desc = iface->altsetting; for (int i = 0; i < desc->bNumEndpoints; i++) { @@ -938,6 +890,8 @@ static struct jlink* jlink_usb_open() jlink_write_ep = epnum; } + struct jlink *result = malloc(sizeof(struct jlink)); + result->usb_handle = dev; return result; } commit 31fc1586a064b8631956095cb029290e1dc6625f Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:41:25 2009 -0800 jlink: remove superfluous indentation Rewrite logic to remove indentation in jlink_usb_open, in prep for further surgery. diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index ebc9acd..8f1d112 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -864,78 +864,81 @@ static struct jlink* jlink_usb_open() result->usb_handle = usb_open(dev); - if (result->usb_handle) - { + if (NULL == result->usb_handle) + return NULL; - /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS AREA!!!!!!!!!!! - * The behavior of libusb is not completely consistent across Windows, Linux, and Mac OS X platforms. The actions taken - * in the following compiler conditionals may not agree with published documentation for libusb, but were found - * to be necessary through trials and tribulations. Even little tweaks can break one or more platforms, so if you do make changes - * test them carefully on all platforms before committing them! - */ + /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS + * AREA!!!!!!!!!!! The behavior of libusb is not completely + * consistent across Windows, Linux, and Mac OS X platforms. + * The actions taken in the following compiler conditionals may + * not agree with published documentation for libusb, but were + * found to be necessary through trials and tribulations. Even + * little tweaks can break one or more platforms, so if you do + * make changes test them carefully on all platforms before + * committing them! + */ #if IS_WIN32 == 0 - usb_reset(result->usb_handle); + usb_reset(result->usb_handle); #if IS_DARWIN == 0 - int timeout = 5; + int timeout = 5; - /* reopen jlink after usb_reset - * on win32 this may take a second or two to re-enumerate */ - while ((dev = find_jlink_device()) == NULL) - { - usleep(1000); - timeout--; - if (!timeout) { - break; - } + /* reopen jlink after usb_reset + * on win32 this may take a second or two to re-enumerate */ + while ((dev = find_jlink_device()) == NULL) + { + usleep(1000); + timeout--; + if (!timeout) { + break; } + } - if (dev == NULL) - { - free(result); - return NULL; - } + if (dev == NULL) + { + free(result); + return NULL; + } - result->usb_handle = usb_open(dev); + result->usb_handle = usb_open(dev); #endif #endif - if (result->usb_handle) - { - /* usb_set_configuration required under win32 */ - usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue); - usb_claim_interface(result->usb_handle, 0); + if (NULL == result->usb_handle) + { + free(result); + return NULL; + } + + /* usb_set_configuration required under win32 */ + usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue); + usb_claim_interface(result->usb_handle, 0); #if 0 - /* - * This makes problems under Mac OS X. And is not needed - * under Windows. Hopefully this will not break a linux build - */ - usb_set_altinterface(result->usb_handle, 0); + /* + * This makes problems under Mac OS X. And is not needed + * under Windows. Hopefully this will not break a linux build + */ + usb_set_altinterface(result->usb_handle, 0); #endif - struct usb_interface *iface = dev->config->interface; - struct usb_interface_descriptor *desc = iface->altsetting; - for (int i = 0; i < desc->bNumEndpoints; i++) - { - uint8_t epnum = desc->endpoint[i].bEndpointAddress; - bool is_input = epnum & 0x80; - LOG_DEBUG("usb ep %s %02x", is_input ? "in" : "out", epnum); - if (is_input) - jlink_read_ep = epnum; - else - jlink_write_ep = epnum; - } - - return result; - } + struct usb_interface *iface = dev->config->interface; + struct usb_interface_descriptor *desc = iface->altsetting; + for (int i = 0; i < desc->bNumEndpoints; i++) + { + uint8_t epnum = desc->endpoint[i].bEndpointAddress; + bool is_input = epnum & 0x80; + LOG_DEBUG("usb ep %s %02x", is_input ? "in" : "out", epnum); + if (is_input) + jlink_read_ep = epnum; + else + jlink_write_ep = epnum; } - free(result); - return NULL; + return result; } static void jlink_usb_close(struct jlink *jlink) commit 9a21ef7614d6de4b3c03db625eca07c0eed045c3 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:25:16 2009 -0800 rlink: use jtag_usb_open helper Rewrite rlink_init routine to use jtag_usb_open helper. Eliminates some spurious calls to exit(). Wraps a tremendously long line of comment to fit 80 columns too. diff --git a/src/jtag/rlink/rlink.c b/src/jtag/rlink/rlink.c index 2cdc70a..6fb721d 100644 --- a/src/jtag/rlink/rlink.c +++ b/src/jtag/rlink/rlink.c @@ -34,9 +34,7 @@ #include "st7.h" #include "ep1_cmd.h" #include "dtc_cmd.h" - -/* system includes */ -#include <usb.h> +#include "usb_common.h" /* This feature is made useless by running the DTC all the time. When automatic, the LED is on whenever the DTC is running. Otherwise, USB messages are sent to turn it on and off. */ @@ -1616,103 +1614,72 @@ int rlink_register_commands(struct command_context *cmd_ctx) static int rlink_init(void) { - struct usb_bus *busses; - struct usb_bus *bus; int i, j, retries; - int found = 0; - int success = 0; uint8_t reply_buffer[USB_EP1IN_SIZE]; usb_init(); - usb_find_busses(); - usb_find_devices(); - - busses = usb_get_busses(); + const uint16_t vids[] = { USB_IDVENDOR, 0 }; + const uint16_t pids[] = { USB_IDPRODUCT, 0 }; + if (jtag_usb_open(vids, pids, &pHDev) != ERROR_OK) + return ERROR_FAIL; - for (bus = busses; bus; bus = bus->next) + struct usb_device *dev = usb_device(pHDev); + if (dev->descriptor.bNumConfigurations > 1) { - struct usb_device *dev; - - for (dev = bus->devices; dev; dev = dev->next) - { - if ((dev->descriptor.idVendor != USB_IDVENDOR) || - (dev->descriptor.idProduct != USB_IDPRODUCT)) - { - continue; - } - found = 1; - LOG_DEBUG("Found device on bus.\n"); - - if (dev->descriptor.bNumConfigurations > 1) - { - LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n"); - break; - } - if (dev->config->bNumInterfaces > 1) - { - LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n"); - break; - } + LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n"); + return ERROR_FAIL; + } + if (dev->config->bNumInterfaces > 1) + { + LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n"); + return ERROR_FAIL; + } - pHDev = usb_open(dev); - if (!pHDev) - { - LOG_ERROR ("Failed to open device.\n"); - break; - } - LOG_DEBUG("Opened device, pHDev = %p\n",pHDev); + LOG_DEBUG("Opened device, pHDev = %p\n", pHDev); - /* usb_set_configuration required under win32 */ - usb_set_configuration(pHDev, dev->config[0].bConfigurationValue); + /* usb_set_configuration required under win32 */ + usb_set_configuration(pHDev, dev->config[0].bConfigurationValue); - retries = 3; - do - { - i = usb_claim_interface(pHDev,0); - if (i) - { - LOG_ERROR("usb_claim_interface: %s", usb_strerror()); + retries = 3; + do + { + i = usb_claim_interface(pHDev,0); + if (i) + { + LOG_ERROR("usb_claim_interface: %s", usb_strerror()); #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP - j = usb_detach_kernel_driver_np(pHDev, 0); - if (j) - LOG_ERROR("detach kernel driver: %s", usb_strerror()); + j = usb_detach_kernel_driver_np(pHDev, 0); + if (j) + LOG_ERROR("detach kernel driver: %s", usb_strerror()); #endif - } - else - { - LOG_DEBUG("interface claimed!\n"); - break; - } - } while (--retries); - - if (!i) - { - if (usb_set_altinterface(pHDev,0)) - { - LOG_ERROR("Failed to set interface.\n"); - break; - } - else - success = 1; - } } - } + else + { + LOG_DEBUG("interface claimed!\n"); + break; + } + } while (--retries); - if (!found) + if (i) { - LOG_ERROR("No device found on bus.\n"); - exit(1); + LOG_ERROR("Initialisation failed."); + return ERROR_FAIL; } - - if (!success) + if (usb_set_altinterface(pHDev,0) != 0) { - LOG_ERROR("Initialisation failed."); - exit(1); + LOG_ERROR("Failed to set interface.\n"); + return ERROR_FAIL; } - - /* The device starts out in an unknown state on open. As such, result reads time out, and it's not even known whether the command was accepted. So, for this first command, we issue it repeatedly until its response doesn't time out. Also, if sending a command is going to time out, we'll find that out here. */ - /* It must be possible to open the device in such a way that this special magic isn't needed, but, so far, it escapes us. */ + /* The device starts out in an unknown state on open. As such, + * result reads time out, and it's not even known whether the + * command was accepted. So, for this first command, we issue + * it repeatedly until its response doesn't time out. Also, if + * sending a command is going to time out, we find that out here. + * + * It must be possible to open the device in such a way that + * this special magic isn't needed, but, so far, it escapes us. + */ for (i = 0; i < 5; i++) { j = ep1_generic_commandl( pHDev, 1, commit ec5e484fd60d1f4ea1f476b57520f4e7e73e8de4 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:12:21 2009 -0800 rlink: eliminate spurious indentation Rework rlink_init to use less indentation. Best viewed with diff -w. diff --git a/src/jtag/rlink/rlink.c b/src/jtag/rlink/rlink.c index c88067c..2cdc70a 100644 --- a/src/jtag/rlink/rlink.c +++ b/src/jtag/rlink/rlink.c @@ -1635,66 +1635,65 @@ int rlink_init(void) for (dev = bus->devices; dev; dev = dev->next) { - if ((dev->descriptor.idVendor == USB_IDVENDOR) && (dev->descriptor.idProduct == USB_IDPRODUCT)) + if ((dev->descriptor.idVendor != USB_IDVENDOR) || + (dev->descriptor.idProduct != USB_IDPRODUCT)) { - found = 1; - LOG_DEBUG("Found device on bus.\n"); + continue; + } + found = 1; + LOG_DEBUG("Found device on bus.\n"); - do - { - if (dev->descriptor.bNumConfigurations > 1) - { - LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n"); - break; - } - if (dev->config->bNumInterfaces > 1) - { - LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n"); - break; - } + if (dev->descriptor.bNumConfigurations > 1) + { + LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n"); + break; + } + if (dev->config->bNumInterfaces > 1) + { + LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n"); + break; + } + + pHDev = usb_open(dev); + if (!pHDev) + { + LOG_ERROR ("Failed to open device.\n"); + break; + } + LOG_DEBUG("Opened device, pHDev = %p\n",pHDev); + + /* usb_set_configuration required under win32 */ + usb_set_configuration(pHDev, dev->config[0].bConfigurationValue); - pHDev = usb_open(dev); - if (!pHDev) - LOG_ERROR ("Failed to open device.\n"); - else - { - LOG_DEBUG("Opened device, pHDev = %p\n",pHDev); - - /* usb_set_configuration required under win32 */ - usb_set_configuration(pHDev, dev->config[0].bConfigurationValue); - - retries = 3; - do - { - i = usb_claim_interface(pHDev,0); - if (i) - { - LOG_ERROR("usb_claim_interface: %s", usb_strerror()); + retries = 3; + do + { + i = usb_claim_interface(pHDev,0); + if (i) + { + LOG_ERROR("usb_claim_interface: %s", usb_strerror()); #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP - j = usb_detach_kernel_driver_np(pHDev, 0); - if (j) - LOG_ERROR("detach kernel driver: %s", usb_strerror()); + j = usb_detach_kernel_driver_np(pHDev, 0); + if (j) + LOG_ERROR("detach kernel driver: %s", usb_strerror()); #endif - } - else - { - LOG_DEBUG("interface claimed!\n"); - break; - } - } while (--retries); - - if (!i) - { - if (usb_set_altinterface(pHDev,0)) - { - LOG_ERROR("Failed to set interface.\n"); - break; - } - else - success = 1; - } - } - } while (0); + } + else + { + LOG_DEBUG("interface claimed!\n"); + break; + } + } while (--retries); + + if (!i) + { + if (usb_set_altinterface(pHDev,0)) + { + LOG_ERROR("Failed to set interface.\n"); + break; + } + else + success = 1; } } } commit de9a182ca6e29611181fec95cff539fd329bdd2e Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:11:03 2009 -0800 vsllink: rewrite to use jtag_usb_open Rewrite vsllink_usb_open to use jtag_usb_open helper. Eliminates spurious calls to exit(). diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c index 7962249..d28854d 100644 --- a/src/jtag/vsllink.c +++ b/src/jtag/vsllink.c @@ -28,9 +28,7 @@ #include "interface.h" #include "commands.h" - -#include <usb.h> - +#include "usb_common.h" //#define _VSLLINK_IN_DEBUG_MODE_ @@ -1703,64 +1701,42 @@ static int vsllink_tap_execute_dma(void) static struct vsllink* vsllink_usb_open(void) { - struct usb_bus *busses; - struct usb_bus *bus; - struct usb_device *dev; - int ret; - - struct vsllink *result; - - result = (struct vsllink*) malloc(sizeof(struct vsllink)); - usb_init(); - usb_find_busses(); - usb_find_devices(); - busses = usb_get_busses(); + const uint16_t vids[] = { vsllink_usb_vid, 0 }; + const uint16_t pids[] = { vsllink_usb_pid, 0 }; + struct usb_dev_handle *dev; + if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + return NULL; - /* find vsllink device in usb bus */ - - for (bus = busses; bus; bus = bus->next) + /* usb_set_configuration required under win32 */ + struct usb_device *udev = usb_device(dev); + int ret = usb_set_configuration(dev, udev->config[0].bConfigurationValue); + if (ret != 0) { - for (dev = bus->devices; dev; dev = dev->next) - { - if ((dev->descriptor.idVendor == vsllink_usb_vid) && (dev->descriptor.idProduct == vsllink_usb_pid)) - { - result->usb_handle = usb_open(dev); - if (NULL == result->usb_handle) - { - LOG_ERROR("failed to open %04X:%04X, not enough permissions?", vsllink_usb_vid, vsllink_usb_pid); - exit(-1); - } - - /* usb_set_configuration required under win32 */ - ret = usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue); - if (ret != 0) - { - LOG_ERROR("fail to set configuration to %d, %d returned, not enough permissions?", dev->config[0].bConfigurationValue, ret); - exit(-1); - } - ret = usb_claim_interface(result->usb_handle, vsllink_usb_interface); - if (ret != 0) - { - LOG_ERROR("fail to claim interface %d, %d returned", vsllink_usb_interface, ret); - exit(-1); - } - + LOG_ERROR("fail to set configuration to %d (error %d)." + "Not enough permissions for the device?", + udev->config[0].bConfigurationValue, ret); + return NULL; + } + ret = usb_claim_interface(dev, vsllink_usb_interface); + if (ret != 0) + { + LOG_ERROR("fail to claim interface %d, %d returned", + vsllink_usb_interface, ret); + return NULL; + } #if 0 - /* - * This makes problems under Mac OS X. And is not needed - * under Windows. Hopefully this will not break a linux build - */ - usb_set_altinterface(result->usb_handle, 0); + /* + * This makes problems under Mac OS X. And is not needed + * under Windows. Hopefully this will not break a linux build + */ + usb_set_altinterface(dev, 0); #endif - return result; - } - } - } - free(result); - return NULL; + struct vsllink *result = malloc(sizeof(struct vsllink)); + result->usb_handle = dev; + return result; } static void vsllink_usb_close(struct vsllink *vsllink) commit 0f544f4310dcd9e056f668f5ddceaad5d7725801 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:09:11 2009 -0800 usbprog: use jtag_usb_open Rewrite usbprob_jtag_open to use jtag_usb_open helper. diff --git a/src/jtag/usbprog.c b/src/jtag/usbprog.c index e8c0ead..204d0e2 100644 --- a/src/jtag/usbprog.c +++ b/src/jtag/usbprog.c @@ -36,8 +36,7 @@ #include "interface.h" #include "commands.h" - -#include <usb.h> +#include "usb_common.h" #define VID 0x1781 @@ -383,39 +382,23 @@ struct usb_bus *busses; struct usbprog_jtag* usbprog_jtag_open(void) { - struct usb_bus *bus; - struct usb_device *dev; - - struct usbprog_jtag *tmp; - - tmp = (struct usbprog_jtag*)malloc(sizeof(struct usbprog_jtag)); - usb_set_debug(10); usb_init(); - usb_find_busses(); - usb_find_devices(); - busses = usb_get_busses(); + const uint16_t vids[] = { VID, 0 }; + const uint16_t pids[] = { PID, 0 }; + struct usb_dev_handle *dev; + if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + return NULL; - /* find usbprog_jtag device in usb bus */ + struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag)); + tmp->usb_handle = dev; - for (bus = busses; bus; bus = bus->next) - { - for (dev = bus->devices; dev; dev = dev->next) - { - /* condition for sucessfully hit (too bad, I only check the vendor id)*/ - if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID) - { - tmp->usb_handle = usb_open(dev); - usb_set_configuration(tmp->usb_handle, 1); - usb_claim_interface(tmp->usb_handle, 0); - usb_set_altinterface(tmp->usb_handle, 0); - return tmp; - } - } - } - free(tmp); - return 0; + usb_set_configuration(dev, 1); + usb_claim_interface(dev, 0); + usb_set_altinterface(dev, 0); + + return tmp; } #if 0 commit d836b079b413e8cbd30267a741f09b6c6f44f378 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:06:05 2009 -0800 arm-jtag-ew: use jtag_usb_open Rewrite armjtagwe_usb_open to use jtag_usb_open. diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c index 46dacc6..01c5559 100644 --- a/src/jtag/arm-jtag-ew.c +++ b/src/jtag/arm-jtag-ew.c @@ -25,6 +25,7 @@ #include "interface.h" #include "commands.h" #include <usb.h> +#include "usb_common.h" #define USB_VID 0x15ba @@ -714,50 +715,30 @@ static int armjtagew_tap_execute(void) static struct armjtagew* armjtagew_usb_open() { - struct usb_bus *busses; - struct usb_bus *bus; - struct usb_device *dev; - - struct armjtagew *result; - - result = (struct armjtagew*) malloc(sizeof(struct armjtagew)); - usb_init(); - usb_find_busses(); - usb_find_devices(); - - busses = usb_get_busses(); - /* find armjtagew device in usb bus */ + const uint16_t vids[] = { USB_VID, 0 }; + const uint16_t pids[] = { USB_PID, 0 }; + struct usb_dev_handle *dev; + if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + return NULL; - for (bus = busses; bus; bus = bus->next) - { - for (dev = bus->devices; dev; dev = dev->next) - { - if ((dev->descriptor.idVendor == USB_VID) && (dev->descriptor.idProduct == USB_PID)) - { - result->usb_handle = usb_open(dev); + struct armjtagew *result = malloc(sizeof(struct armjtagew)); + result->usb_handle = dev; #if 0 - /* usb_set_configuration required under win32 */ - usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue); + /* usb_set_configuration required under win32 */ + usb_set_configuration(dev, dev->config[0].bConfigurationValue); #endif - usb_claim_interface(result->usb_handle, 0); - + usb_claim_interface(dev, 0); #if 0 - /* - * This makes problems under Mac OS X. And is not needed - * under Windows. Hopefully this will not break a linux build - */ - usb_set_altinterface(result->usb_handle, 0); + /* + * This makes problems under Mac OS X. And is not needed + * under Windows. Hopefully this will not break a linux build + */ + usb_set_altinterface(dev, 0); #endif - return result; - } - } - } - - free(result); - return NULL; + return result; } static void armjtagew_usb_close(struct armjtagew *armjtagew) commit 3a660e229301c905392a0b2826e5ebf08c4e01b9 Author: Zachary T Welch <zw...@su...> Date: Thu Nov 19 12:02:07 2009 -0800 add jtag/usb_common.[ch] files Begins to consolidate code used by several USB JTAG interfaces. This first patch provides the required build system changes and a common jtag_usb_open routine, which will replace the guts for probing the busses and devices for possible VID/PID matches. The following patches convert each driver to use it. diff --git a/configure.in b/configure.in index 8ba8951..81e4326 100644 --- a/configure.in +++ b/configure.in @@ -996,6 +996,7 @@ if test $build_jlink = yes -o $build_vsllink = yes -o $build_usbprog = yes -o \ then AC_CHECK_HEADERS([usb.h],[], [AC_MSG_ERROR([usb.h is required to build some OpenOCD driver(s)])]) + build_usb=yes fi AM_CONDITIONAL(RELEASE, test $build_release = yes) @@ -1021,6 +1022,7 @@ AM_CONDITIONAL(JLINK, test $build_jlink = yes) AM_CONDITIONAL(VSLLINK, test $build_vsllink = yes) AM_CONDITIONAL(RLINK, test $build_rlink = yes) AM_CONDITIONAL(ARMJTAGEW, test $build_armjtagew = yes) +AM_CONDITIONAL(USB, test $build_usb = yes) AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes) AM_CONDITIONAL(IS_MINGW, test $is_mingw = yes) AM_CONDITIONAL(IS_WIN32, test $is_win32 = yes) diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am index 85d98c0..5254a2b 100644 --- a/src/jtag/Makefile.am +++ b/src/jtag/Makefile.am @@ -23,6 +23,10 @@ else # Standard Driver: common files DRIVERFILES += driver.c commands.c +if USB +DRIVERFILES += usb_common.c +endif + if BITBANG DRIVERFILES += bitbang.c endif @@ -92,7 +96,8 @@ noinst_HEADERS = \ rlink/ep1_cmd.h \ rlink/rlink.h \ rlink/st7.h \ - minidummy/jtag_minidriver.h + minidummy/jtag_minidriver.h \ + usb_common.h EXTRA_DIST = startup.tcl diff --git a/src/jtag/usb_common.c b/src/jtag/usb_common.c new file mode 100644 index 0000000..463f1af --- /dev/null +++ b/src/jtag/usb_common.c @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2009 by Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "usb_common.h" + + +static bool jtag_usb_match(struct usb_device *dev, + const uint16_t vids[], const uint16_t pids[]) +{ + for (unsigned i = 0; vids[i] && pids[i]; i++) + { + if (dev->descriptor.idVendor == vids[i] && + dev->descriptor.idProduct == pids[i]) + { + return true; + } + } + return false; +} + +int jtag_usb_open(const uint16_t vids[], const uint16_t pids[], + struct usb_dev_handle **out) +{ + usb_find_busses(); + usb_find_devices(); + + struct usb_bus *busses = usb_get_busses(); + for (struct usb_bus *bus = busses; bus; bus = bus->next) + { + for (struct usb_device *dev = bus->devices; dev; dev = dev->next) + { + if (!jtag_usb_match(dev, vids, pids)) + continue; + + *out = usb_open(dev); + if (NULL == *out) + return -errno; + return 0; + } + } + return -ENODEV; +} diff --git a/src/jtag/usb_common.h b/src/jtag/usb_common.h new file mode 100644 index 0000000..da395ad --- /dev/null +++ b/src/jtag/usb_common.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2009 by Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef JTAG_USB_COMMON_H +#define JTAG_USB_COMMON_H + +#include "types.h" + +#include <usb.h> + +int jtag_usb_open(const uint16_t vids[], const uint16_t pids[], + struct usb_dev_handle **out); + +#endif // JTAG_USB_COMMON_H ----------------------------------------------------------------------- Summary of changes: configure.in | 2 + src/jtag/Makefile.am | 7 +- src/jtag/arm-jtag-ew.c | 53 +++------ src/jtag/jlink.c | 147 +++++++++--------------- src/jtag/rlink/rlink.c | 132 ++++++++------------- src/{flash/common.c => jtag/usb_common.c} | 51 +++++--- src/{server/tcl_server.h => jtag/usb_common.h} | 16 ++- src/jtag/usbprog.c | 43 ++----- src/jtag/vsllink.c | 84 +++++--------- 9 files changed, 210 insertions(+), 325 deletions(-) copy src/{flash/common.c => jtag/usb_common.c} (65%) copy src/{server/tcl_server.h => jtag/usb_common.h} (81%) hooks/post-receive -- Main OpenOCD repository |
From: David B. <dbr...@us...> - 2009-11-24 10:28:19
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 3efc99b34a934cb4d657ec27a164769c46c10f28 (commit) via ec64acf536942168b4e038c6720c83687d3a0d08 (commit) via bf3abc48f008e0a0c0e42b943481872599463af6 (commit) via 5eb893ec41c8c6cf6499558b6fed826b65e18a16 (commit) from 6ff33a4ee8db483e29bc78b8c35e50342ca60850 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 3efc99b34a934cb4d657ec27a164769c46c10f28 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 01:27:29 2009 -0800 ARM11: remove old R0..R15/CPSR code This finishes the basic switchover to the new register code, for everything except the debug registers. (And maybe we shouldn't have a cache for *those* which works this way...) The context save/restore code now uses the new code, but it's in a slightly different sequence. That should be fine since the R0/PC/CPSR stuff is all that really matters (and if we can update those, we can update the rest). Now there's no longer a way any code can be confused about which copy of "r1" (etc) to use. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index 3bdb444..a5175af 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -48,26 +48,6 @@ static bool arm11_config_hardware_step = false; enum arm11_regtype { - ARM11_REGISTER_CORE, - ARM11_REGISTER_CPSR, - - ARM11_REGISTER_FX, - ARM11_REGISTER_FPS, - - ARM11_REGISTER_FIQ, - ARM11_REGISTER_SVC, - ARM11_REGISTER_ABT, - ARM11_REGISTER_IRQ, - ARM11_REGISTER_UND, - ARM11_REGISTER_MON, - - ARM11_REGISTER_SPSR_FIQ, - ARM11_REGISTER_SPSR_SVC, - ARM11_REGISTER_SPSR_ABT, - ARM11_REGISTER_SPSR_IRQ, - ARM11_REGISTER_SPSR_UND, - ARM11_REGISTER_SPSR_MON, - /* debug regs */ ARM11_REGISTER_DSCR, ARM11_REGISTER_WDTR, @@ -86,25 +66,6 @@ struct arm11_reg_defs /* update arm11_regcache_ids when changing this */ static const struct arm11_reg_defs arm11_reg_defs[] = { - {"r0", 0, 0, ARM11_REGISTER_CORE}, - {"r1", 1, 1, ARM11_REGISTER_CORE}, - {"r2", 2, 2, ARM11_REGISTER_CORE}, - {"r3", 3, 3, ARM11_REGISTER_CORE}, - {"r4", 4, 4, ARM11_REGISTER_CORE}, - {"r5", 5, 5, ARM11_REGISTER_CORE}, - {"r6", 6, 6, ARM11_REGISTER_CORE}, - {"r7", 7, 7, ARM11_REGISTER_CORE}, - {"r8", 8, 8, ARM11_REGISTER_CORE}, - {"r9", 9, 9, ARM11_REGISTER_CORE}, - {"r10", 10, 10, ARM11_REGISTER_CORE}, - {"r11", 11, 11, ARM11_REGISTER_CORE}, - {"r12", 12, 12, ARM11_REGISTER_CORE}, - {"sp", 13, 13, ARM11_REGISTER_CORE}, - {"lr", 14, 14, ARM11_REGISTER_CORE}, - {"pc", 15, 15, ARM11_REGISTER_CORE}, - - {"cpsr", 0, 25, ARM11_REGISTER_CPSR}, - /* Debug Registers */ {"dscr", 0, -1, ARM11_REGISTER_DSCR}, {"wdtr", 0, -1, ARM11_REGISTER_WDTR}, @@ -113,30 +74,6 @@ static const struct arm11_reg_defs arm11_reg_defs[] = enum arm11_regcache_ids { - ARM11_RC_R0, - ARM11_RC_RX = ARM11_RC_R0, - - ARM11_RC_R1, - ARM11_RC_R2, - ARM11_RC_R3, - ARM11_RC_R4, - ARM11_RC_R5, - ARM11_RC_R6, - ARM11_RC_R7, - ARM11_RC_R8, - ARM11_RC_R9, - ARM11_RC_R10, - ARM11_RC_R11, - ARM11_RC_R12, - ARM11_RC_R13, - ARM11_RC_SP = ARM11_RC_R13, - ARM11_RC_R14, - ARM11_RC_LR = ARM11_RC_R14, - ARM11_RC_R15, - ARM11_RC_PC = ARM11_RC_R15, - - ARM11_RC_CPSR, - ARM11_RC_DSCR, ARM11_RC_WDTR, ARM11_RC_RDTR, @@ -229,6 +166,8 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) arm11->reg_list[i].dirty = 0; } + /* See e.g. ARM1136 TRM, "14.8.4 Entering Debug state" */ + /* Save DSCR */ CHECK_RETVAL(arm11_read_DSCR(arm11, &R(DSCR))); @@ -254,10 +193,12 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) } - /* DSCR: set ARM11_DSCR_EXECUTE_ARM_INSTRUCTION_ENABLE */ - /* ARM1176 spec says this is needed only for wDTR/rDTR's "ITR mode", but not to issue ITRs - ARM1136 seems to require this to issue ITR's as well */ - + /* DSCR: set ARM11_DSCR_EXECUTE_ARM_INSTRUCTION_ENABLE + * + * ARM1176 spec says this is needed only for wDTR/rDTR's "ITR mode", + * but not to issue ITRs. ARM1136 seems to require this to issue + * ITR's as well... + */ uint32_t new_dscr = R(DSCR) | ARM11_DSCR_EXECUTE_ARM_INSTRUCTION_ENABLE; /* this executes JTAG queue: */ @@ -297,6 +238,11 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) } #endif + /* Save registers. + * + * NOTE: ARM1136 TRM suggests saving just R0 here now, then + * CPSR and PC after the rDTR stuff. We do it all at once. + */ retval = arm_dpm_read_current_registers(&arm11->dpm); if (retval != ERROR_OK) LOG_ERROR("DPM REG READ -- fail %d", retval); @@ -305,19 +251,7 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) if (retval != ERROR_OK) return retval; - /* save r0 - r14 */ - - /** \todo TODO: handle other mode registers */ - - for (size_t i = 0; i < 15; i++) - { - /* MCR p14,0,R?,c0,c5,0 */ - retval = arm11_run_instr_data_from_core(arm11, 0xEE000E15 | (i << 12), &R(RX + i), 1); - if (retval != ERROR_OK) - return retval; - } - - /* save rDTR */ + /* maybe save rDTR */ /* check rDTRfull in DSCR */ @@ -333,34 +267,9 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) arm11->reg_list[ARM11_RC_RDTR].valid = 0; } - /* save CPSR */ - - /* MRS r0,CPSR (move CPSR -> r0 (-> wDTR -> local var)) */ - retval = arm11_run_instr_data_from_core_via_r0(arm11, 0xE10F0000, &R(CPSR)); - if (retval != ERROR_OK) - return retval; - - /* save PC */ - - /* MOV R0,PC (move PC -> r0 (-> wDTR -> local var)) */ - retval = arm11_run_instr_data_from_core_via_r0(arm11, 0xE1A0000F, &R(PC)); - if (retval != ERROR_OK) - return retval; - - /* adjust PC depending on ARM state */ - - if (R(CPSR) & ARM11_CPSR_J) /* Java state */ - { - arm11->reg_values[ARM11_RC_PC] -= 0; - } - else if (R(CPSR) & ARM11_CPSR_T) /* Thumb state */ - { - arm11->reg_values[ARM11_RC_PC] -= 4; - } - else /* ARM state */ - { - arm11->reg_values[ARM11_RC_PC] -= 8; - } + /* REVISIT Now that we've saved core state, there's may also + * be MMU and cache state to care about ... + */ if (arm11->simulate_reset_on_next_halt) { @@ -393,29 +302,16 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) { int retval; - retval = arm11_run_instr_data_prepare(arm11); - if (retval != ERROR_OK) - return retval; - - /** \todo TODO: handle other mode registers */ - - /* restore R1 - R14 */ - - for (unsigned i = 1; i < 15; i++) - { - if (!arm11->reg_list[ARM11_RC_RX + i].dirty) - continue; - - /* MRC p14,0,r?,c0,c5,0 */ - arm11_run_instr_data_to_core1(arm11, - 0xee100e15 | (i << 12), R(RX + i)); + /* See e.g. ARM1136 TRM, "14.8.5 Leaving Debug state" */ - // LOG_DEBUG("RESTORE R%u %08x", i, R(RX + i)); - } + /* NOTE: the ARM1136 TRM suggests restoring all registers + * except R0/PC/CPSR right now. Instead, we do them all + * at once, just a bit later on. + */ - retval = arm11_run_instr_data_finish(arm11); - if (retval != ERROR_OK) - return retval; + /* REVISIT once we start caring about MMU and cache state, + * address it here ... + */ /* spec says clear wDTR and rDTR; we assume they are clear as otherwise our programming would be sloppy */ @@ -438,50 +334,27 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) } } -/* DEBUG for now, trust "new" code only for shadowed registers */ -retval = arm_dpm_write_dirty_registers(&arm11->dpm); - - retval = arm11_run_instr_data_prepare(arm11); - if (retval != ERROR_OK) - return retval; - - /* restore original wDTR */ - + /* maybe restore original wDTR */ if ((R(DSCR) & ARM11_DSCR_WDTR_FULL) || arm11->reg_list[ARM11_RC_WDTR].dirty) { + retval = arm11_run_instr_data_prepare(arm11); + if (retval != ERROR_OK) + return retval; + /* MCR p14,0,R0,c0,c5,0 */ retval = arm11_run_instr_data_to_core_via_r0(arm11, 0xee000e15, R(WDTR)); if (retval != ERROR_OK) return retval; - } - - /* restore CPSR */ - - /* MSR CPSR,R0*/ - retval = arm11_run_instr_data_to_core_via_r0(arm11, 0xe129f000, R(CPSR)); - if (retval != ERROR_OK) - return retval; - - - /* restore PC */ - - /* MOV PC,R0 */ - retval = arm11_run_instr_data_to_core_via_r0(arm11, 0xe1a0f000, R(PC)); - if (retval != ERROR_OK) - return retval; + retval = arm11_run_instr_data_finish(arm11); + if (retval != ERROR_OK) + return retval; + } - /* restore R0 */ - - /* MRC p14,0,r0,c0,c5,0 */ - arm11_run_instr_data_to_core1(arm11, 0xee100e15, R(R0)); - - retval = arm11_run_instr_data_finish(arm11); - if (retval != ERROR_OK) - return retval; - -/* DEBUG use this when "new" code is really managing core registers */ -// retval = arm_dpm_write_dirty_registers(&arm11->dpm); + /* restore CPSR, PC, and R0 ... after flushing any modified + * registers. + */ + retval = arm_dpm_write_dirty_registers(&arm11->dpm); register_cache_invalidate(arm11->arm.core_cache); @@ -489,7 +362,7 @@ retval = arm_dpm_write_dirty_registers(&arm11->dpm); arm11_write_DSCR(arm11, R(DSCR)); - /* restore rDTR */ + /* maybe restore rDTR */ if (R(DSCR) & ARM11_DSCR_RDTR_FULL || arm11->reg_list[ARM11_RC_RDTR].dirty) { @@ -509,6 +382,8 @@ retval = arm_dpm_write_dirty_registers(&arm11->dpm); arm11_add_dr_scan_vc(ARRAY_SIZE(chain5_fields), chain5_fields, TAP_DRPAUSE); } + /* now processor is ready to RESTART */ + return ERROR_OK; } @@ -639,6 +514,19 @@ static int arm11_halt(struct target *target) return ERROR_OK; } +static uint32_t +arm11_nextpc(struct arm11_common *arm11, int current, uint32_t address) +{ + void *value = arm11->arm.core_cache->reg_list[15].value; + + if (!current) + buf_set_u32(value, 0, 32, address); + else + address = buf_get_u32(value, 0, 32); + + return address; +} + static int arm11_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) { @@ -657,10 +545,9 @@ static int arm11_resume(struct target *target, int current, return ERROR_TARGET_NOT_HALTED; } - if (!current) - R(PC) = address; + address = arm11_nextpc(arm11, current, address); - LOG_DEBUG("RESUME PC %08" PRIx32 "%s", R(PC), !current ? "!" : ""); + LOG_DEBUG("RESUME PC %08" PRIx32 "%s", address, !current ? "!" : ""); /* clear breakpoints/watchpoints and VCR*/ arm11_sc7_clear_vbw(arm11); @@ -677,7 +564,7 @@ static int arm11_resume(struct target *target, int current, for (bp = target->breakpoints; bp; bp = bp->next) { - if (bp->address == R(PC)) + if (bp->address == address) { LOG_DEBUG("must step over %08" PRIx32 "", bp->address); arm11_step(target, 1, 0, 0); @@ -778,33 +665,28 @@ static int arm11_step(struct target *target, int current, struct arm11_common *arm11 = target_to_arm11(target); - if (!current) - R(PC) = address; + address = arm11_nextpc(arm11, current, address); - LOG_DEBUG("STEP PC %08" PRIx32 "%s", R(PC), !current ? "!" : ""); + LOG_DEBUG("STEP PC %08" PRIx32 "%s", address, !current ? "!" : ""); /** \todo TODO: Thumb not supported here */ uint32_t next_instruction; - CHECK_RETVAL(arm11_read_memory_word(arm11, R(PC), &next_instruction)); + CHECK_RETVAL(arm11_read_memory_word(arm11, address, &next_instruction)); /* skip over BKPT */ if ((next_instruction & 0xFFF00070) == 0xe1200070) { - R(PC) += 4; - arm11->reg_list[ARM11_RC_PC].valid = 1; - arm11->reg_list[ARM11_RC_PC].dirty = 0; + address = arm11_nextpc(arm11, 0, address + 4); LOG_DEBUG("Skipping BKPT"); } /* skip over Wait for interrupt / Standby */ /* mcr 15, 0, r?, cr7, cr0, {4} */ else if ((next_instruction & 0xFFFF0FFF) == 0xee070f90) { - R(PC) += 4; - arm11->reg_list[ARM11_RC_PC].valid = 1; - arm11->reg_list[ARM11_RC_PC].dirty = 0; + address = arm11_nextpc(arm11, 0, address + 4); LOG_DEBUG("Skipping WFI"); } /* ignore B to self */ @@ -844,7 +726,7 @@ static int arm11_step(struct target *target, int current, * FIXME Thumb stepping likely needs to use 0x03 * or 0xc0 byte masks, not 0x0f. */ - brp[0].value = R(PC); + brp[0].value = address; brp[1].value = 0x1 | (3 << 1) | (0x0F << 5) | (0 << 14) | (0 << 16) | (0 << 20) | (2 << 21); @@ -1045,8 +927,7 @@ static int arm11_read_memory_inner(struct target *target, switch (size) { case 1: - /** \todo TODO: check if dirty is the right choice to force a rewrite on arm11_resume() */ - arm11->reg_list[ARM11_RC_R1].dirty = 1; + arm11->arm.core_cache->reg_list[1].dirty = true; for (size_t i = 0; i < count; i++) { @@ -1066,7 +947,7 @@ static int arm11_read_memory_inner(struct target *target, case 2: { - arm11->reg_list[ARM11_RC_R1].dirty = 1; + arm11->arm.core_cache->reg_list[1].dirty = true; for (size_t i = 0; i < count; i++) { @@ -1150,7 +1031,7 @@ static int arm11_write_memory_inner(struct target *target, { case 1: { - arm11->reg_list[ARM11_RC_R1].dirty = 1; + arm11->arm.core_cache->reg_list[1].dirty = true; for (size_t i = 0; i < count; i++) { @@ -1172,7 +1053,7 @@ static int arm11_write_memory_inner(struct target *target, case 2: { - arm11->reg_list[ARM11_RC_R1].dirty = 1; + arm11->arm.core_cache->reg_list[1].dirty = true; for (size_t i = 0; i < count; i++) { @@ -1363,9 +1244,9 @@ static int arm11_init_target(struct command_context *cmd_ctx, { /* Initialize anything we can set up without talking to the target */ - /* FIXME Switch to use the standard build_reg_cache() not custom - * code. Do it from examine(), after we check whether we're - * an arm1176 and thus support the Secure Monitor mode. + /* REVISIT do we really want such a debug-registers-only cache? + * If we do, it should probably be handled purely by the DPM code, + * so it works identically on the v7a/v7r cores. */ return arm11_build_reg_cache(target); } @@ -1535,9 +1416,8 @@ static int arm11_build_reg_cache(struct target *target) arm11->reg_list = reg_list; - /* Build the process context cache */ - cache->name = "arm11 registers"; - cache->next = NULL; + /* build cache for some of the debug registers */ + cache->name = "arm11 debug registers"; cache->reg_list = reg_list; cache->num_regs = ARM11_REGCACHE_COUNT; @@ -1545,7 +1425,6 @@ static int arm11_build_reg_cache(struct target *target) (*cache_p) = cache; arm11->core_cache = cache; -// armv7m->process_context = cache; size_t i; diff --git a/src/target/arm11.h b/src/target/arm11.h index 033ba89..c3f4e86 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -26,8 +26,7 @@ #include "armv4_5.h" #include "arm_dpm.h" -/* TEMPORARY -- till we switch to the shared infrastructure */ -#define ARM11_REGCACHE_COUNT 20 +#define ARM11_REGCACHE_COUNT 3 #define ARM11_TAP_DEFAULT TAP_INVALID @@ -70,7 +69,7 @@ struct arm11_common bool simulate_reset_on_next_halt; /**< Perform cleanups of the ARM state on next halt */ - /** \name Shadow registers to save processor state */ + /** \name Shadow registers to save debug state */ /*@{*/ struct reg * reg_list; /**< target register list */ commit ec64acf536942168b4e038c6720c83687d3a0d08 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 01:27:24 2009 -0800 ARM11: use standard run_algorithm() As with single stepping, the previous stuff was needed because the ARM11 code wasn't using the standard ARM base type and register access ... but now those mechanisms work, so we can switch out that special-purpose glue, in favor of the more thoroughly tested/capable "standard" code. Fixes a bug in the resume() implementation: it wasn't handling two of its arguments correctly, preventing the "flash erase_check" algorithm from working. (This code needs a *subsequent* update for correct register handling, though... removing the confusion about which "r2", for example, to use.) This should resolve some "FIXME" comments too, for Thumb and processor mode support. It also gets rid of a nasty exit() call; servers should only have *clean* shutdown paths. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index d021cbd..3bdb444 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -665,8 +665,11 @@ static int arm11_resume(struct target *target, int current, /* clear breakpoints/watchpoints and VCR*/ arm11_sc7_clear_vbw(arm11); - /* Set up breakpoints */ if (!debug_execution) + target_free_all_working_areas(target); + + /* Set up breakpoints */ + if (handle_breakpoints) { /* check if one matches PC and step over it if necessary */ @@ -1325,176 +1328,6 @@ static int arm11_remove_watchpoint(struct target *target, return ERROR_FAIL; } -// HACKHACKHACK - FIXME mode/state -/* target algorithm support */ -static int arm11_run_algorithm(struct target *target, - int num_mem_params, struct mem_param *mem_params, - int num_reg_params, struct reg_param *reg_params, - uint32_t entry_point, uint32_t exit_point, - int timeout_ms, void *arch_info) -{ - struct arm11_common *arm11 = target_to_arm11(target); -// enum armv4_5_state core_state = arm11->core_state; -// enum armv4_5_mode core_mode = arm11->core_mode; - uint32_t context[16]; - uint32_t cpsr; - int exit_breakpoint_size = 0; - int retval = ERROR_OK; - LOG_DEBUG("Running algorithm"); - - - if (target->state != TARGET_HALTED) - { - LOG_WARNING("target not halted"); - return ERROR_TARGET_NOT_HALTED; - } - - // FIXME -// if (!is_arm_mode(arm11->core_mode)) -// return ERROR_FAIL; - - // Save regs - for (unsigned i = 0; i < 16; i++) - { - context[i] = buf_get_u32((uint8_t*)(&arm11->reg_values[i]),0,32); - LOG_DEBUG("Save %u: 0x%" PRIx32 "", i, context[i]); - } - - cpsr = buf_get_u32((uint8_t*)(arm11->reg_values + ARM11_RC_CPSR),0,32); - LOG_DEBUG("Save CPSR: 0x%" PRIx32 "", cpsr); - - for (int i = 0; i < num_mem_params; i++) - { - target_write_buffer(target, mem_params[i].address, mem_params[i].size, mem_params[i].value); - } - - // Set register parameters - for (int i = 0; i < num_reg_params; i++) - { - struct reg *reg = register_get_by_name(arm11->core_cache, reg_params[i].reg_name, 0); - if (!reg) - { - LOG_ERROR("BUG: register '%s' not found", reg_params[i].reg_name); - return ERROR_INVALID_ARGUMENTS; - } - - if (reg->size != reg_params[i].size) - { - LOG_ERROR("BUG: register '%s' size doesn't match reg_params[i].size", reg_params[i].reg_name); - return ERROR_INVALID_ARGUMENTS; - } - arm11_set_reg(reg,reg_params[i].value); -// printf("%i: Set %s =%08x\n", i, reg_params[i].reg_name,val); - } - - exit_breakpoint_size = 4; - -/* arm11->core_state = arm11_algorithm_info->core_state; - if (arm11->core_state == ARMV4_5_STATE_ARM) - exit_breakpoint_size = 4; - else if (arm11->core_state == ARMV4_5_STATE_THUMB) - exit_breakpoint_size = 2; - else - { - LOG_ERROR("BUG: can't execute algorithms when not in ARM or Thumb state"); - exit(-1); - } -*/ - - -/* arm11 at this point only supports ARM not THUMB mode - however if this test needs to be reactivated the current state can be read back - from CPSR */ -#if 0 - if (arm11_algorithm_info->core_mode != ARMV4_5_MODE_ANY) - { - LOG_DEBUG("setting core_mode: 0x%2.2x", arm11_algorithm_info->core_mode); - buf_set_u32(arm11->reg_list[ARM11_RC_CPSR].value, 0, 5, arm11_algorithm_info->core_mode); - arm11->reg_list[ARM11_RC_CPSR].dirty = 1; - arm11->reg_list[ARM11_RC_CPSR].valid = 1; - } -#endif - - if ((retval = breakpoint_add(target, exit_point, exit_breakpoint_size, BKPT_HARD)) != ERROR_OK) - { - LOG_ERROR("can't add breakpoint to finish algorithm execution"); - retval = ERROR_TARGET_FAILURE; - goto restore; - } - - // no debug, otherwise breakpoint is not set - CHECK_RETVAL(target_resume(target, 0, entry_point, 1, 0)); - - CHECK_RETVAL(target_wait_state(target, TARGET_HALTED, timeout_ms)); - - if (target->state != TARGET_HALTED) - { - CHECK_RETVAL(target_halt(target)); - - CHECK_RETVAL(target_wait_state(target, TARGET_HALTED, 500)); - - retval = ERROR_TARGET_TIMEOUT; - - goto del_breakpoint; - } - - if (buf_get_u32(arm11->reg_list[15].value, 0, 32) != exit_point) - { - LOG_WARNING("target reentered debug state, but not at the desired exit point: 0x%4.4" PRIx32 "", - buf_get_u32(arm11->reg_list[15].value, 0, 32)); - retval = ERROR_TARGET_TIMEOUT; - goto del_breakpoint; - } - - for (int i = 0; i < num_mem_params; i++) - { - if (mem_params[i].direction != PARAM_OUT) - target_read_buffer(target, mem_params[i].address, mem_params[i].size, mem_params[i].value); - } - - for (int i = 0; i < num_reg_params; i++) - { - if (reg_params[i].direction != PARAM_OUT) - { - struct reg *reg = register_get_by_name(arm11->core_cache, reg_params[i].reg_name, 0); - if (!reg) - { - LOG_ERROR("BUG: register '%s' not found", reg_params[i].reg_name); - retval = ERROR_INVALID_ARGUMENTS; - goto del_breakpoint; - } - - if (reg->size != reg_params[i].size) - { - LOG_ERROR("BUG: register '%s' size doesn't match reg_params[i].size", reg_params[i].reg_name); - retval = ERROR_INVALID_ARGUMENTS; - goto del_breakpoint; - } - - buf_set_u32(reg_params[i].value, 0, 32, buf_get_u32(reg->value, 0, 32)); - } - } - -del_breakpoint: - breakpoint_remove(target, exit_point); - -restore: - // Restore context - for (size_t i = 0; i < 16; i++) - { - LOG_DEBUG("restoring register %s with value 0x%8.8" PRIx32 "", - arm11->reg_list[i].name, context[i]); - arm11_set_reg(&arm11->reg_list[i], (uint8_t*)&context[i]); - } - LOG_DEBUG("restoring CPSR with value 0x%8.8" PRIx32 "", cpsr); - arm11_set_reg(&arm11->reg_list[ARM11_RC_CPSR], (uint8_t*)&cpsr); - -// arm11->core_state = core_state; -// arm11->core_mode = core_mode; - - return retval; -} - static int arm11_target_create(struct target *target, Jim_Interp *interp) { struct arm11_common *arm11; @@ -1925,7 +1758,7 @@ struct target_type arm11_target = { .add_watchpoint = arm11_add_watchpoint, .remove_watchpoint = arm11_remove_watchpoint, - .run_algorithm = arm11_run_algorithm, + .run_algorithm = armv4_5_run_algorithm, .register_commands = arm11_register_commands, .target_create = arm11_target_create, commit bf3abc48f008e0a0c0e42b943481872599463af6 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 01:27:21 2009 -0800 ARM11: use standard single step simulation The previous stuff was needed because the ARM11 code wasn't using the standard ARM base type and register access ... but now those mechanisms work, so we can switch out that special-purpose glue. This should resolve all the "FIXME -- handle Thumb single stepping" comments too, and properly handle the processor's mode. (Modulo the issue that this code doesn't yet handle two-byte breakpoints.) Clarify the comments about the the hardware single stepping. When we eventually share breakpoint code with Cortex-A8, we can just make that be the default on cores which support it. We may still want an override command, not just to facilitate testing but to cope with "instruction address mismatch" not quite being true single-step. Signed-off-by: David Brownell <dbr...@us...> diff --git a/TODO b/TODO index bdbb0ec..da5cf52 100644 --- a/TODO +++ b/TODO @@ -167,8 +167,7 @@ https://lists.berlios.de/pipermail/openocd-development/2009-October/011506.html mdw 0xb80005f0 0x8, mdh 0xb80005f0 0x10, mdb 0xb80005f0 0x20. mdb returns garabage. - implement missing functionality (grep FNC_INFO_NOTIMPLEMENTED ...) - - thumb support is missing: ISTR ARMv6 requires Thumb. - ARM1156 has Thumb2; ARM1136 doesn't. +- Thumb2 single stepping: ARM1156T2 needs simulator support - Cortex A8 support (ML) - add target implementation (ML) - Generic ARM run_algorithm() interface diff --git a/src/target/arm11.c b/src/target/arm11.c index 4e6326d..d021cbd 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -761,96 +761,6 @@ static int arm11_resume(struct target *target, int current, return ERROR_OK; } - -static int armv4_5_to_arm11(int reg) -{ - if (reg < 16) - return reg; - switch (reg) - { - case ARMV4_5_CPSR: - return ARM11_RC_CPSR; - case 16: - /* FIX!!! handle thumb better! */ - return ARM11_RC_CPSR; - default: - LOG_ERROR("BUG: register translation from armv4_5 to arm11 not supported %d", reg); - exit(-1); - } -} - - -static uint32_t arm11_sim_get_reg(struct arm_sim_interface *sim, int reg) -{ - struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - reg=armv4_5_to_arm11(reg); - - return buf_get_u32(arm11->reg_list[reg].value, 0, 32); -} - -static void arm11_sim_set_reg(struct arm_sim_interface *sim, - int reg, uint32_t value) -{ - struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - reg=armv4_5_to_arm11(reg); - - buf_set_u32(arm11->reg_list[reg].value, 0, 32, value); -} - -static uint32_t arm11_sim_get_cpsr(struct arm_sim_interface *sim, - int pos, int bits) -{ - struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - return buf_get_u32(arm11->reg_list[ARM11_RC_CPSR].value, pos, bits); -} - -static enum armv4_5_state arm11_sim_get_state(struct arm_sim_interface *sim) -{ -// struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - /* FIX!!!! we should implement thumb for arm11 */ - return ARMV4_5_STATE_ARM; -} - -static void arm11_sim_set_state(struct arm_sim_interface *sim, - enum armv4_5_state mode) -{ -// struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - /* FIX!!!! we should implement thumb for arm11 */ - LOG_ERROR("Not implemented: %s", __func__); -} - - -static enum armv4_5_mode arm11_sim_get_mode(struct arm_sim_interface *sim) -{ - //struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; - - /* FIX!!!! we should implement something that returns the current mode here!!! */ - return ARMV4_5_MODE_USR; -} - -static int arm11_simulate_step(struct target *target, uint32_t *dry_run_pc) -{ - struct arm_sim_interface sim; - - sim.user_data=target->arch_info; - sim.get_reg=&arm11_sim_get_reg; - sim.set_reg=&arm11_sim_set_reg; - sim.get_reg_mode=&arm11_sim_get_reg; - sim.set_reg_mode=&arm11_sim_set_reg; - sim.get_cpsr=&arm11_sim_get_cpsr; - sim.get_mode=&arm11_sim_get_mode; - sim.get_state=&arm11_sim_get_state; - sim.set_state=&arm11_sim_set_state; - - return arm_simulate_step_core(target, dry_run_pc, &sim); - -} - static int arm11_step(struct target *target, int current, uint32_t address, int handle_breakpoints) { @@ -919,24 +829,41 @@ static int arm11_step(struct target *target, int current, if (arm11_config_hardware_step) { - /* hardware single stepping be used if possible or is it better to - * always use the same code path? Hardware single stepping is not supported - * on all hardware + /* Hardware single stepping ("instruction address + * mismatch") is used if enabled. It's not quite + * exactly "run one instruction"; "branch to here" + * loops won't break, neither will some other cases, + * but it's probably the best default. + * + * Hardware single stepping isn't supported on v6 + * debug modules. ARM1176 and v7 can support it... + * + * FIXME Thumb stepping likely needs to use 0x03 + * or 0xc0 byte masks, not 0x0f. */ brp[0].value = R(PC); - brp[1].value = 0x1 | (3 << 1) | (0x0F << 5) | (0 << 14) | (0 << 16) | (0 << 20) | (2 << 21); + brp[1].value = 0x1 | (3 << 1) | (0x0F << 5) + | (0 << 14) | (0 << 16) | (0 << 20) + | (2 << 21); } else { - /* sets a breakpoint on the next PC(calculated by simulation), + /* Sets a breakpoint on the next PC, as calculated + * by instruction set simulation. + * + * REVISIT stepping Thumb on ARM1156 requires Thumb2 + * support from the simulator. */ uint32_t next_pc; int retval; - retval = arm11_simulate_step(target, &next_pc); + + retval = arm_simulate_step(target, &next_pc); if (retval != ERROR_OK) return retval; brp[0].value = next_pc; - brp[1].value = 0x1 | (3 << 1) | (0x0F << 5) | (0 << 14) | (0 << 16) | (0 << 20) | (0 << 21); + brp[1].value = 0x1 | (3 << 1) | (0x0F << 5) + | (0 << 14) | (0 << 16) | (0 << 20) + | (0 << 21); } CHECK_RETVAL(arm11_sc7_run(arm11, brp, ARRAY_SIZE(brp))); @@ -1826,6 +1753,13 @@ static int arm11_build_reg_cache(struct target *target) return ERROR_OK; } +/* FIXME all these BOOL_WRAPPER things should be modifying + * per-instance state, not shared state; ditto the vector + * catch register support. Scan chains with multiple cores + * should be able to say "work with this core like this, + * that core like that". Example, ARM11 MPCore ... + */ + #define ARM11_BOOL_WRAPPER(name, print_name) \ COMMAND_HANDLER(arm11_handle_bool_##name) \ { \ commit 5eb893ec41c8c6cf6499558b6fed826b65e18a16 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 01:27:16 2009 -0800 ARM11: partial support for standard ARM register interfaces. This provides "standard" ARM register support -- with twenty or more shadow registers on top of what this code now handles, but properly associated with the various core modes -- parallel to the current register code. That is, the current code is stilil managing the "current" registers; the new code shadows them. You can see all the registers with "arm reg", modify the shadows like "r8_fiq" or "sp_abt" with "reg", and see them get properly written back when you step. (Just don't do that with any of the registers managed by the "old" code ...) It also switches to using more standard code, relying on those standard registers, in two places: (a) the poll status display, which now shows core state (ARM/Thumb/...) and mode (Supervisor, IRQ, etc); and (b) GDB register access. So it's not a full migration, there are warts -- every place that touches the old register cache is a potential bug -- but it's a small more-or-less-comprehensible step that's even somewhat useful. Later patches complete the migration. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index 3c841bb..4e6326d 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -144,9 +144,6 @@ enum arm11_regcache_ids ARM11_RC_MAX, }; -/* GDB expects ARMs to give R0..R15, CPSR, and 7 FPA dummies */ -#define ARM11_GDB_REGISTER_COUNT 26 - static int arm11_on_enter_debug_state(struct arm11_common *arm11); static int arm11_step(struct target *target, int current, uint32_t address, int handle_breakpoints); @@ -223,6 +220,9 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) { int retval; + /* REVISIT entire cache should already be invalid !!! */ + register_cache_invalidate(arm11->arm.core_cache); + for (size_t i = 0; i < ARRAY_SIZE(arm11->reg_values); i++) { arm11->reg_list[i].valid = 1; @@ -297,6 +297,10 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) } #endif + retval = arm_dpm_read_current_registers(&arm11->dpm); + if (retval != ERROR_OK) + LOG_ERROR("DPM REG READ -- fail %d", retval); + retval = arm11_run_instr_data_prepare(arm11); if (retval != ERROR_OK) return retval; @@ -434,6 +438,9 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) } } +/* DEBUG for now, trust "new" code only for shadowed registers */ +retval = arm_dpm_write_dirty_registers(&arm11->dpm); + retval = arm11_run_instr_data_prepare(arm11); if (retval != ERROR_OK) return retval; @@ -473,6 +480,11 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) if (retval != ERROR_OK) return retval; +/* DEBUG use this when "new" code is really managing core registers */ +// retval = arm_dpm_write_dirty_registers(&arm11->dpm); + + register_cache_invalidate(arm11->arm.core_cache); + /* restore DSCR */ arm11_write_DSCR(arm11, R(DSCR)); @@ -545,14 +557,13 @@ static int arm11_poll(struct target *target) /* architecture specific status reply */ static int arm11_arch_state(struct target *target) { - struct arm11_common *arm11 = target_to_arm11(target); + int retval; - LOG_USER("target halted due to %s\ncpsr: 0x%8.8" PRIx32 " pc: 0x%8.8" PRIx32 "", - Jim_Nvp_value2name_simple(nvp_target_debug_reason, target->debug_reason)->name, - R(CPSR), - R(PC)); + retval = armv4_5_arch_state(target); - return ERROR_OK; + /* REVISIT also display ARM11-specific MMU and cache status ... */ + + return retval; } /* target request support */ @@ -1067,31 +1078,6 @@ static int arm11_soft_reset_halt(struct target *target) return ERROR_FAIL; } -/* target register access for gdb */ -static int arm11_get_gdb_reg_list(struct target *target, - struct reg **reg_list[], int *reg_list_size) -{ - struct arm11_common *arm11 = target_to_arm11(target); - - *reg_list_size = ARM11_GDB_REGISTER_COUNT; - *reg_list = malloc(sizeof(struct reg*) * ARM11_GDB_REGISTER_COUNT); - - /* nine unused legacy FPA registers are expected by GDB */ - for (size_t i = 16; i < 24; i++) - (*reg_list)[i] = &arm_gdb_dummy_fp_reg; - (*reg_list)[24] = &arm_gdb_dummy_fps_reg; - - for (size_t i = 0; i < ARM11_REGCACHE_COUNT; i++) - { - if (arm11_reg_defs[i].gdb_num == -1) - continue; - - (*reg_list)[arm11_reg_defs[i].gdb_num] = arm11->reg_list + i; - } - - return ERROR_OK; -} - /* target memory access * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit) * count: number of items of <size> @@ -1633,6 +1619,8 @@ static int arm11_examine(struct target *target) uint32_t didr, device_id; uint8_t implementor; + /* FIXME split into do-first-time and do-every-time logic ... */ + /* check IDCODE */ arm11_add_IR(arm11, ARM11_IDCODE, ARM11_TAP_DEFAULT); @@ -1705,6 +1693,14 @@ static int arm11_examine(struct target *target) if (retval != ERROR_OK) return retval; + /* Build register cache "late", after target_init(), since we + * want to know if this core supports Secure Monitor mode. + */ + if (!target_was_examined(target)) { + arm11_dpm_init(arm11, didr); + retval = arm_dpm_setup(&arm11->dpm); + } + /* ETM on ARM11 still uses original scanchain 6 access mode */ if (arm11->arm.etm && !target_was_examined(target)) { *register_get_last_cache_p(&target->reg_cache) = @@ -1980,7 +1976,7 @@ struct target_type arm11_target = { .deassert_reset = arm11_deassert_reset, .soft_reset_halt = arm11_soft_reset_halt, - .get_gdb_reg_list = arm11_get_gdb_reg_list, + .get_gdb_reg_list = armv4_5_get_gdb_reg_list, .read_memory = arm11_read_memory, .write_memory = arm11_write_memory, ----------------------------------------------------------------------- Summary of changes: TODO | 3 +- src/target/arm11.c | 622 +++++++++++----------------------------------------- src/target/arm11.h | 5 +- 3 files changed, 135 insertions(+), 495 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: David B. <dbr...@us...> - 2009-11-24 09:15:20
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 6ff33a4ee8db483e29bc78b8c35e50342ca60850 (commit) via caf827ee8122de66721e62b933b7133df2349c4f (commit) via e6dc927e972bb2d91131b0193b676c531377f318 (commit) via ad75af0b17af75d57b95298fb40784d33cc8f3e2 (commit) from 0583cb0a0d222787c4048f9362292c5db9d969b0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6ff33a4ee8db483e29bc78b8c35e50342ca60850 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 00:14:15 2009 -0800 ARM11: remove register "history" debug stuff This was a private mechanism to snapshot registers before leaving debug state, and then on reentry to optionally display what changed. It was coupled to the private register cache, which won't be sticking around in that form for much longer. Remove (instead of teaching it how to handle *all* the registers). (The idea is interesting, but we ought to be able to implement this in a generic way. Ideally through Tcl scripts that can automatically be invoked following debug entry...) Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index cb1af7b..3c841bb 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -155,9 +155,6 @@ static int arm11_build_reg_cache(struct target *target); static int arm11_set_reg(struct reg *reg, uint8_t *buf); static int arm11_get_reg(struct reg *reg); -static void arm11_record_register_history(struct arm11_common * arm11); -static void arm11_dump_reg_changes(struct arm11_common * arm11); - /** Check and if necessary take control of the system * @@ -380,41 +377,9 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) if (retval != ERROR_OK) return retval; - arm11_dump_reg_changes(arm11); - return ERROR_OK; } -static void arm11_dump_reg_changes(struct arm11_common * arm11) -{ - - if (!(debug_level >= LOG_LVL_DEBUG)) - { - return; - } - - for (size_t i = 0; i < ARM11_REGCACHE_COUNT; i++) - { - if (!arm11->reg_list[i].valid) - { - if (arm11->reg_history[i].valid) - LOG_DEBUG("%8s INVALID (%08" PRIx32 ")", arm11_reg_defs[i].name, arm11->reg_history[i].value); - } - else - { - if (arm11->reg_history[i].valid) - { - if (arm11->reg_history[i].value != arm11->reg_values[i]) - LOG_DEBUG("%8s %08" PRIx32 " (%08" PRIx32 ")", arm11_reg_defs[i].name, arm11->reg_values[i], arm11->reg_history[i].value); - } - else - { - LOG_DEBUG("%8s %08" PRIx32 " (INVALID)", arm11_reg_defs[i].name, arm11->reg_values[i]); - } - } - } -} - /** Restore processor state * * This is called in preparation for the RESTART function. @@ -532,24 +497,9 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) arm11_add_dr_scan_vc(ARRAY_SIZE(chain5_fields), chain5_fields, TAP_DRPAUSE); } - arm11_record_register_history(arm11); - return ERROR_OK; } -static void arm11_record_register_history(struct arm11_common *arm11) -{ - for (size_t i = 0; i < ARM11_REGCACHE_COUNT; i++) - { - arm11->reg_history[i].value = arm11->reg_values[i]; - arm11->reg_history[i].valid = arm11->reg_list[i].valid; - - arm11->reg_list[i].valid = 0; - arm11->reg_list[i].dirty = 0; - } -} - - /* poll current target status */ static int arm11_poll(struct target *target) { diff --git a/src/target/arm11.h b/src/target/arm11.h index a67c337..033ba89 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -41,12 +41,6 @@ } \ } while (0) -struct arm11_register_history -{ - uint32_t value; - uint8_t valid; -}; - enum arm11_debug_version { ARM11_DEBUG_V6 = 0x01, @@ -84,9 +78,6 @@ struct arm11_common /*@}*/ - struct arm11_register_history - reg_history[ARM11_REGCACHE_COUNT]; /**< register state before last resume */ - size_t free_brps; /**< keep track of breakpoints allocated by arm11_add_breakpoint() */ size_t free_wrps; /**< keep track of breakpoints allocated by arm11_add_watchpoint() */ commit caf827ee8122de66721e62b933b7133df2349c4f Author: David Brownell <dbr...@us...> Date: Tue Nov 24 00:14:06 2009 -0800 ARM11: implement provider for new DPM interface This is a very thin layer over some of the current ARM11 debug TAP utilities. The layer isn't yet hooked up. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.h b/src/target/arm11.h index d40faa4..a67c337 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -24,6 +24,7 @@ #define ARM11_H #include "armv4_5.h" +#include "arm_dpm.h" /* TEMPORARY -- till we switch to the shared infrastructure */ #define ARM11_REGCACHE_COUNT 20 @@ -59,6 +60,9 @@ struct arm11_common struct arm arm; struct target * target; /**< Reference back to the owner */ + /** Debug module state. */ + struct arm_dpm dpm; + /** \name Processor type detection */ /*@{*/ diff --git a/src/target/arm11_dbgtap.c b/src/target/arm11_dbgtap.c index c8d5902..b5b02ef 100644 --- a/src/target/arm11_dbgtap.c +++ b/src/target/arm11_dbgtap.c @@ -951,3 +951,76 @@ int arm11_read_memory_word(struct arm11_common * arm11, uint32_t address, uint32 return arm11_run_instr_data_finish(arm11); } + +/************************************************************************/ + +/* + * ARM11 provider for the OpenOCD implementation of the standard + * architectural ARM v6/v7 "Debug Programmer's Model" (DPM). + */ + +static inline struct arm11_common *dpm_to_arm11(struct arm_dpm *dpm) +{ + return container_of(dpm, struct arm11_common, dpm); +} + +static int arm11_dpm_prepare(struct arm_dpm *dpm) +{ + struct arm11_common *arm11 = dpm_to_arm11(dpm); + + arm11 = container_of(dpm->arm, struct arm11_common, arm); + + return arm11_run_instr_data_prepare(dpm_to_arm11(dpm)); +} + +static int arm11_dpm_finish(struct arm_dpm *dpm) +{ + return arm11_run_instr_data_finish(dpm_to_arm11(dpm)); +} + +static int arm11_dpm_instr_write_data_dcc(struct arm_dpm *dpm, + uint32_t opcode, uint32_t data) +{ + return arm11_run_instr_data_to_core(dpm_to_arm11(dpm), + opcode, &data, 1); +} + +static int arm11_dpm_instr_write_data_r0(struct arm_dpm *dpm, + uint32_t opcode, uint32_t data) +{ + return arm11_run_instr_data_to_core_via_r0(dpm_to_arm11(dpm), + opcode, data); +} + +static int arm11_dpm_instr_read_data_dcc(struct arm_dpm *dpm, + uint32_t opcode, uint32_t *data) +{ + return arm11_run_instr_data_from_core(dpm_to_arm11(dpm), + opcode, data, 1); +} + +static int arm11_dpm_instr_read_data_r0(struct arm_dpm *dpm, + uint32_t opcode, uint32_t *data) +{ + return arm11_run_instr_data_from_core_via_r0(dpm_to_arm11(dpm), + opcode, data); +} + + +void arm11_dpm_init(struct arm11_common *arm11, uint32_t didr) +{ + struct arm_dpm *dpm = &arm11->dpm; + + dpm->arm = &arm11->arm; + + dpm->didr = didr; + + dpm->prepare = arm11_dpm_prepare; + dpm->finish = arm11_dpm_finish; + + dpm->instr_write_data_dcc = arm11_dpm_instr_write_data_dcc; + dpm->instr_write_data_r0 = arm11_dpm_instr_write_data_r0; + + dpm->instr_read_data_dcc = arm11_dpm_instr_read_data_dcc; + dpm->instr_read_data_r0 = arm11_dpm_instr_read_data_r0; +} diff --git a/src/target/arm11_dbgtap.h b/src/target/arm11_dbgtap.h index b85a138..8b6a206 100644 --- a/src/target/arm11_dbgtap.h +++ b/src/target/arm11_dbgtap.h @@ -60,4 +60,7 @@ void arm11_sc7_set_vcr(struct arm11_common *arm11, uint32_t value); int arm11_read_memory_word(struct arm11_common *arm11, uint32_t address, uint32_t *result); +/* Set up high-level debug module utilities */ +void arm11_dpm_init(struct arm11_common *arm11, uint32_t didr); + #endif // ARM11_DBGTAP_H commit e6dc927e972bb2d91131b0193b676c531377f318 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 00:13:58 2009 -0800 ARM: new DPM interface First version of interface for sharing code between ARMv6 and ARMv7a debug modules ... now the architecture includes debug support. (Not the same as for the trimmed-down v7m or v6m though!) This is a first version of an interface that will let the ARM11 and Cortex-A8 support share code, features, and bugfixes. Based on existing code from both of those cores. The ARM v7-AR architecture specification calls this commonality the "Debug Programmer's Model (DPM)", which seemed to be an appropriate acronym -- a TLA even! -- for use in our code. Made it so. :) The initial scope of this just supports register access, and is geared towards supporting top level "struct arm" mechanisms. Later, things like breakpoint and watchpoint support should be included. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/Makefile.am b/src/target/Makefile.am index 23aea82..a367fd4 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -75,6 +75,7 @@ ARMV7_SRC = \ cortex_a8.c ARM_DEBUG_SRC = \ + arm_dpm.c \ arm_jtag.c \ arm_disassembler.c \ arm_simulator.c \ @@ -96,6 +97,7 @@ MIPS32_SRC = \ noinst_HEADERS = \ algorithm.h \ + arm_dpm.h \ arm_jtag.h \ arm_adi_v5.h \ arm_disassembler.h \ diff --git a/src/target/arm_dpm.c b/src/target/arm_dpm.c new file mode 100644 index 0000000..18a9dcc --- /dev/null +++ b/src/target/arm_dpm.c @@ -0,0 +1,529 @@ +/* + * Copyright (C) 2009 by David Brownell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "armv4_5.h" /* REVISIT to become arm.h */ +#include "arm_dpm.h" +#include "jtag.h" +#include "register.h" + + +/** + * @file + * Implements various ARM DPM operations using architectural debug registers. + * These routines layer over core-specific communication methods to cope with + * implementation differences between cores like ARM1136 and Cortex-A8. + */ + +/* Toggles between recorded core mode (USR, SVC, etc) and a temporary one. + * Routines *must* restore the original mode before returning!! + */ +static int dpm_modeswitch(struct arm_dpm *dpm, enum armv4_5_mode mode) +{ + int retval; + uint32_t cpsr; + + /* restore previous mode */ + if (mode == ARMV4_5_MODE_ANY) + cpsr = buf_get_u32(dpm->arm->cpsr->value, 0, 32); + + /* else force to the specified mode */ + else + cpsr = mode; + + retval = dpm->instr_write_data_r0(dpm, ARMV4_5_MSR_GP(0, 0xf, 0), cpsr); + + /* REVISIT on Cortex-A8, we need a Prefetch Flush operation too ... + cortex_a8_exec_opcode(target, + ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); + */ + + return retval; +} + +/* just read the register -- rely on the core mode being right */ +static int dpm_read_reg(struct arm_dpm *dpm, struct reg *r, unsigned regnum) +{ + uint32_t value; + int retval; + + switch (regnum) { + case 0 ... 14: + /* return via DCC: "MCR p14, 0, Rnum, c0, c5, 0" */ + retval = dpm->instr_read_data_dcc(dpm, + ARMV4_5_MCR(14, 0, regnum, 0, 5, 0), + &value); + break; + case 15: /* PC */ + /* "MOV r0, pc"; then return via DCC */ + retval = dpm->instr_read_data_r0(dpm, 0xe1a0000f, &value); + + /* NOTE: this seems like a slightly awkward place to update + * this value ... but if the PC gets written (the only way + * to change what we compute), the arch spec says subsequent + * reads return values which are "unpredictable". So this + * is always right except in those broken-by-intent cases. + */ + switch (dpm->arm->core_state) { + case ARMV4_5_STATE_ARM: + value -= 8; + break; + case ARMV4_5_STATE_THUMB: + case ARM_STATE_THUMB_EE: + value -= 4; + break; + case ARMV4_5_STATE_JAZELLE: + /* core-specific ... ? */ + LOG_WARNING("Jazelle PC adjustment unknown"); + break; + } + break; + default: + /* 16: "MRS r0, CPSR"; then return via DCC + * 17: "MRS r0, SPSR"; then return via DCC + */ + retval = dpm->instr_read_data_r0(dpm, + ARMV4_5_MRS(0, regnum & 1), + &value); + break; + } + + if (retval == ERROR_OK) { + buf_set_u32(r->value, 0, 32, value); + r->valid = true; + r->dirty = false; + LOG_DEBUG("READ: %s, %8.8x", r->name, (unsigned) value); + } + + return retval; +} + +/* just write the register -- rely on the core mode being right */ +static int dpm_write_reg(struct arm_dpm *dpm, struct reg *r, unsigned regnum) +{ + int retval; + uint32_t value = buf_get_u32(r->value, 0, 32); + + switch (regnum) { + case 0 ... 14: + /* load register from DCC: "MCR p14, 0, Rnum, c0, c5, 0" */ + retval = dpm->instr_write_data_dcc(dpm, + ARMV4_5_MRC(14, 0, regnum, 0, 5, 0), + value); + break; + case 15: /* PC */ + /* read r0 from DCC; then "MOV pc, r0" */ + retval = dpm->instr_write_data_r0(dpm, 0xe1a0f000, value); + break; + default: + /* 16: read r0 from DCC, then "MSR r0, CPSR_cxsf" + * 17: read r0 from DCC, then "MSR r0, SPSR_cxsf" + */ + retval = dpm->instr_write_data_r0(dpm, + ARMV4_5_MSR_GP(0, 0xf, regnum & 1), + value); + + /* REVISIT on Cortex-A8, we need a Prefetch Flush operation + * after writing CPSR ... + cortex_a8_exec_opcode(target, + ARMV4_5_MCR(15, 0, 0, 7, 5, 4)); + */ + + break; + } + + if (retval == ERROR_OK) { + r->dirty = false; + LOG_DEBUG("WRITE: %s, %8.8x", r->name, (unsigned) value); + } + + return retval; +} + +/** + * Read basic registers of the the current context: R0 to R15, and CPSR; + * sets the core mode (such as USR or IRQ) and state (such as ARM or Thumb). + * In normal operation this is called on entry to halting debug state, + * possibly after some other operations supporting restore of debug state + * or making sure the CPU is fully idle (drain write buffer, etc). + */ +int arm_dpm_read_current_registers(struct arm_dpm *dpm) +{ + struct arm *arm = dpm->arm; + uint32_t cpsr; + int retval; + struct reg *r; + + retval = dpm->prepare(dpm); + if (retval != ERROR_OK) + return retval; + + /* read R0 first (it's used for scratch), then CPSR */ + r = arm->core_cache->reg_list + 0; + if (!r->valid) { + retval = dpm_read_reg(dpm, r, 0); + if (retval != ERROR_OK) + goto fail; + } + r->dirty = true; + + retval = dpm->instr_read_data_r0(dpm, ARMV4_5_MRS(0, 0), &cpsr); + if (retval != ERROR_OK) + goto fail; + + /* update core mode and state, plus shadow mapping for R8..R14 */ + arm_set_cpsr(arm, cpsr); + + /* REVISIT we can probably avoid reading R1..R14, saving time... */ + for (unsigned i = 1; i < 16; i++) { + r = arm_reg_current(arm, i); + if (r->valid) + continue; + + retval = dpm_read_reg(dpm, r, i); + if (retval != ERROR_OK) + goto fail; + } + + /* NOTE: SPSR ignored (if it's even relevant). */ + +fail: + /* (void) */ dpm->finish(dpm); + return retval; +} + +/** + * Writes all modified core registers for all processor modes. In normal + * operation this is called on exit from halting debug state. + */ +int arm_dpm_write_dirty_registers(struct arm_dpm *dpm) +{ + struct arm *arm = dpm->arm; + struct reg_cache *cache = arm->core_cache; + int retval; + bool did_write; + + retval = dpm->prepare(dpm); + if (retval != ERROR_OK) + goto done; + + /* Scan the registers until we find one that's both dirty and + * eligible for flushing. Flush that and everything else that + * shares the same core mode setting. Typically this won't + * actually find anything to do... + */ + do { + enum armv4_5_mode mode = ARMV4_5_MODE_ANY; + + did_write = false; + + /* check everything except our scratch register R0 */ + for (unsigned i = 1; i < cache->num_regs; i++) { + struct arm_reg *r; + unsigned regnum; + + /* also skip PC, CPSR, and non-dirty */ + if (i == 15) + continue; + if (arm->cpsr == cache->reg_list + i) + continue; + if (!cache->reg_list[i].dirty) + continue; + + r = cache->reg_list[i].arch_info; + regnum = r->num; + + /* may need to pick and set a mode */ + if (!did_write) { + enum armv4_5_mode tmode; + + did_write = true; + mode = tmode = r->mode; + + /* cope with special cases */ + switch (regnum) { + case 8 ... 12: + /* r8..r12 "anything but FIQ" case; + * we "know" core mode is accurate + * since we haven't changed it yet + */ + if (arm->core_mode == ARMV4_5_MODE_FIQ + && ARMV4_5_MODE_ANY + != mode) + tmode = ARMV4_5_MODE_USR; + break; + case 16: + /* SPSR */ + regnum++; + break; + } + + /* REVISIT error checks */ + if (tmode != ARMV4_5_MODE_ANY) + retval = dpm_modeswitch(dpm, tmode); + } + if (r->mode != mode) + continue; + + retval = dpm_write_reg(dpm, + &cache->reg_list[i], + regnum); + + } + + } while (did_write); + + /* Restore original CPSR ... assuming either that we changed it, + * or it's dirty. Must write PC to ensure the return address is + * defined, and must not write it before CPSR. + */ + retval = dpm_modeswitch(dpm, ARMV4_5_MODE_ANY); + arm->cpsr->dirty = false; + + retval = dpm_write_reg(dpm, &cache->reg_list[15], 15); + cache->reg_list[15].dirty = false; + + /* flush R0 -- it's *very* dirty by now */ + retval = dpm_write_reg(dpm, &cache->reg_list[0], 0); + cache->reg_list[0].dirty = false; + + /* (void) */ dpm->finish(dpm); +done: + return retval; +} + +/* Returns ARMV4_5_MODE_ANY or temporary mode to use while reading the + * specified register ... works around flakiness from ARM core calls. + * Caller already filtered out SPSR access; mode is never MODE_SYS + * or MODE_ANY. + */ +static enum armv4_5_mode dpm_mapmode(struct arm *arm, + unsigned num, enum armv4_5_mode mode) +{ + enum armv4_5_mode amode = arm->core_mode; + + /* don't switch if the mode is already correct */ + if (amode == ARMV4_5_MODE_SYS) + amode = ARMV4_5_MODE_USR; + if (mode == amode) + return ARMV4_5_MODE_ANY; + + switch (num) { + /* don't switch for non-shadowed registers (r0..r7, r15/pc, cpsr) */ + case 0 ... 7: + case 15: + case 16: + break; + /* r8..r12 aren't shadowed for anything except FIQ */ + case 8 ... 12: + if (mode == ARMV4_5_MODE_FIQ) + return mode; + break; + /* r13/sp, and r14/lr are always shadowed */ + case 13: + case 14: + return mode; + default: + LOG_WARNING("invalid register #%u", num); + break; + } + return ARMV4_5_MODE_ANY; +} + +static int arm_dpm_read_core_reg(struct target *target, struct reg *r, + int regnum, enum armv4_5_mode mode) +{ + struct arm_dpm *dpm = target_to_arm(target)->dpm; + int retval; + + if (regnum < 0 || regnum > 16) + return ERROR_INVALID_ARGUMENTS; + + if (regnum == 16) { + if (mode != ARMV4_5_MODE_ANY) + regnum = 17; + } else + mode = dpm_mapmode(dpm->arm, regnum, mode); + + /* REVISIT what happens if we try to read SPSR in a core mode + * which has no such register? + */ + + retval = dpm->prepare(dpm); + if (retval != ERROR_OK) + return retval; + + if (mode != ARMV4_5_MODE_ANY) { + retval = dpm_modeswitch(dpm, mode); + if (retval != ERROR_OK) + goto fail; + } + + retval = dpm_read_reg(dpm, r, regnum); + /* always clean up, regardless of error */ + + if (mode != ARMV4_5_MODE_ANY) + /* (void) */ dpm_modeswitch(dpm, ARMV4_5_MODE_ANY); + +fail: + /* (void) */ dpm->finish(dpm); + return retval; +} + +static int arm_dpm_write_core_reg(struct target *target, struct reg *r, + int regnum, enum armv4_5_mode mode, uint32_t value) +{ + struct arm_dpm *dpm = target_to_arm(target)->dpm; + int retval; + + + if (regnum < 0 || regnum > 16) + return ERROR_INVALID_ARGUMENTS; + + if (regnum == 16) { + if (mode != ARMV4_5_MODE_ANY) + regnum = 17; + } else + mode = dpm_mapmode(dpm->arm, regnum, mode); + + /* REVISIT what happens if we try to write SPSR in a core mode + * which has no such register? + */ + + retval = dpm->prepare(dpm); + if (retval != ERROR_OK) + return retval; + + if (mode != ARMV4_5_MODE_ANY) { + retval = dpm_modeswitch(dpm, mode); + if (retval != ERROR_OK) + goto fail; + } + + retval = dpm_write_reg(dpm, r, regnum); + /* always clean up, regardless of error */ + + if (mode != ARMV4_5_MODE_ANY) + /* (void) */ dpm_modeswitch(dpm, ARMV4_5_MODE_ANY); + +fail: + /* (void) */ dpm->finish(dpm); + return retval; +} + +static int arm_dpm_full_context(struct target *target) +{ + struct arm *arm = target_to_arm(target); + struct arm_dpm *dpm = arm->dpm; + struct reg_cache *cache = arm->core_cache; + int retval; + bool did_read; + + retval = dpm->prepare(dpm); + if (retval != ERROR_OK) + goto done; + + do { + enum armv4_5_mode mode = ARMV4_5_MODE_ANY; + + did_read = false; + + /* We "know" arm_dpm_read_current_registers() was called so + * the unmapped registers (R0..R7, PC, AND CPSR) and some + * view of R8..R14 are current. We also "know" oddities of + * register mapping: special cases for R8..R12 and SPSR. + * + * Pick some mode with unread registers and read them all. + * Repeat until done. + */ + for (unsigned i = 0; i < cache->num_regs; i++) { + struct arm_reg *r; + + if (cache->reg_list[i].valid) + continue; + r = cache->reg_list[i].arch_info; + + /* may need to pick a mode and set CPSR */ + if (!did_read) { + did_read = true; + mode = r->mode; + + /* For R8..R12 when we've entered debug + * state in FIQ mode... patch mode. + */ + if (mode == ARMV4_5_MODE_ANY) + mode = ARMV4_5_MODE_USR; + + /* REVISIT error checks */ + retval = dpm_modeswitch(dpm, mode); + } + if (r->mode != mode) + continue; + + /* CPSR was read, so "R16" must mean SPSR */ + retval = dpm_read_reg(dpm, + &cache->reg_list[i], + (r->num == 16) ? 17 : r->num); + + } + + } while (did_read); + + retval = dpm_modeswitch(dpm, ARMV4_5_MODE_ANY); + /* (void) */ dpm->finish(dpm); +done: + return retval; +} + +/** + * Hooks up this DPM to its associated target; call only once. + * Initially this only covers the register cache. + */ +int arm_dpm_setup(struct arm_dpm *dpm) +{ + struct arm *arm = dpm->arm; + struct target *target = arm->target; + struct reg_cache *cache; + + arm->dpm = dpm; + + arm->full_context = arm_dpm_full_context; + arm->read_core_reg = arm_dpm_read_core_reg; + arm->write_core_reg = arm_dpm_write_core_reg; + + cache = armv4_5_build_reg_cache(target, arm); + if (!cache) + return ERROR_FAIL; + + *register_get_last_cache_p(&target->reg_cache) = cache; + return ERROR_OK; +} + +/** + * Reinitializes DPM state at the beginning of a new debug session + * or after a reset which may have affected the debug module. + */ +int arm_dpm_initialize(struct arm_dpm *dpm) +{ + /* FIXME -- nothing yet */ + return ERROR_OK; +} diff --git a/src/target/arm_dpm.h b/src/target/arm_dpm.h new file mode 100644 index 0000000..06b548e --- /dev/null +++ b/src/target/arm_dpm.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2009 by David Brownell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __ARM_DPM_H +#define __ARM_DPM_H + +/** + * @file + * This is the interface to the Debug Programmers Model for ARMv6 and + * ARMv7 processors. ARMv6 processors (such as ARM11xx implementations) + * introduced a model which became part of the ARMv7-AR architecture + * which is most familiar through the Cortex-A series parts. While + * specific details differ (like how to write the instruction register), + * the high level models easily support shared code because those + * registers are compatible. + */ + +/** + * This wraps an implementation of DPM primitives. Each interface + * provider supplies a structure like this, which is the glue between + * upper level code and the lower level hardware access. + * + * It is a PRELIMINARY AND INCOMPLETE set of primitives, starting with + * support for CPU register access. + */ +struct arm_dpm { + struct arm *arm; + + /** Cache of DIDR */ + uint32_t didr; + + /** Invoke before a series of instruction operations */ + int (*prepare)(struct arm_dpm *); + + /** Invoke after a series of instruction operations */ + int (*finish)(struct arm_dpm *); + + /* WRITE TO CPU */ + + /** Runs one instruction, writing data to DCC before execution. */ + int (*instr_write_data_dcc)(struct arm_dpm *, + uint32_t opcode, uint32_t data); + + /** Runs one instruction, writing data to R0 before execution. */ + int (*instr_write_data_r0)(struct arm_dpm *, + uint32_t opcode, uint32_t data); + + /* READ FROM CPU */ + + /** Runs one instruction, reading data from dcc after execution. */ + int (*instr_read_data_dcc)(struct arm_dpm *, + uint32_t opcode, uint32_t *data); + + /** Runs one instruction, reading data from r0 after execution. */ + int (*instr_read_data_r0)(struct arm_dpm *, + uint32_t opcode, uint32_t *data); + + // FIXME -- add breakpoint support + + // FIXME -- add watchpoint support (including context-sensitive ones) + + // FIXME -- read/write DCSR methods and symbols +}; + +int arm_dpm_setup(struct arm_dpm *dpm); +int arm_dpm_reinitialize(struct arm_dpm *dpm); + +int arm_dpm_read_current_registers(struct arm_dpm *); +int arm_dpm_write_dirty_registers(struct arm_dpm *); + +#endif /* __ARM_DPM_H */ diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index 461d206..da5c75a 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -1233,6 +1233,7 @@ static int arm_full_context(struct target *target) int armv4_5_init_arch_info(struct target *target, struct arm *armv4_5) { target->arch_info = armv4_5; + armv4_5->target = target; armv4_5->common_magic = ARMV4_5_COMMON_MAGIC; arm_set_cpsr(armv4_5, ARMV4_5_MODE_USR); diff --git a/src/target/armv4_5.h b/src/target/armv4_5.h index 4931455..7a6cb61 100644 --- a/src/target/armv4_5.h +++ b/src/target/armv4_5.h @@ -101,6 +101,12 @@ struct arm /** Flag reporting unavailability of the BKPT instruction. */ bool is_armv4; + /** Backpointer to the target. */ + struct target *target; + + /** Handle for the debug module, if one is present. */ + struct arm_dpm *dpm; + /** Handle for the Embedded Trace Module, if one is present. */ struct etm_context *etm; commit ad75af0b17af75d57b95298fb40784d33cc8f3e2 Author: David Brownell <dbr...@us...> Date: Tue Nov 24 00:13:43 2009 -0800 target: cope with *any* error setting a breakpoint It's wrong to map unrecognized failure codes to success. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index f657ddc..3ab1464 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -46,6 +46,7 @@ int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enu { struct breakpoint *breakpoint = target->breakpoints; struct breakpoint **breakpoint_p = &target->breakpoints; + char *reason; int retval; int n; @@ -53,7 +54,11 @@ int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enu while (breakpoint) { n++; - if (breakpoint->address == address){ + if (breakpoint->address == address) { + /* FIXME don't assume "same address" means "same + * breakpoint" ... check all the parameters before + * succeeding. + */ LOG_DEBUG("Duplicate Breakpoint address: 0x%08" PRIx32 " (BP %d)", address, breakpoint->unique_id ); return ERROR_OK; @@ -71,31 +76,24 @@ int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enu (*breakpoint_p)->next = NULL; (*breakpoint_p)->unique_id = bpwp_unique_id++; - if ((retval = target_add_breakpoint(target, *breakpoint_p)) != ERROR_OK) - { - switch (retval) - { - case ERROR_TARGET_RESOURCE_NOT_AVAILABLE: - LOG_INFO("can't add %s breakpoint, resource not available (BPID=%d)", - breakpoint_type_strings[(*breakpoint_p)->type], - (*breakpoint_p)->unique_id ); - - free((*breakpoint_p)->orig_instr); - free(*breakpoint_p); - *breakpoint_p = NULL; - return retval; - break; - case ERROR_TARGET_NOT_HALTED: - LOG_INFO("can't add breakpoint while target is running (BPID: %d)", - (*breakpoint_p)->unique_id ); - free((*breakpoint_p)->orig_instr); - free(*breakpoint_p); - *breakpoint_p = NULL; - return retval; - break; - default: - break; - } + retval = target_add_breakpoint(target, *breakpoint_p); + switch (retval) { + case ERROR_OK: + break; + case ERROR_TARGET_RESOURCE_NOT_AVAILABLE: + reason = "resource not available"; + goto fail; + case ERROR_TARGET_NOT_HALTED: + reason = "target running"; + goto fail; + default: + reason = "unknown reason"; +fail: + LOG_ERROR("can't add breakpoint: %s", reason); + free((*breakpoint_p)->orig_instr); + free(*breakpoint_p); + *breakpoint_p = NULL; + return retval; } LOG_DEBUG("added %s breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %d)", ----------------------------------------------------------------------- Summary of changes: src/target/Makefile.am | 2 + src/target/arm11.c | 50 ----- src/target/arm11.h | 13 +- src/target/arm11_dbgtap.c | 73 +++++++ src/target/arm11_dbgtap.h | 3 + src/target/arm_dpm.c | 529 +++++++++++++++++++++++++++++++++++++++++++++ src/target/arm_dpm.h | 87 ++++++++ src/target/armv4_5.c | 1 + src/target/armv4_5.h | 6 + src/target/breakpoints.c | 50 ++--- 10 files changed, 729 insertions(+), 85 deletions(-) create mode 100644 src/target/arm_dpm.c create mode 100644 src/target/arm_dpm.h hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-24 09:01:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 0583cb0a0d222787c4048f9362292c5db9d969b0 (commit) from 0d06a06f8bb7d0dcb91ec7d31ab00c0c730f1cf4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0583cb0a0d222787c4048f9362292c5db9d969b0 Author: Andreas Fritiofson <and...@gm...> Date: Tue Nov 24 00:32:54 2009 +0100 support for scripts in $HOME/.openocd Add $HOME/.openocd as the first default script search directory, allowing the user to override the standard scripts. Update the user guide with information on where OpenOCD expects to find configuration files and scripts. Also fixed some minor formatting issues. Add entry to NEWS as well. Signed-off-by: Andreas Fritiofson <and...@gm...> Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/NEWS b/NEWS index 1a024e4..0dcc4bc 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ Flash Layer: Board, Target, and Interface Configuration Scripts: ARM9 - ETM and ETB hookup for iMX2* targets + Add $HOME/.openocd to the search path. Documentation: Build and Release: diff --git a/doc/openocd.texi b/doc/openocd.texi index cff7fc5..e94c9d0 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -483,14 +483,24 @@ bash$ openocd --help --pipe | -p use pipes when talking to gdb @end verbatim -By default OpenOCD reads the file configuration file @file{openocd.cfg} -in the current directory. To specify a different (or multiple) -configuration file, you can use the ``-f'' option. For example: +By default OpenOCD reads the configuration file @file{openocd.cfg}. +To specify a different (or multiple) +configuration file, you can use the @option{-f} option. For example: @example openocd -f config1.cfg -f config2.cfg -f config3.cfg @end example +Configuration files and scripts are searched for in +@enumerate +@item the current directory, +@item any search dir specified on the command line using the @option{-s} option, +@item @file{$HOME/.openocd} (not on Windows), +@item the site wide script library @file{$pkgdatadir/site} and +@item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}. +@end enumerate +The first found file with a matching file name will be used. + OpenOCD starts by processing the configuration commands provided on the command line or in @file{openocd.cfg}. @xref{Configuration Stage}. @@ -507,7 +517,7 @@ clients (Telnet, GDB, Other) and processes the commands issued through those channels. If you are having problems, you can enable internal debug messages via -the ``-d'' option. +the @option{-d} option. Also it is possible to interleave JIM-Tcl commands w/config scripts using the @option{-c} command line switch. @@ -523,10 +533,6 @@ setting from within a telnet or gdb session using @command{debug_level You can redirect all output from the daemon to a file using the @option{-l <logfile>} switch. -Search paths for config/script files can be added to OpenOCD by using -the @option{-s <search>} switch. The current directory and the OpenOCD -target library is in the search path by default. - For details on the @option{-p} option. @xref{Connecting to GDB}. Note! OpenOCD will launch the GDB & telnet server even if it can not diff --git a/src/helper/options.c b/src/helper/options.c index 874196e..3db96fd 100644 --- a/src/helper/options.c +++ b/src/helper/options.c @@ -101,7 +101,22 @@ static void add_default_dirs(void) * listed last in the built-in search order, so the user can * override these scripts with site-specific customizations. */ - /// @todo Implement @c add_script_search_dir("${HOME}/.openocd"). + + const char *home = getenv("HOME"); + + if (home) + { + char *path; + + path = alloc_printf("%s/.openocd", home); + + if (path) + { + add_script_search_dir(path); + free(path); + } + } + add_script_search_dir(PKGDATADIR "/site"); add_script_search_dir(PKGDATADIR "/scripts"); #endif ----------------------------------------------------------------------- Summary of changes: NEWS | 1 + doc/openocd.texi | 22 ++++++++++++++-------- src/helper/options.c | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-24 08:28:33
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 0d06a06f8bb7d0dcb91ec7d31ab00c0c730f1cf4 (commit) from 828d006a9d05b24b6dcdf1c552912e04586d6f7d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0d06a06f8bb7d0dcb91ec7d31ab00c0c730f1cf4 Author: Jerry Ling <jer...@dr...> Date: Mon Nov 23 12:11:54 2009 +0100 mips: fix gaffe when removing dynamic array allocation Classic sizeof() gaffe. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 40627e1..4f9a704 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -620,7 +620,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c memcpy(¶m_in[2], buf, count * sizeof(uint32_t)); mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1); + count + 2, param_in, 0, NULL, 1); free(param_in); @@ -715,7 +715,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c } mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1); + count + 2, param_in, 0, NULL, 1); free(param_in); @@ -778,7 +778,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co } retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ - sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1); + count +2, param_in, 0, NULL, 1); free(param_in); ----------------------------------------------------------------------- Summary of changes: src/target/mips32_pracc.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-23 20:33:08
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 828d006a9d05b24b6dcdf1c552912e04586d6f7d (commit) from eeb4276deb5c3ba6621b8121d460bc50857c8d53 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 828d006a9d05b24b6dcdf1c552912e04586d6f7d Author: Ãyvind Harboe <oyv...@zy...> Date: Mon Nov 23 18:23:10 2009 +0100 arm926ejs: fix gaffe when converting from arm926ejs cp15 to mcr the first arg is the register number 15 = cp15. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/tcl/board/dm355evm.cfg b/tcl/board/dm355evm.cfg index 2e298b7..2c8bea8 100644 --- a/tcl/board/dm355evm.cfg +++ b/tcl/board/dm355evm.cfg @@ -182,7 +182,7 @@ proc dm355evm_init {} { ######################## # turn on icache - set I bit in cp15 register c1 - mcr 0 0 1 0 0x00051078 + mcr 15 0 0 1 0 0x00051078 } # NAND -- socket has two chipselects, MT29F16G08FAA puts 1GByte on each one. diff --git a/tcl/board/openrd.cfg b/tcl/board/openrd.cfg index 4bc708d..12cc79e 100644 --- a/tcl/board/openrd.cfg +++ b/tcl/board/openrd.cfg @@ -29,7 +29,7 @@ proc openrd_init { } { jtag_reset 0 0 wait_halt - mcr 0 0 1 0 0x00052078 + mcr 15 0 0 1 0 0x00052078 mww 0xD0001400 0x43000C30 # DDR SDRAM Configuration Register mww 0xD0001404 0x37543000 # Dunit Control Low Register diff --git a/tcl/board/sheevaplug.cfg b/tcl/board/sheevaplug.cfg index 8e8396d..9267eb9 100644 --- a/tcl/board/sheevaplug.cfg +++ b/tcl/board/sheevaplug.cfg @@ -29,7 +29,7 @@ proc sheevaplug_init { } { jtag_reset 0 0 wait_halt - mcr 0 0 1 0 0x00052078 + mcr 15 0 0 1 0 0x00052078 mww 0xD0001400 0x43000C30 # DDR SDRAM Configuration Register mww 0xD0001404 0x39543000 # Dunit Control Low Register ----------------------------------------------------------------------- Summary of changes: tcl/board/dm355evm.cfg | 2 +- tcl/board/openrd.cfg | 2 +- tcl/board/sheevaplug.cfg | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-23 14:06:24
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via eeb4276deb5c3ba6621b8121d460bc50857c8d53 (commit) from b8b1353dd798d4aa811cdccc8eb2d6b41c1090d4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit eeb4276deb5c3ba6621b8121d460bc50857c8d53 Author: Ãyvind Harboe <oyv...@zy...> Date: Mon Oct 26 14:08:43 2009 +0100 arm926ejs: retire cp15 commands, handled by mrc/mcr. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/doc/openocd.texi b/doc/openocd.texi index 9659e92..cff7fc5 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -5704,13 +5704,6 @@ they are not built from ARM926ej-s designs. Print information about the caches found. @end deffn -@deffn Command {arm926ejs cp15} opcode1 opcode2 CRn CRm regnum [value] -Accesses cp15 register @var{regnum} using -@var{opcode1}, @var{opcode2}, @var{CRn}, and @var{CRm}. -If a @var{value} is provided, that value is written to that register. -Else that register is read and displayed. -@end deffn - @subsection ARM966E specific commands @cindex ARM966E diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 56d86cc..24488c4 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -713,67 +713,6 @@ static int arm926ejs_target_create(struct target *target, Jim_Interp *interp) return arm926ejs_init_arch_info(target, arm926ejs, target->tap); } -COMMAND_HANDLER(arm926ejs_handle_cp15_command) -{ - int retval; - struct target *target = get_current_target(CMD_CTX); - struct arm926ejs_common *arm926ejs = target_to_arm926(target); - int opcode_1; - int opcode_2; - int CRn; - int CRm; - - if ((CMD_ARGC < 4) || (CMD_ARGC > 5)) - { - command_print(CMD_CTX, "usage: arm926ejs cp15 <opcode_1> <opcode_2> <CRn> <CRm> [value]"); - return ERROR_OK; - } - - COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], opcode_1); - COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], opcode_2); - COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], CRn); - COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], CRm); - - retval = arm926ejs_verify_pointer(CMD_CTX, arm926ejs); - if (retval != ERROR_OK) - return retval; - - if (target->state != TARGET_HALTED) - { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); - return ERROR_OK; - } - - if (CMD_ARGC == 4) - { - uint32_t value; - if ((retval = arm926ejs->read_cp15(target, opcode_1, opcode_2, CRn, CRm, &value)) != ERROR_OK) - { - command_print(CMD_CTX, "couldn't access register"); - return ERROR_OK; - } - if ((retval = jtag_execute_queue()) != ERROR_OK) - { - return retval; - } - - command_print(CMD_CTX, "%i %i %i %i: %8.8" PRIx32 "", opcode_1, opcode_2, CRn, CRm, value); - } - else - { - uint32_t value; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[4], value); - if ((retval = arm926ejs->write_cp15(target, opcode_1, opcode_2, CRn, CRm, value)) != ERROR_OK) - { - command_print(CMD_CTX, "couldn't access register"); - return ERROR_OK; - } - command_print(CMD_CTX, "%i %i %i %i: %8.8" PRIx32 "", opcode_1, opcode_2, CRn, CRm, value); - } - - return ERROR_OK; -} - COMMAND_HANDLER(arm926ejs_handle_cache_info_command) { int retval; @@ -829,11 +768,6 @@ int arm926ejs_register_commands(struct command_context *cmd_ctx) NULL, COMMAND_ANY, "arm926ejs specific commands"); - register_command(cmd_ctx, arm926ejs_cmd, "cp15", - arm926ejs_handle_cp15_command, COMMAND_EXEC, - "display/modify cp15 register " - "<opcode_1> <opcode_2> <CRn> <CRm> [value]"); - register_command(cmd_ctx, arm926ejs_cmd, "cache_info", arm926ejs_handle_cache_info_command, COMMAND_EXEC, "display information about target caches"); diff --git a/tcl/board/dm355evm.cfg b/tcl/board/dm355evm.cfg index 1f814b2..2e298b7 100644 --- a/tcl/board/dm355evm.cfg +++ b/tcl/board/dm355evm.cfg @@ -182,7 +182,7 @@ proc dm355evm_init {} { ######################## # turn on icache - set I bit in cp15 register c1 - arm926ejs cp15 0 0 1 0 0x00051078 + mcr 0 0 1 0 0x00051078 } # NAND -- socket has two chipselects, MT29F16G08FAA puts 1GByte on each one. diff --git a/tcl/board/openrd.cfg b/tcl/board/openrd.cfg index e8784d4..4bc708d 100644 --- a/tcl/board/openrd.cfg +++ b/tcl/board/openrd.cfg @@ -29,7 +29,7 @@ proc openrd_init { } { jtag_reset 0 0 wait_halt - arm926ejs cp15 0 0 1 0 0x00052078 + mcr 0 0 1 0 0x00052078 mww 0xD0001400 0x43000C30 # DDR SDRAM Configuration Register mww 0xD0001404 0x37543000 # Dunit Control Low Register diff --git a/tcl/board/sheevaplug.cfg b/tcl/board/sheevaplug.cfg index afd621a..8e8396d 100644 --- a/tcl/board/sheevaplug.cfg +++ b/tcl/board/sheevaplug.cfg @@ -29,7 +29,7 @@ proc sheevaplug_init { } { jtag_reset 0 0 wait_halt - arm926ejs cp15 0 0 1 0 0x00052078 + mcr 0 0 1 0 0x00052078 mww 0xD0001400 0x43000C30 # DDR SDRAM Configuration Register mww 0xD0001404 0x39543000 # Dunit Control Low Register ----------------------------------------------------------------------- Summary of changes: doc/openocd.texi | 7 ----- src/target/arm926ejs.c | 66 ---------------------------------------------- tcl/board/dm355evm.cfg | 2 +- tcl/board/openrd.cfg | 2 +- tcl/board/sheevaplug.cfg | 2 +- 5 files changed, 3 insertions(+), 76 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: David B. <dbr...@us...> - 2009-11-23 00:51:32
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via b8b1353dd798d4aa811cdccc8eb2d6b41c1090d4 (commit) via fa9b0e2167c295c1f0de349563b893540fc73cb0 (commit) from af7f6891e98d538eabcf137d89f28bf3406a4999 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b8b1353dd798d4aa811cdccc8eb2d6b41c1090d4 Author: David Brownell <dbr...@us...> Date: Sun Nov 22 15:51:16 2009 -0800 ARM11: remove unused state and exports For now there's no point in saving this stuff after examine() checks it out as OK. Ditto exporting symbols that aren't used outside of the module which defines them. In fact, those two things needlessly complicate the code... Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index 0a54c52..cb1af7b 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -385,7 +385,7 @@ static int arm11_on_enter_debug_state(struct arm11_common *arm11) return ERROR_OK; } -void arm11_dump_reg_changes(struct arm11_common * arm11) +static void arm11_dump_reg_changes(struct arm11_common * arm11) { if (!(debug_level >= LOG_LVL_DEBUG)) @@ -1680,6 +1680,8 @@ static int arm11_examine(struct target *target) int retval; char *type; struct arm11_common *arm11 = target_to_arm11(target); + uint32_t didr, device_id; + uint8_t implementor; /* check IDCODE */ @@ -1687,7 +1689,7 @@ static int arm11_examine(struct target *target) struct scan_field idcode_field; - arm11_setup_field(arm11, 32, NULL, &arm11->device_id, &idcode_field); + arm11_setup_field(arm11, 32, NULL, &device_id, &idcode_field); arm11_add_dr_scan_vc(1, &idcode_field, TAP_DRPAUSE); @@ -1699,14 +1701,14 @@ static int arm11_examine(struct target *target) struct scan_field chain0_fields[2]; - arm11_setup_field(arm11, 32, NULL, &arm11->didr, chain0_fields + 0); - arm11_setup_field(arm11, 8, NULL, &arm11->implementor, chain0_fields + 1); + arm11_setup_field(arm11, 32, NULL, &didr, chain0_fields + 0); + arm11_setup_field(arm11, 8, NULL, &implementor, chain0_fields + 1); arm11_add_dr_scan_vc(ARRAY_SIZE(chain0_fields), chain0_fields, TAP_IDLE); CHECK_RETVAL(jtag_execute_queue()); - switch (arm11->device_id & 0x0FFFF000) + switch (device_id & 0x0FFFF000) { case 0x07B36000: type = "ARM1136"; @@ -1724,26 +1726,25 @@ static int arm11_examine(struct target *target) } LOG_INFO("found %s", type); - arm11->debug_version = (arm11->didr >> 16) & 0x0F; - - if (arm11->debug_version != ARM11_DEBUG_V6 && - arm11->debug_version != ARM11_DEBUG_V61) - { - LOG_ERROR("Only ARMv6 v6 and v6.1 architectures supported."); + /* unlikely this could ever fail, but ... */ + switch ((didr >> 16) & 0x0F) { + case ARM11_DEBUG_V6: + case ARM11_DEBUG_V61: /* supports security extensions */ + break; + default: + LOG_ERROR("Only ARM v6 and v6.1 debug supported."); return ERROR_FAIL; } - arm11->brp = ((arm11->didr >> 24) & 0x0F) + 1; - arm11->wrp = ((arm11->didr >> 28) & 0x0F) + 1; + arm11->brp = ((didr >> 24) & 0x0F) + 1; + arm11->wrp = ((didr >> 28) & 0x0F) + 1; /** \todo TODO: reserve one brp slot if we allow breakpoints during step */ arm11->free_brps = arm11->brp; arm11->free_wrps = arm11->wrp; - LOG_DEBUG("IDCODE %08" PRIx32 " IMPLEMENTOR %02x DIDR %08" PRIx32 "", - arm11->device_id, - (int)(arm11->implementor), - arm11->didr); + LOG_DEBUG("IDCODE %08" PRIx32 " IMPLEMENTOR %02x DIDR %08" PRIx32, + device_id, implementor, didr); /* as a side-effect this reads DSCR and thus * clears the ARM11_DSCR_STICKY_PRECISE_DATA_ABORT / Sticky Precise Data Abort Flag diff --git a/src/target/arm11.h b/src/target/arm11.h index 3d7841d..d40faa4 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -62,15 +62,9 @@ struct arm11_common /** \name Processor type detection */ /*@{*/ - uint32_t device_id; /**< IDCODE readout */ - uint32_t didr; /**< DIDR readout (debug capabilities) */ - uint8_t implementor; /**< DIDR Implementor readout */ - size_t brp; /**< Number of Breakpoint Register Pairs from DIDR */ size_t wrp; /**< Number of Watchpoint Register Pairs from DIDR */ - enum arm11_debug_version - debug_version; /**< ARM debug architecture from DIDR */ /*@}*/ uint32_t last_dscr; /**< Last retrieved DSCR value; diff --git a/src/target/arm11_dbgtap.c b/src/target/arm11_dbgtap.c index 26de4ce..c8d5902 100644 --- a/src/target/arm11_dbgtap.c +++ b/src/target/arm11_dbgtap.c @@ -48,7 +48,8 @@ static const tap_state_t arm11_move_pi_to_si_via_ci[] = }; -int arm11_add_ir_scan_vc(int num_fields, struct scan_field *fields, tap_state_t state) +static int arm11_add_ir_scan_vc(int num_fields, struct scan_field *fields, + tap_state_t state) { if (cmd_queue_cur_state == TAP_IRPAUSE) jtag_add_pathmove(ARRAY_SIZE(arm11_move_pi_to_si_via_ci), arm11_move_pi_to_si_via_ci); @@ -201,7 +202,8 @@ int arm11_add_debug_SCAN_N(struct arm11_common * arm11, uint8_t chain, tap_state * * \remarks This adds to the JTAG command queue but does \em not execute it. */ -void arm11_add_debug_INST(struct arm11_common * arm11, uint32_t inst, uint8_t * flag, tap_state_t state) +static void arm11_add_debug_INST(struct arm11_common * arm11, + uint32_t inst, uint8_t * flag, tap_state_t state) { JTAG_DEBUG("INST <= 0x%08x", inst); @@ -377,7 +379,9 @@ int arm11_run_instr_data_finish(struct arm11_common * arm11) * \param count Number of opcodes to execute * */ -int arm11_run_instr_no_data(struct arm11_common * arm11, uint32_t * opcode, size_t count) +static +int arm11_run_instr_no_data(struct arm11_common * arm11, + uint32_t * opcode, size_t count) { arm11_add_IR(arm11, ARM11_ITRSEL, ARM11_TAP_DEFAULT); diff --git a/src/target/arm11_dbgtap.h b/src/target/arm11_dbgtap.h index 87b66a5..b85a138 100644 --- a/src/target/arm11_dbgtap.h +++ b/src/target/arm11_dbgtap.h @@ -11,8 +11,6 @@ void arm11_add_IR(struct arm11_common *arm11, uint8_t instr, tap_state_t state); int arm11_add_debug_SCAN_N(struct arm11_common *arm11, uint8_t chain, tap_state_t state); -void arm11_add_debug_INST(struct arm11_common *arm11, - uint32_t inst, uint8_t *flag, tap_state_t state); int arm11_read_DSCR(struct arm11_common *arm11, uint32_t *dscr); int arm11_write_DSCR(struct arm11_common *arm11, uint32_t dscr); @@ -20,8 +18,6 @@ enum target_debug_reason arm11_get_DSCR_debug_reason(uint32_t dscr); int arm11_run_instr_data_prepare(struct arm11_common *arm11); int arm11_run_instr_data_finish(struct arm11_common *arm11); -int arm11_run_instr_no_data(struct arm11_common *arm11, - uint32_t *opcode, size_t count); int arm11_run_instr_no_data1(struct arm11_common *arm11, uint32_t opcode); int arm11_run_instr_data_to_core(struct arm11_common *arm11, uint32_t opcode, uint32_t *data, size_t count); @@ -38,8 +34,6 @@ int arm11_run_instr_data_to_core_via_r0(struct arm11_common *arm11, int arm11_add_dr_scan_vc(int num_fields, struct scan_field *fields, tap_state_t state); -int arm11_add_ir_scan_vc(int num_fields, struct scan_field *fields, - tap_state_t state); /** * Used with arm11_sc7_run to make a list of read/write commands for commit fa9b0e2167c295c1f0de349563b893540fc73cb0 Author: David Brownell <dbr...@us...> Date: Sun Nov 22 15:50:24 2009 -0800 ARM11: macro cleanup Make this code look more like the rest of the OpenOCD code. - Use calloc() directly, not NEW() ... and fix some potential memory leaks while we're at it. - Remove FNC_INFO ... it's a NOP that just clutters things, and it's trivial for developers to add tracing as needed. - Replace FNC_INFO_NOTIMPLEMENTED with LOG_WARNING calls; ditto. And stop having those call sites wrongly succeed! - Waste less space with the CHECK_RETVAL() macro. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index 1a7b4e0..0a54c52 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -40,18 +40,6 @@ #define _DEBUG_INSTRUCTION_EXECUTION_ #endif -#if 0 -#define FNC_INFO LOG_DEBUG("-") -#else -#define FNC_INFO -#endif - -#if 1 -#define FNC_INFO_NOTIMPLEMENTED do { LOG_DEBUG("NOT IMPLEMENTED"); /*exit(-1);*/ } while (0) -#else -#define FNC_INFO_NOTIMPLEMENTED -#endif - static bool arm11_config_memwrite_burst = true; static bool arm11_config_memwrite_error_fatal = true; static uint32_t arm11_vcr = 0; @@ -180,8 +168,6 @@ static void arm11_dump_reg_changes(struct arm11_common * arm11); */ static int arm11_check_init(struct arm11_common *arm11, uint32_t *dscr) { - FNC_INFO; - uint32_t dscr_local_tmp_copy; if (!dscr) @@ -239,7 +225,6 @@ static int arm11_check_init(struct arm11_common *arm11, uint32_t *dscr) static int arm11_on_enter_debug_state(struct arm11_common *arm11) { int retval; - FNC_INFO; for (size_t i = 0; i < ARRAY_SIZE(arm11->reg_values); i++) { @@ -437,7 +422,6 @@ void arm11_dump_reg_changes(struct arm11_common * arm11) */ static int arm11_leave_debug_state(struct arm11_common *arm11) { - FNC_INFO; int retval; retval = arm11_run_instr_data_prepare(arm11); @@ -569,7 +553,6 @@ static void arm11_record_register_history(struct arm11_common *arm11) /* poll current target status */ static int arm11_poll(struct target *target) { - FNC_INFO; int retval; struct arm11_common *arm11 = target_to_arm11(target); uint32_t dscr; @@ -626,15 +609,14 @@ static int arm11_arch_state(struct target *target) static int arm11_target_request_data(struct target *target, uint32_t size, uint8_t *buffer) { - FNC_INFO_NOTIMPLEMENTED; + LOG_WARNING("Not implemented: %s", __func__); - return ERROR_OK; + return ERROR_FAIL; } /* target execution control */ static int arm11_halt(struct target *target) { - FNC_INFO; struct arm11_common *arm11 = target_to_arm11(target); LOG_DEBUG("target->state: %s", @@ -699,8 +681,6 @@ static int arm11_halt(struct target *target) static int arm11_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) { - FNC_INFO; - // LOG_DEBUG("current %d address %08x handle_breakpoints %d debug_execution %d", // current, address, handle_breakpoints, debug_execution); @@ -880,7 +860,7 @@ static void arm11_sim_set_state(struct arm_sim_interface *sim, // struct arm11_common * arm11 = (struct arm11_common *)sim->user_data; /* FIX!!!! we should implement thumb for arm11 */ - LOG_ERROR("Not implemetned!"); + LOG_ERROR("Not implemented: %s", __func__); } @@ -913,8 +893,6 @@ static int arm11_simulate_step(struct target *target, uint32_t *dry_run_pc) static int arm11_step(struct target *target, int current, uint32_t address, int handle_breakpoints) { - FNC_INFO; - LOG_DEBUG("target->state: %s", target_state_name(target)); @@ -1068,7 +1046,6 @@ static int arm11_step(struct target *target, int current, static int arm11_assert_reset(struct target *target) { - FNC_INFO; int retval; struct arm11_common *arm11 = target_to_arm11(target); @@ -1135,16 +1112,15 @@ static int arm11_deassert_reset(struct target *target) static int arm11_soft_reset_halt(struct target *target) { - FNC_INFO_NOTIMPLEMENTED; + LOG_WARNING("Not implemented: %s", __func__); - return ERROR_OK; + return ERROR_FAIL; } /* target register access for gdb */ static int arm11_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size) { - FNC_INFO; struct arm11_common *arm11 = target_to_arm11(target); *reg_list_size = ARM11_GDB_REGISTER_COUNT; @@ -1181,8 +1157,6 @@ static int arm11_read_memory_inner(struct target *target, /** \todo TODO: check if buffer cast to uint32_t* and uint16_t* might cause alignment problems */ int retval; - FNC_INFO; - if (target->state != TARGET_HALTED) { LOG_WARNING("target was not halted"); @@ -1277,7 +1251,6 @@ static int arm11_write_memory_inner(struct target *target, bool arm11_config_memrw_no_increment) { int retval; - FNC_INFO; if (target->state != TARGET_HALTED) { @@ -1421,8 +1394,6 @@ static int arm11_write_memory(struct target *target, static int arm11_bulk_write_memory(struct target *target, uint32_t address, uint32_t count, uint8_t *buffer) { - FNC_INFO; - if (target->state != TARGET_HALTED) { LOG_WARNING("target was not halted"); @@ -1438,7 +1409,6 @@ static int arm11_bulk_write_memory(struct target *target, static int arm11_add_breakpoint(struct target *target, struct breakpoint *breakpoint) { - FNC_INFO; struct arm11_common *arm11 = target_to_arm11(target); #if 0 @@ -1469,7 +1439,6 @@ static int arm11_add_breakpoint(struct target *target, static int arm11_remove_breakpoint(struct target *target, struct breakpoint *breakpoint) { - FNC_INFO; struct arm11_common *arm11 = target_to_arm11(target); arm11->free_brps++; @@ -1480,17 +1449,17 @@ static int arm11_remove_breakpoint(struct target *target, static int arm11_add_watchpoint(struct target *target, struct watchpoint *watchpoint) { - FNC_INFO_NOTIMPLEMENTED; + LOG_WARNING("Not implemented: %s", __func__); - return ERROR_OK; + return ERROR_FAIL; } static int arm11_remove_watchpoint(struct target *target, struct watchpoint *watchpoint) { - FNC_INFO_NOTIMPLEMENTED; + LOG_WARNING("Not implemented: %s", __func__); - return ERROR_OK; + return ERROR_FAIL; } // HACKHACKHACK - FIXME mode/state @@ -1665,11 +1634,7 @@ restore: static int arm11_target_create(struct target *target, Jim_Interp *interp) { - FNC_INFO; - - NEW(struct arm11_common, arm11, 1); - - arm11->target = target; + struct arm11_common *arm11; if (target->tap == NULL) return ERROR_FAIL; @@ -1680,8 +1645,14 @@ static int arm11_target_create(struct target *target, Jim_Interp *interp) return ERROR_COMMAND_SYNTAX_ERROR; } + arm11 = calloc(1, sizeof *arm11); + if (!arm11) + return ERROR_FAIL; + armv4_5_init_arch_info(target, &arm11->arm); + arm11->target = target; + arm11->jtag_info.tap = target->tap; arm11->jtag_info.scann_size = 5; arm11->jtag_info.scann_instr = ARM11_SCAN_N; @@ -1708,7 +1679,6 @@ static int arm11_examine(struct target *target) { int retval; char *type; - FNC_INFO; struct arm11_common *arm11 = target_to_arm11(target); /* check IDCODE */ @@ -1801,8 +1771,6 @@ static int arm11_examine(struct target *target) /** Load a register that is marked !valid in the register cache */ static int arm11_get_reg(struct reg *reg) { - FNC_INFO; - struct target * target = ((struct arm11_reg_state *)reg->arch_info)->target; if (target->state != TARGET_HALTED) @@ -1824,8 +1792,6 @@ static int arm11_get_reg(struct reg *reg) /** Change a value in the register cache */ static int arm11_set_reg(struct reg *reg, uint8_t *buf) { - FNC_INFO; - struct target *target = ((struct arm11_reg_state *)reg->arch_info)->target; struct arm11_common *arm11 = target_to_arm11(target); // const struct arm11_reg_defs *arm11_reg_info = arm11_reg_defs + ((struct arm11_reg_state *)reg->arch_info)->def_index; @@ -1845,10 +1811,20 @@ static const struct reg_arch_type arm11_reg_type = { static int arm11_build_reg_cache(struct target *target) { struct arm11_common *arm11 = target_to_arm11(target); - - NEW(struct reg_cache, cache, 1); - NEW(struct reg, reg_list, ARM11_REGCACHE_COUNT); - NEW(struct arm11_reg_state, arm11_reg_states, ARM11_REGCACHE_COUNT); + struct reg_cache *cache; + struct reg *reg_list; + struct arm11_reg_state *arm11_reg_states; + + cache = calloc(1, sizeof *cache); + reg_list = calloc(ARM11_REGCACHE_COUNT, sizeof *reg_list); + arm11_reg_states = calloc(ARM11_REGCACHE_COUNT, + sizeof *arm11_reg_states); + if (!cache || !reg_list || !arm11_reg_states) { + free(cache); + free(reg_list); + free(arm11_reg_states); + return ERROR_FAIL; + } arm11->reg_list = reg_list; @@ -1998,8 +1974,6 @@ static int arm11_mcr(struct target *target, int cpnum, static int arm11_register_commands(struct command_context *cmd_ctx) { - FNC_INFO; - struct command *top_cmd, *mw_cmd; armv4_5_register_commands(cmd_ctx); diff --git a/src/target/arm11.h b/src/target/arm11.h index 0b37929..3d7841d 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -25,27 +25,20 @@ #include "armv4_5.h" -#define NEW(type, variable, items) \ - type * variable = calloc(1, sizeof(type) * items) - /* TEMPORARY -- till we switch to the shared infrastructure */ #define ARM11_REGCACHE_COUNT 20 #define ARM11_TAP_DEFAULT TAP_INVALID - -#define CHECK_RETVAL(action) \ -do { \ - int __retval = (action); \ - \ - if (__retval != ERROR_OK) \ - { \ - LOG_DEBUG("error while calling \"" # action "\""); \ - return __retval; \ - } \ - \ -} while (0) - +#define CHECK_RETVAL(action) \ + do { \ + int __retval = (action); \ + if (__retval != ERROR_OK) { \ + LOG_DEBUG("error while calling \"%s\"", \ + # action ); \ + return __retval; \ + } \ + } while (0) struct arm11_register_history { ----------------------------------------------------------------------- Summary of changes: src/target/arm11.c | 121 ++++++++++++++++++--------------------------- src/target/arm11.h | 31 +++-------- src/target/arm11_dbgtap.c | 10 +++- src/target/arm11_dbgtap.h | 6 -- 4 files changed, 64 insertions(+), 104 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 20:25:03
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via af7f6891e98d538eabcf137d89f28bf3406a4999 (commit) from 2d6829d6982fa485b8cabb3a91e41b9c50c7f3d1 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit af7f6891e98d538eabcf137d89f28bf3406a4999 Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 20:23:34 2009 +0100 mips: remove dynamic arrays - reduces stack usage Allocate working memory dynamically. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 3177e0f..40627e1 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -440,7 +440,7 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co }; // /* TODO remove array */ - uint32_t param_out[count]; + uint32_t *param_out = malloc(count * sizeof(uint32_t)); int i; // int retval; @@ -472,6 +472,8 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co buf[i] = param_out[i]; } + free(param_out); + return ERROR_OK; } @@ -519,7 +521,7 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou }; // /* TODO remove array */ - uint32_t param_out[count]; + uint32_t *param_out = malloc(count * sizeof(uint32_t)); int i; // int retval; @@ -551,6 +553,8 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou buf[i] = param_out[i]; } + free(param_out); + return ERROR_OK; } @@ -609,7 +613,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c }; /* TODO remove array */ - uint32_t param_in[count + 2]; + uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t)); param_in[0] = addr; param_in[1] = addr + count * sizeof(uint32_t); //last address @@ -618,6 +622,8 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1); + free(param_in); + return ERROR_OK; } @@ -698,7 +704,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c }; /* TODO remove array */ - uint32_t param_in[count + 2]; + uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t)); int i; param_in[0] = addr; param_in[1] = count; @@ -711,6 +717,8 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1); + free(param_in); + return ERROR_OK; } @@ -758,7 +766,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co }; /* TODO remove array */ - uint32_t param_in[count + 2]; + uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t)); int retval; int i; param_in[0] = addr; @@ -772,6 +780,8 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \ sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1); + free(param_in); + return retval; } ----------------------------------------------------------------------- Summary of changes: src/target/mips32_pracc.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 20:19:29
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 2d6829d6982fa485b8cabb3a91e41b9c50c7f3d1 (commit) from 5985dee35da3ea24f1c9cb30b6cd50aa1bc63660 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2d6829d6982fa485b8cabb3a91e41b9c50c7f3d1 Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 20:18:26 2009 +0100 mips: use const for code sequences This will allow data to be allocated in read only memory instead of on the stack. Speeds things up and reduces stack usage. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index abc4a6f..3177e0f 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -83,7 +83,7 @@ struct mips32_pracc_context int num_iparam; uint32_t *local_oparam; int num_oparam; - uint32_t *code; + const uint32_t *code; int code_len; uint32_t stack[32]; int stack_offset; @@ -208,7 +208,7 @@ static int mips32_pracc_exec_write(struct mips32_pracc_context *ctx, uint32_t ad return ERROR_OK; } -int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, uint32_t *code, int num_param_in, uint32_t *param_in, int num_param_out, uint32_t *param_out, int cycle) +int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, const uint32_t *code, int num_param_in, uint32_t *param_in, int num_param_out, uint32_t *param_out, int cycle) { uint32_t ejtag_ctrl; uint32_t address, data; @@ -290,7 +290,7 @@ int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint32_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -364,7 +364,7 @@ int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int co int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -398,7 +398,7 @@ int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint16_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -477,7 +477,7 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint8_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -576,7 +576,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c { //NC: use destination pointer as loop counter (last address is in $10) - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -623,7 +623,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -656,7 +656,7 @@ int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint16_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -716,7 +716,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint8_t *buf) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(15,31,0), /* move $15 to COP0 DeSave */ MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)), /* $15 = MIPS32_PRACC_STACK */ @@ -777,7 +777,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_LUI(2,UPPER16(MIPS32_PRACC_PARAM_IN)), /* $2 = MIPS32_PRACC_PARAM_IN */ MIPS32_ORI(2,2,LOWER16(MIPS32_PRACC_PARAM_IN)), @@ -849,7 +849,7 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs) int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs) { - uint32_t code[] = { + static const uint32_t code[] = { /* start: */ MIPS32_MTC0(2,31,0), /* move $2 to COP0 DeSave */ MIPS32_LUI(2,UPPER16(MIPS32_PRACC_PARAM_OUT)), /* $2 = MIPS32_PRACC_PARAM_OUT */ diff --git a/src/target/mips32_pracc.h b/src/target/mips32_pracc.h index 3b124c7..5d1cf3d 100644 --- a/src/target/mips32_pracc.h +++ b/src/target/mips32_pracc.h @@ -63,7 +63,7 @@ int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs); int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs); -int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, uint32_t *code, +int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, const uint32_t *code, int num_param_in, uint32_t *param_in, int num_param_out, uint32_t *param_out, int cycle); ----------------------------------------------------------------------- Summary of changes: src/target/mips32_pracc.c | 24 ++++++++++++------------ src/target/mips32_pracc.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 20:01:34
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 5985dee35da3ea24f1c9cb30b6cd50aa1bc63660 (commit) from bcebce3ce25465589d379c809a12e2beda8430b9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5985dee35da3ea24f1c9cb30b6cd50aa1bc63660 Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 19:57:57 2009 +0100 arm11: do not use dynamic arrays Allocate working memory dynamically, caught by checkstack.pl Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/TODO b/TODO index c7e341d..bdbb0ec 100644 --- a/TODO +++ b/TODO @@ -309,7 +309,8 @@ fairly easy to complete: - use dynamic allocations for working memory. Scan & fix code for excessive stack allocations. take linux/scripts/checkstack.pl and -see what the worst offenders are. Example, on amd64: +see what the worst offenders are. Dynamic stack allocations are found +at the bottom of the list below. Example, on amd64: $ objdump -d | checkstack.pl | head -10 0x004311e3 image_open [openocd]: 13464 diff --git a/src/target/arm11_dbgtap.c b/src/target/arm11_dbgtap.c index 0f7e495..26de4ce 100644 --- a/src/target/arm11_dbgtap.c +++ b/src/target/arm11_dbgtap.c @@ -880,10 +880,11 @@ int arm11_sc7_run(struct arm11_common * arm11, struct arm11_sc7_action * actions */ void arm11_sc7_clear_vbw(struct arm11_common * arm11) { - struct arm11_sc7_action clear_bw[arm11->brp + arm11->wrp + 1]; + size_t clear_bw_size = arm11->brp + arm11->wrp + 1; + struct arm11_sc7_action *clear_bw = malloc(sizeof(struct arm11_sc7_action) * clear_bw_size); struct arm11_sc7_action * pos = clear_bw; - for (size_t i = 0; i < ARRAY_SIZE(clear_bw); i++) + for (size_t i = 0; i < clear_bw_size; i++) { clear_bw[i].write = true; clear_bw[i].value = 0; @@ -899,7 +900,9 @@ void arm11_sc7_clear_vbw(struct arm11_common * arm11) (pos++)->address = ARM11_SC7_VCR; - arm11_sc7_run(arm11, clear_bw, ARRAY_SIZE(clear_bw)); + arm11_sc7_run(arm11, clear_bw, clear_bw_size); + + free (clear_bw); } /** Write VCR register ----------------------------------------------------------------------- Summary of changes: TODO | 3 ++- src/target/arm11_dbgtap.c | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 19:54:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via bcebce3ce25465589d379c809a12e2beda8430b9 (commit) from dc22fd899eb8081c46566566cfe23d11e13a7b63 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit bcebce3ce25465589d379c809a12e2beda8430b9 Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 19:52:37 2009 +0100 arm926ejs: fix warnings buf_set_u32() operated on an uninitialized stack variable with non-byte boundaries, which led to warnings about reading uninitialized stack. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index a9d454b..56d86cc 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -56,7 +56,7 @@ static int arm926ejs_cp15_read(struct target *target, uint32_t op1, uint32_t op2 struct arm_jtag *jtag_info = &arm7_9->jtag_info; uint32_t address = ARM926EJS_CP15_ADDR(op1, op2, CRn, CRm); struct scan_field fields[4]; - uint8_t address_buf[2]; + uint8_t address_buf[2] = {0, 0}; uint8_t nr_w_buf = 0; uint8_t access = 1; @@ -149,7 +149,7 @@ static int arm926ejs_cp15_write(struct target *target, uint32_t op1, uint32_t op uint32_t address = ARM926EJS_CP15_ADDR(op1, op2, CRn, CRm); struct scan_field fields[4]; uint8_t value_buf[4]; - uint8_t address_buf[2]; + uint8_t address_buf[2] = {0, 0}; uint8_t nr_w_buf = 1; uint8_t access = 1; ----------------------------------------------------------------------- Summary of changes: src/target/arm926ejs.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: David B. <dbr...@us...> - 2009-11-22 19:29:02
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via dc22fd899eb8081c46566566cfe23d11e13a7b63 (commit) via b404b9ab57f17d84eb8dbfb42e6ac49c32913eee (commit) via fa618cc74deea6741c745b4f80dace2421209a1e (commit) via 1c619a2f12cbfe1887824d41e68e85a1c4f5a8b3 (commit) via ab5ac33fd462c37e4cf5a6bc1fe5fd0631e44469 (commit) from 5416c525d4e232161572fbbd1b200a7f3a7c2819 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit dc22fd899eb8081c46566566cfe23d11e13a7b63 Author: David Brownell <dbr...@us...> Date: Sun Nov 22 10:28:19 2009 -0800 TODO: ref 'checkstack.pl' not 'checkpatch.pl' Signed-off-by: David Brownell <dbr...@us...> diff --git a/TODO b/TODO index 2b7fad9..c7e341d 100644 --- a/TODO +++ b/TODO @@ -308,10 +308,10 @@ fairly easy to complete: - use dynamic allocations for working memory. Scan & fix code -for excessive stack allocations. take linux/scripts/checkpatch.pl and +for excessive stack allocations. take linux/scripts/checkstack.pl and see what the worst offenders are. Example, on amd64: - $ objdump -d | checkpatch.pl | head -10 + $ objdump -d | checkstack.pl | head -10 0x004311e3 image_open [openocd]: 13464 0x00431301 image_open [openocd]: 13464 0x004237a4 target_array2mem [openocd]: 4376 commit b404b9ab57f17d84eb8dbfb42e6ac49c32913eee Author: David Brownell <dbr...@us...> Date: Sun Nov 22 10:21:48 2009 -0800 ARM: use arm_reg_current() Start using the arm_reg_current() call. This shrinks and speeds the affected code. It can also prevent some coredumps coming from invalid CPSR values ... the ARMV4_5_CORE_REG_MODE() macro returns bogus registers if e.g. "Secure Monitor" mode isn't supported by the current CPU. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index a58bd3b..4c5e286 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -1245,9 +1245,11 @@ int arm7_9_soft_reset_halt(struct target *target) /* reset registers */ for (i = 0; i <= 14; i++) { - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).value, 0, 32, 0xffffffff); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).dirty = 1; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).valid = 1; + struct reg *r = arm_reg_current(armv4_5, i); + + buf_set_u32(r->value, 0, 32, 0xffffffff); + r->dirty = 1; + r->valid = 1; } if ((retval = target_call_event_callbacks(target, TARGET_EVENT_HALTED)) != ERROR_OK) @@ -1443,32 +1445,31 @@ static int arm7_9_debug_entry(struct target *target) for (i = 0; i <= 15; i++) { + struct reg *r = arm_reg_current(armv4_5, i); + LOG_DEBUG("r%i: 0x%8.8" PRIx32 "", i, context[i]); - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).value, 0, 32, context[i]); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).dirty = 0; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).valid = 1; + + buf_set_u32(r->value, 0, 32, context[i]); + /* r0 and r15 (pc) have to be restored later */ + r->dirty = (i == 0) || (i == 15); + r->valid = 1; } LOG_DEBUG("entered debug state at PC 0x%" PRIx32 "", context[15]); /* exceptions other than USR & SYS have a saved program status register */ - if ((armv4_5->core_mode != ARMV4_5_MODE_USR) && (armv4_5->core_mode != ARMV4_5_MODE_SYS)) - { + if (armv4_5->spsr) { uint32_t spsr; arm7_9->read_xpsr(target, &spsr, 1); if ((retval = jtag_execute_queue()) != ERROR_OK) { return retval; } - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 16).value, 0, 32, spsr); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 16).dirty = 0; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 16).valid = 1; + buf_set_u32(armv4_5->spsr->value, 0, 32, spsr); + armv4_5->spsr->dirty = 0; + armv4_5->spsr->valid = 1; } - /* r0 and r15 (pc) have to be restored later */ - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 15).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 15).valid; - if ((retval = jtag_execute_queue()) != ERROR_OK) return retval; @@ -2377,8 +2378,11 @@ int arm7_9_read_memory(struct target *target, uint32_t address, uint32_t size, u if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - for (i = 0; i <= last_reg; i++) - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).valid; + for (i = 0; i <= last_reg; i++) { + struct reg *r = arm_reg_current(armv4_5, i); + + r->dirty = r->valid; + } arm7_9->read_xpsr(target, &cpsr, 0); if ((retval = jtag_execute_queue()) != ERROR_OK) @@ -2562,8 +2566,11 @@ int arm7_9_write_memory(struct target *target, uint32_t address, uint32_t size, if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - for (i = 0; i <= last_reg; i++) - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, i).valid; + for (i = 0; i <= last_reg; i++) { + struct reg *r = arm_reg_current(armv4_5, i); + + r->dirty = r->valid; + } arm7_9->read_xpsr(target, &cpsr, 0); if ((retval = jtag_execute_queue()) != ERROR_OK) diff --git a/src/target/arm920t.c b/src/target/arm920t.c index a1fb7f3..0610c93 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -216,6 +216,7 @@ static int arm920t_read_cp15_interpreted(struct target *target, uint32_t* regs_p[1]; uint32_t regs[2]; uint32_t cp15c15 = 0x0; + struct reg *r = armv4_5->core_cache->reg_list; /* load address into R1 */ regs[1] = address; @@ -247,8 +248,8 @@ static int arm920t_read_cp15_interpreted(struct target *target, if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = 1; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = 1; + r[0].dirty = 1; + r[1].dirty = 1; return ERROR_OK; } @@ -260,6 +261,7 @@ int arm920t_write_cp15_interpreted(struct target *target, uint32_t cp15c15 = 0x0; struct arm *armv4_5 = target_to_armv4_5(target); uint32_t regs[2]; + struct reg *r = armv4_5->core_cache->reg_list; /* load value, address into R0, R1 */ regs[0] = value; @@ -287,8 +289,8 @@ int arm920t_write_cp15_interpreted(struct target *target, if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = 1; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = 1; + r[0].dirty = 1; + r[1].dirty = 1; return ERROR_OK; } @@ -678,6 +680,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) FILE *output; struct arm920t_cache_line d_cache[8][64], i_cache[8][64]; int segment, index; + struct reg *r; retval = arm920t_verify_pointer(CMD_CTX, arm920t); if (retval != ERROR_OK) @@ -893,17 +896,22 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - /* mark registers dirty. */ - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).valid; + /* force writeback of the valid data */ + r = armv4_5->core_cache->reg_list; + r[0].dirty = r[0].valid; + r[1].dirty = r[1].valid; + r[2].dirty = r[2].valid; + r[3].dirty = r[3].valid; + r[4].dirty = r[4].valid; + r[5].dirty = r[5].valid; + r[6].dirty = r[6].valid; + r[7].dirty = r[7].valid; + + r = arm_reg_current(armv4_5, 8); + r->dirty = r->valid; + + r = arm_reg_current(armv4_5, 9); + r->dirty = r->valid; return ERROR_OK; } @@ -924,6 +932,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) uint32_t Dlockdown, Ilockdown; struct arm920t_tlb_entry d_tlb[64], i_tlb[64]; int victim; + struct reg *r; retval = arm920t_verify_pointer(CMD_CTX, arm920t); if (retval != ERROR_OK) @@ -1176,17 +1185,22 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; - /* mark registers dirty */ - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).valid; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).valid; + /* force writeback of the valid data */ + r = armv4_5->core_cache->reg_list; + r[0].dirty = r[0].valid; + r[1].dirty = r[1].valid; + r[2].dirty = r[2].valid; + r[3].dirty = r[3].valid; + r[4].dirty = r[4].valid; + r[5].dirty = r[5].valid; + r[6].dirty = r[6].valid; + r[7].dirty = r[7].valid; + + r = arm_reg_current(armv4_5, 8); + r->dirty = r->valid; + + r = arm_reg_current(armv4_5, 9); + r->dirty = r->valid; return ERROR_OK; } diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index de579fe..b006e81 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -496,8 +496,7 @@ static int cortex_a8_resume(struct target *target, int current, /* current = 1: continue on current pc, otherwise continue at <address> */ resume_pc = buf_get_u32( - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).value, + armv4_5->core_cache->reg_list[15].value, 0, 32); if (!current) resume_pc = address; @@ -522,13 +521,10 @@ static int cortex_a8_resume(struct target *target, int current, return ERROR_FAIL; } LOG_DEBUG("resume pc = 0x%08" PRIx32, resume_pc); - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).value, + buf_set_u32(armv4_5->core_cache->reg_list[15].value, 0, 32, resume_pc); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).dirty = 1; - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 15).valid = 1; + armv4_5->core_cache->reg_list[15].dirty = 1; + armv4_5->core_cache->reg_list[15].valid = 1; cortex_a8_restore_context(target); @@ -653,8 +649,7 @@ static int cortex_a8_debug_entry(struct target *target) /* update cache */ for (i = 0; i <= ARM_PC; i++) { - reg = &ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, i); + reg = arm_reg_current(armv4_5, i); buf_set_u32(reg->value, 0, 32, regfile[i]); reg->valid = 1; @@ -672,13 +667,10 @@ static int cortex_a8_debug_entry(struct target *target) // ARM state regfile[ARM_PC] -= 8; } - buf_set_u32(ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, ARM_PC).value, - 0, 32, regfile[ARM_PC]); - ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0) - .dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, - armv4_5->core_mode, 0).valid; + reg = armv4_5->core_cache->reg_list + 15; + buf_set_u32(reg->value, 0, 32, regfile[ARM_PC]); + reg->dirty = reg->valid; ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 15) .dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 15).valid; commit fa618cc74deea6741c745b4f80dace2421209a1e Author: David Brownell <dbr...@us...> Date: Sun Nov 22 10:21:22 2009 -0800 ARM11: remove needless string format #ifdeffery We don't need to use size_t in these places; so it's easy to be rid of the need for this #ifdef and its MS-derived portability problems. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm11.c b/src/target/arm11.c index 9c42705..1a7b4e0 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -448,15 +448,16 @@ static int arm11_leave_debug_state(struct arm11_common *arm11) /* restore R1 - R14 */ - for (size_t i = 1; i < 15; i++) + for (unsigned i = 1; i < 15; i++) { if (!arm11->reg_list[ARM11_RC_RX + i].dirty) continue; /* MRC p14,0,r?,c0,c5,0 */ - arm11_run_instr_data_to_core1(arm11, 0xee100e15 | (i << 12), R(RX + i)); + arm11_run_instr_data_to_core1(arm11, + 0xee100e15 | (i << 12), R(RX + i)); - // LOG_DEBUG("RESTORE R" ZU " %08x", i, R(RX + i)); + // LOG_DEBUG("RESTORE R%u %08x", i, R(RX + i)); } retval = arm11_run_instr_data_finish(arm11); @@ -742,7 +743,7 @@ static int arm11_resume(struct target *target, int current, /* set all breakpoints */ - size_t brp_num = 0; + unsigned brp_num = 0; for (bp = target->breakpoints; bp; bp = bp->next) { @@ -757,7 +758,8 @@ static int arm11_resume(struct target *target, int current, arm11_sc7_run(arm11, brp, ARRAY_SIZE(brp)); - LOG_DEBUG("Add BP " ZU " at %08" PRIx32 "", brp_num, bp->address); + LOG_DEBUG("Add BP %d at %08" PRIx32, brp_num, + bp->address); brp_num++; } @@ -1869,7 +1871,14 @@ static int arm11_build_reg_cache(struct target *target) ARM11_REGCACHE_COUNT != ARRAY_SIZE(arm11_reg_defs) || ARM11_REGCACHE_COUNT != ARM11_RC_MAX) { - LOG_ERROR("BUG: arm11->reg_values inconsistent (%d " ZU " " ZU " %d)", ARM11_REGCACHE_COUNT, ARRAY_SIZE(arm11->reg_values), ARRAY_SIZE(arm11_reg_defs), ARM11_RC_MAX); + LOG_ERROR("BUG: arm11->reg_values inconsistent (%d %u %u %d)", + ARM11_REGCACHE_COUNT, + (unsigned) ARRAY_SIZE(arm11->reg_values), + (unsigned) ARRAY_SIZE(arm11_reg_defs), + ARM11_RC_MAX); + /* FIXME minimally, use a build_bug_on(X) mechanism; + * runtime exit() here is bad! + */ exit(-1); } diff --git a/src/target/arm11.h b/src/target/arm11.h index 79f4b6b..0b37929 100644 --- a/src/target/arm11.h +++ b/src/target/arm11.h @@ -28,16 +28,6 @@ #define NEW(type, variable, items) \ type * variable = calloc(1, sizeof(type) * items) -/* For MinGW use 'I' prefix to print size_t (instead of 'z') */ -/* Except if __USE_MINGW_ANSI_STDIO is defined with MinGW */ - -#if (!defined(__MSVCRT__) || defined(__USE_MINGW_ANSI_STDIO)) -#define ZU "%zu" -#else -#define ZU "%Iu" -#endif - - /* TEMPORARY -- till we switch to the shared infrastructure */ #define ARM11_REGCACHE_COUNT 20 diff --git a/src/target/arm11_dbgtap.c b/src/target/arm11_dbgtap.c index bdbcc8f..0f7e495 100644 --- a/src/target/arm11_dbgtap.c +++ b/src/target/arm11_dbgtap.c @@ -588,12 +588,13 @@ int arm11_run_instr_data_to_core_noack(struct arm11_common * arm11, uint32_t opc arm11_setup_field(arm11, 1, NULL, NULL, chain5_fields + 2); uint8_t *Readies; - size_t readiesNum = (count + 1); - size_t bytes = sizeof(*Readies)*readiesNum; + unsigned readiesNum = count + 1; + unsigned bytes = sizeof(*Readies)*readiesNum; + Readies = (uint8_t *) malloc(bytes); if (Readies == NULL) { - LOG_ERROR("Out of memory allocating " ZU " bytes", bytes); + LOG_ERROR("Out of memory allocating %u bytes", bytes); return ERROR_FAIL; } @@ -626,7 +627,7 @@ int arm11_run_instr_data_to_core_noack(struct arm11_common * arm11, uint32_t opc int retval = jtag_execute_queue(); if (retval == ERROR_OK) { - size_t error_count = 0; + unsigned error_count = 0; for (size_t i = 0; i < readiesNum; i++) { @@ -637,7 +638,8 @@ int arm11_run_instr_data_to_core_noack(struct arm11_common * arm11, uint32_t opc } if (error_count > 0 ) - LOG_ERROR(ZU " words out of " ZU " not transferred", error_count, readiesNum); + LOG_ERROR("%u words out of %u not transferred", + error_count, readiesNum); } commit 1c619a2f12cbfe1887824d41e68e85a1c4f5a8b3 Author: David Brownell <dbr...@us...> Date: Sun Nov 22 10:20:14 2009 -0800 target: make register flags "bool" Mostly for clarity, but it also saves code and data space. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/register.h b/src/target/register.h index 0f8f2f4..0cd0ddf 100644 --- a/src/target/register.h +++ b/src/target/register.h @@ -29,8 +29,8 @@ struct reg { char *name; void *value; - int dirty; - int valid; + bool dirty; + bool valid; uint32_t size; void *arch_info; const struct reg_arch_type *type; commit ab5ac33fd462c37e4cf5a6bc1fe5fd0631e44469 Author: David Brownell <dbr...@us...> Date: Sun Nov 22 10:19:58 2009 -0800 ARM: remove 'armv4_5_common_s' migration #define Finish migrating from the old symbol to the new one. Signed-off-by: David Brownell <dbr...@us...> diff --git a/src/target/arm720t.c b/src/target/arm720t.c index 3aa77ea..f9388ab 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -225,7 +225,7 @@ static int arm720t_verify_pointer(struct command_context *cmd_ctx, static int arm720t_arch_state(struct target *target) { struct arm720t_common *arm720t = target_to_arm720(target); - struct armv4_5_common_s *armv4_5; + struct arm *armv4_5; static const char *state[] = { @@ -307,7 +307,7 @@ static int arm720t_soft_reset_halt(struct target *target) struct arm720t_common *arm720t = target_to_arm720(target); struct reg *dbg_stat = &arm720t->arm7_9_common .eice_cache->reg_list[EICE_DBG_STAT]; - struct armv4_5_common_s *armv4_5 = &arm720t->arm7_9_common + struct arm *armv4_5 = &arm720t->arm7_9_common .armv4_5_common; if ((retval = target_halt(target)) != ERROR_OK) diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 19fe98d..a58bd3b 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -1160,7 +1160,7 @@ int arm7_9_clear_halt(struct target *target) int arm7_9_soft_reset_halt(struct target *target) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL]; int i; @@ -1338,7 +1338,7 @@ static int arm7_9_debug_entry(struct target *target) uint32_t cpsr, cpsr_mask = 0; int retval; struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL]; @@ -1492,7 +1492,7 @@ int arm7_9_full_context(struct target *target) int i; int retval; struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; LOG_DEBUG("-"); @@ -1586,7 +1586,7 @@ int arm7_9_full_context(struct target *target) int arm7_9_restore_context(struct target *target) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *reg; struct arm_reg *reg_arch_info; enum armv4_5_mode current_mode = armv4_5->core_mode; @@ -1797,7 +1797,7 @@ void arm7_9_enable_breakpoints(struct target *target) int arm7_9_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct breakpoint *breakpoint = target->breakpoints; struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL]; int err, retval = ERROR_OK; @@ -1957,7 +1957,7 @@ int arm7_9_resume(struct target *target, int current, uint32_t address, int hand void arm7_9_enable_eice_step(struct target *target, uint32_t next_pc) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; uint32_t current_pc; current_pc = buf_get_u32(armv4_5->core_cache->reg_list[15].value, 0, 32); @@ -2009,7 +2009,7 @@ void arm7_9_disable_eice_step(struct target *target) int arm7_9_step(struct target *target, int current, uint32_t address, int handle_breakpoints) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct breakpoint *breakpoint = NULL; int err, retval; @@ -2107,7 +2107,7 @@ static int arm7_9_read_core_reg(struct target *target, struct reg *r, int retval; struct arm_reg *areg = r->arch_info; struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; @@ -2169,7 +2169,7 @@ static int arm7_9_write_core_reg(struct target *target, struct reg *r, uint32_t reg[16]; struct arm_reg *areg = r->arch_info; struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; if (!is_arm_mode(armv4_5->core_mode)) return ERROR_FAIL; @@ -2227,7 +2227,7 @@ static int arm7_9_write_core_reg(struct target *target, struct reg *r, int arm7_9_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; uint32_t reg[16]; uint32_t num_accesses = 0; int thisrun_accesses; @@ -2404,7 +2404,7 @@ int arm7_9_read_memory(struct target *target, uint32_t address, uint32_t size, u int arm7_9_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL]; uint32_t reg[16]; diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c index e7ea768..742eace 100644 --- a/src/target/arm7tdmi.c +++ b/src/target/arm7tdmi.c @@ -581,7 +581,7 @@ static void arm7tdmi_branch_resume(struct target *target) static void arm7tdmi_branch_resume_thumb(struct target *target) { struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct arm_jtag *jtag_info = &arm7_9->jtag_info; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; @@ -641,7 +641,7 @@ static void arm7tdmi_branch_resume_thumb(struct target *target) static void arm7tdmi_build_reg_cache(struct target *target) { struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); (*cache_p) = armv4_5_build_reg_cache(target, armv4_5); } diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 8a03554..a1fb7f3 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -212,7 +212,7 @@ static int arm920t_execute_cp15(struct target *target, uint32_t cp15_opcode, static int arm920t_read_cp15_interpreted(struct target *target, uint32_t cp15_opcode, uint32_t address, uint32_t *value) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); uint32_t* regs_p[1]; uint32_t regs[2]; uint32_t cp15c15 = 0x0; @@ -258,7 +258,7 @@ int arm920t_write_cp15_interpreted(struct target *target, uint32_t cp15_opcode, uint32_t value, uint32_t address) { uint32_t cp15c15 = 0x0; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); uint32_t regs[2]; /* load value, address into R0, R1 */ @@ -436,7 +436,7 @@ int arm920t_arch_state(struct target *target) }; struct arm920t_common *arm920t = target_to_arm920(target); - struct armv4_5_common_s *armv4_5; + struct arm *armv4_5; if (arm920t->common_magic != ARM920T_COMMON_MAGIC) { @@ -555,7 +555,7 @@ int arm920t_soft_reset_halt(struct target *target) int retval = ERROR_OK; struct arm920t_common *arm920t = target_to_arm920(target); struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; if ((retval = target_halt(target)) != ERROR_OK) @@ -668,7 +668,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; uint32_t cp15c15; uint32_t cp15_ctrl, cp15_ctrl_saved; uint32_t regs[16]; @@ -914,7 +914,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; uint32_t cp15c15; uint32_t cp15_ctrl, cp15_ctrl_saved; uint32_t regs[16]; diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index aa29989..a9d454b 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -494,7 +494,7 @@ int arm926ejs_arch_state(struct target *target) }; struct arm926ejs_common *arm926ejs = target_to_arm926(target); - struct armv4_5_common_s *armv4_5; + struct arm *armv4_5; if (arm926ejs->common_magic != ARM926EJS_COMMON_MAGIC) { @@ -524,7 +524,7 @@ int arm926ejs_soft_reset_halt(struct target *target) int retval = ERROR_OK; struct arm926ejs_common *arm926ejs = target_to_arm926(target); struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; if ((retval = target_halt(target)) != ERROR_OK) diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 38b2284..298b26a 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -664,7 +664,7 @@ static void arm9tdmi_branch_resume_thumb(struct target *target) LOG_DEBUG("-"); struct arm7_9_common *arm7_9 = target_to_arm7_9(target); - struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common; + struct arm *armv4_5 = &arm7_9->armv4_5_common; struct arm_jtag *jtag_info = &arm7_9->jtag_info; struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT]; @@ -751,7 +751,7 @@ void arm9tdmi_disable_single_step(struct target *target) static void arm9tdmi_build_reg_cache(struct target *target) { struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); (*cache_p) = armv4_5_build_reg_cache(target, armv4_5); } diff --git a/src/target/arm_simulator.c b/src/target/arm_simulator.c index 23cc556..73aac96 100644 --- a/src/target/arm_simulator.c +++ b/src/target/arm_simulator.c @@ -850,7 +850,7 @@ static enum armv4_5_mode armv4_5_get_mode(struct arm_sim_interface *sim) int arm_simulate_step(struct target *target, uint32_t *dry_run_pc) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); struct arm_sim_interface sim; sim.user_data = armv4_5; diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index 22e1186..461d206 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -487,7 +487,7 @@ static int armv4_5_set_core_reg(struct reg *reg, uint8_t *buf) { struct arm_reg *armv4_5 = reg->arch_info; struct target *target = armv4_5->target; - struct armv4_5_common_s *armv4_5_target = target_to_armv4_5(target); + struct arm *armv4_5_target = target_to_armv4_5(target); uint32_t value = buf_get_u32(buf, 0, 32); if (target->state != TARGET_HALTED) @@ -579,7 +579,7 @@ struct reg_cache* armv4_5_build_reg_cache(struct target *target, struct arm *arm int armv4_5_arch_state(struct target *target) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC) { @@ -603,7 +603,7 @@ int armv4_5_arch_state(struct target *target) COMMAND_HANDLER(handle_armv4_5_reg_command) { struct target *target = get_current_target(CMD_CTX); - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); unsigned num_regs; struct reg *regs; @@ -690,7 +690,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) COMMAND_HANDLER(handle_armv4_5_core_state_command) { struct target *target = get_current_target(CMD_CTX); - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); if (!is_arm(armv4_5)) { @@ -810,7 +810,7 @@ int armv4_5_register_commands(struct command_context *cmd_ctx) int armv4_5_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); int i; if (!is_arm_mode(armv4_5->core_mode)) @@ -835,7 +835,7 @@ int armv4_5_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int static int armv4_5_run_algorithm_completion(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info) { int retval; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); if ((retval = target_wait_state(target, TARGET_HALTED, timeout_ms)) != ERROR_OK) { @@ -866,7 +866,7 @@ static int armv4_5_run_algorithm_completion(struct target *target, uint32_t exit int armv4_5_run_algorithm_inner(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info, int (*run_it)(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info)) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); struct armv4_5_algorithm *armv4_5_algorithm_info = arch_info; enum armv4_5_state core_state = armv4_5->core_state; uint32_t context[17]; @@ -1217,7 +1217,7 @@ int arm_blank_check_memory(struct target *target, static int arm_full_context(struct target *target) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); unsigned num_regs = armv4_5->core_cache->num_regs; struct reg *reg = armv4_5->core_cache->reg_list; int retval = ERROR_OK; diff --git a/src/target/armv4_5.h b/src/target/armv4_5.h index a9599c8..4931455 100644 --- a/src/target/armv4_5.h +++ b/src/target/armv4_5.h @@ -67,9 +67,6 @@ enum { ARMV4_5_CPSR = 31, }; #define ARMV4_5_COMMON_MAGIC 0x0A450A45 -/* NOTE: this is being morphed into a generic toplevel holder for ARMs. */ -#define armv4_5_common_s arm - /** * Represents a generic ARM core, with standard application registers. * diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 63f95b8..1d13779 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -59,7 +59,7 @@ int armv7a_arch_state(struct target *target) }; struct armv7a_common *armv7a = target_to_armv7a(target); - struct armv4_5_common_s *armv4_5 = &armv7a->armv4_5_common; + struct arm *armv4_5 = &armv7a->armv4_5_common; if (armv7a->common_magic != ARMV7_COMMON_MAGIC) { diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c index fa26b6a..de579fe 100644 --- a/src/target/cortex_a8.c +++ b/src/target/cortex_a8.c @@ -457,7 +457,7 @@ static int cortex_a8_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) { struct armv7a_common *armv7a = target_to_armv7a(target); - struct armv4_5_common_s *armv4_5 = &armv7a->armv4_5 _common; + struct arm *armv4_5 = &armv7a->armv4_5_common; struct swjdp_common *swjdp = &armv7a->swjdp_info; // struct breakpoint *breakpoint = NULL; @@ -587,7 +587,7 @@ static int cortex_a8_debug_entry(struct target *target) struct working_area *regfile_working_area = NULL; struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target); struct armv7a_common *armv7a = target_to_armv7a(target); - struct armv4_5_common_s *armv4_5 = &armv7a->armv4_5_common; + struct arm *armv4_5 = &armv7a->armv4_5_common; struct swjdp_common *swjdp = &armv7a->swjdp_info; struct reg *reg; @@ -743,7 +743,7 @@ static int cortex_a8_step(struct target *target, int current, uint32_t address, int handle_breakpoints) { struct armv7a_common *armv7a = target_to_armv7a(target); - struct armv4_5_common_s *armv4_5 = &armv7a->armv4_5_common; + struct arm *armv4_5 = &armv7a->armv4_5_common; struct breakpoint *breakpoint = NULL; struct breakpoint stepbreakpoint; @@ -915,7 +915,7 @@ static int cortex_a8_load_core_reg_u32(struct target *target, int num, armv4_5_mode_t mode, uint32_t * value) { int retval; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); if ((num <= ARM_CPSR)) { @@ -953,7 +953,7 @@ static int cortex_a8_store_core_reg_u32(struct target *target, int num, { int retval; // uint32_t reg; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); #ifdef ARMV7_GDB_HACKS /* If the LR register is being modified, make sure it will put us @@ -998,7 +998,7 @@ static int cortex_a8_read_core_reg(struct target *target, struct reg *r, { uint32_t value; int retval; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); struct reg *cpsr_r = NULL; uint32_t cpsr = 0; unsigned cookie = num; @@ -1053,7 +1053,7 @@ static int cortex_a8_write_core_reg(struct target *target, struct reg *r, int num, enum armv4_5_mode mode, uint32_t value) { int retval; - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); struct reg *cpsr_r = NULL; uint32_t cpsr = 0; unsigned cookie = num; @@ -1584,7 +1584,7 @@ static int cortex_a8_examine(struct target *target) static void cortex_a8_build_reg_cache(struct target *target) { struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); armv4_5->core_type = ARM_MODE_MON; diff --git a/src/target/xscale.c b/src/target/xscale.c index e8a3e49..e471ac3 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -833,7 +833,7 @@ static int xscale_update_vectors(struct target *target) static int xscale_arch_state(struct target *target) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; static const char *state[] = { @@ -911,7 +911,7 @@ static int xscale_poll(struct target *target) static int xscale_debug_entry(struct target *target) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; uint32_t pc; uint32_t buffer[10]; int i; @@ -1179,7 +1179,7 @@ static int xscale_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; struct breakpoint *breakpoint = target->breakpoints; uint32_t current_pc; int retval; @@ -1335,7 +1335,7 @@ static int xscale_step_inner(struct target *target, int current, uint32_t address, int handle_breakpoints) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; uint32_t next_pc; int retval; int i; @@ -1416,7 +1416,7 @@ static int xscale_step_inner(struct target *target, int current, static int xscale_step(struct target *target, int current, uint32_t address, int handle_breakpoints) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); struct breakpoint *breakpoint = target->breakpoints; uint32_t current_pc; @@ -1661,7 +1661,7 @@ static int xscale_write_core_reg(struct target *target, struct reg *r, static int xscale_full_context(struct target *target) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); uint32_t *buffer; @@ -1737,7 +1737,7 @@ static int xscale_full_context(struct target *target) static int xscale_restore_context(struct target *target) { - struct armv4_5_common_s *armv4_5 = target_to_armv4_5(target); + struct arm *armv4_5 = target_to_armv4_5(target); int i, j; @@ -2470,7 +2470,7 @@ static int xscale_write_dcsr_sw(struct target *target, uint32_t value) static int xscale_read_trace(struct target *target) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; struct xscale_trace_data **trace_data_p; /* 258 words from debug handler @@ -2821,7 +2821,7 @@ static const struct reg_arch_type xscale_reg_type = { static void xscale_build_reg_cache(struct target *target) { struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); struct xscale_reg *arch_info = malloc(sizeof(xscale_reg_arch_info)); int i; @@ -3271,7 +3271,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) { struct target *target = get_current_target(CMD_CTX); struct xscale_common *xscale = target_to_xscale(target); - struct armv4_5_common_s *armv4_5 = &xscale->armv4_5_common; + struct arm *armv4_5 = &xscale->armv4_5_common; uint32_t dcsr_value; int retval; ----------------------------------------------------------------------- Summary of changes: TODO | 4 +- src/target/arm11.c | 21 ++++++++--- src/target/arm11.h | 10 ------ src/target/arm11_dbgtap.c | 12 ++++--- src/target/arm720t.c | 4 +- src/target/arm7_9_common.c | 67 +++++++++++++++++++++----------------- src/target/arm7tdmi.c | 4 +- src/target/arm920t.c | 78 ++++++++++++++++++++++++++------------------ src/target/arm926ejs.c | 4 +- src/target/arm9tdmi.c | 4 +- src/target/arm_simulator.c | 2 +- src/target/armv4_5.c | 16 ++++---- src/target/armv4_5.h | 3 -- src/target/armv7a.c | 2 +- src/target/cortex_a8.c | 40 +++++++++------------- src/target/register.h | 4 +- src/target/xscale.c | 20 ++++++------ 17 files changed, 153 insertions(+), 142 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 19:15:30
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 5416c525d4e232161572fbbd1b200a7f3a7c2819 (commit) via aacc5b583c6415fe8d3e6fc99066d6ef819fa22c (commit) from 7daec5a0ce109c04b117d42374a99b849fd8a89a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5416c525d4e232161572fbbd1b200a7f3a7c2819 Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 19:06:44 2009 +0100 flash: dynamically allocate working storage Allocate working memory rather than using stack. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/flash/flash.c b/src/flash/flash.c index ef6c6da..e2136b7 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -728,24 +728,40 @@ COMMAND_HANDLER(handle_flash_fill_command) uint32_t address; uint32_t pattern; uint32_t count; - uint8_t chunk[1024]; - uint8_t readback[1024]; uint32_t wrote = 0; uint32_t cur_size = 0; uint32_t chunk_count; struct target *target = get_current_target(CMD_CTX); uint32_t i; uint32_t wordsize; + int retval = ERROR_OK; + + static size_t const chunksize = 1024; + uint8_t *chunk = malloc(chunksize); + if (chunk == NULL) + return ERROR_FAIL; + + uint8_t *readback = malloc(chunksize); + if (readback == NULL) + { + free(chunk); + return ERROR_FAIL; + } + if (CMD_ARGC != 3) - return ERROR_COMMAND_SYNTAX_ERROR; + { + retval = ERROR_COMMAND_SYNTAX_ERROR; + goto done; + } + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pattern); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count); if (count == 0) - return ERROR_OK; + goto done; switch (CMD_NAME[4]) { @@ -759,10 +775,11 @@ COMMAND_HANDLER(handle_flash_fill_command) wordsize = 1; break; default: - return ERROR_COMMAND_SYNTAX_ERROR; + retval = ERROR_COMMAND_SYNTAX_ERROR; + goto done; } - chunk_count = MIN(count, (1024 / wordsize)); + chunk_count = MIN(count, (chunksize / wordsize)); switch (wordsize) { case 4: @@ -795,15 +812,22 @@ COMMAND_HANDLER(handle_flash_fill_command) bank = get_flash_bank_by_addr(target, address); if (bank == NULL) { - return ERROR_FAIL; + retval = ERROR_FAIL; + goto done; } err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size); if (err != ERROR_OK) - return err; + { + retval = err; + goto done; + } err = target_read_buffer(target, address + wrote, cur_size, readback); if (err != ERROR_OK) - return err; + { + retval = err; + goto done; + } unsigned i; for (i = 0; i < cur_size; i++) @@ -812,7 +836,8 @@ COMMAND_HANDLER(handle_flash_fill_command) { LOG_ERROR("Verfication error address 0x%08" PRIx32 ", read back 0x%02x, expected 0x%02x", address + wrote + i, readback[i], chunk[i]); - return ERROR_FAIL; + retval = ERROR_FAIL; + goto done; } } } @@ -823,7 +848,12 @@ COMMAND_HANDLER(handle_flash_fill_command) " in %fs (%0.3f kb/s)", wrote, address, duration_elapsed(&bench), duration_kbps(&bench, wrote)); } - return ERROR_OK; + + done: + free(readback); + free(chunk); + + return retval; } COMMAND_HANDLER(handle_flash_write_bank_command) @@ -1152,10 +1182,10 @@ int flash_write(struct target *target, struct image *image, uint32_t *written, i int default_flash_mem_blank_check(struct flash_bank *bank) { struct target *target = bank->target; - uint8_t buffer[1024]; - int buffer_size = sizeof(buffer); + const int buffer_size = 1024; int i; uint32_t nBytes; + int retval = ERROR_OK; if (bank->target->state != TARGET_HALTED) { @@ -1163,6 +1193,8 @@ int default_flash_mem_blank_check(struct flash_bank *bank) return ERROR_TARGET_NOT_HALTED; } + uint8_t *buffer = malloc(buffer_size); + for (i = 0; i < bank->num_sectors; i++) { uint32_t j; @@ -1171,7 +1203,6 @@ int default_flash_mem_blank_check(struct flash_bank *bank) for (j = 0; j < bank->sectors[i].size; j += buffer_size) { uint32_t chunk; - int retval; chunk = buffer_size; if (chunk > (j - bank->sectors[i].size)) { @@ -1180,7 +1211,9 @@ int default_flash_mem_blank_check(struct flash_bank *bank) retval = target_read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer); if (retval != ERROR_OK) - return retval; + { + goto done; + } for (nBytes = 0; nBytes < chunk; nBytes++) { @@ -1193,7 +1226,10 @@ int default_flash_mem_blank_check(struct flash_bank *bank) } } - return ERROR_OK; + done: + free(buffer); + + return retval; } int default_flash_blank_check(struct flash_bank *bank) commit aacc5b583c6415fe8d3e6fc99066d6ef819fa22c Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 18:58:42 2009 +0100 target: reduce stack usage 4096 byte buffer allocated dynamically. Better for embedded OS's. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/target.c b/src/target/target.c index 70fd8f2..55adcce 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3145,7 +3145,6 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, uint32_t count; uint32_t v; const char *varname; - uint8_t buffer[4096]; int n, e, retval; uint32_t i; @@ -3227,14 +3226,20 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, /* index counter */ n = 0; + + size_t buffersize = 4096; + uint8_t *buffer = malloc(buffersize); + if (buffer == NULL) + return JIM_ERR; + /* assume ok */ e = JIM_OK; while (len) { /* Slurp... in buffer size chunks */ count = len; /* in objects.. */ - if (count > (sizeof(buffer)/width)) { - count = (sizeof(buffer)/width); + if (count > (buffersize/width)) { + count = (buffersize/width); } retval = target_read_memory(target, addr, width, count, buffer); @@ -3268,6 +3273,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, } } + free(buffer); + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); return JIM_OK; @@ -3331,7 +3338,6 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, uint32_t count; uint32_t v; const char *varname; - uint8_t buffer[4096]; int n, e, retval; uint32_t i; @@ -3415,12 +3421,18 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, n = 0; /* assume ok */ e = JIM_OK; + + size_t buffersize = 4096; + uint8_t *buffer = malloc(buffersize); + if (buffer == NULL) + return JIM_ERR; + while (len) { /* Slurp... in buffer size chunks */ count = len; /* in objects.. */ - if (count > (sizeof(buffer)/width)) { - count = (sizeof(buffer)/width); + if (count > (buffersize/width)) { + count = (buffersize/width); } v = 0; /* shut up gcc */ @@ -3454,6 +3466,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, } } + free(buffer); + Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); return JIM_OK; ----------------------------------------------------------------------- Summary of changes: src/flash/flash.c | 68 +++++++++++++++++++++++++++++++++++++++------------ src/target/target.c | 26 +++++++++++++++---- 2 files changed, 72 insertions(+), 22 deletions(-) hooks/post-receive -- Main OpenOCD repository |
From: Øyvind H. <go...@us...> - 2009-11-22 18:51:49
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 7daec5a0ce109c04b117d42374a99b849fd8a89a (commit) from 5c4a73d0d89989b7fbe260ed4fa00a8259e01b03 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7daec5a0ce109c04b117d42374a99b849fd8a89a Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 18:50:57 2009 +0100 todo: add tip on how to identify excessive stack usage Use dynamic allocations for working memory rather than stack. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/TODO b/TODO index 8713e81..2b7fad9 100644 --- a/TODO +++ b/TODO @@ -306,6 +306,22 @@ These ideas were first introduced here: @par The following architectural tasks need to be accomplished and should be fairly easy to complete: + +- use dynamic allocations for working memory. Scan & fix code +for excessive stack allocations. take linux/scripts/checkpatch.pl and +see what the worst offenders are. Example, on amd64: + + $ objdump -d | checkpatch.pl | head -10 + 0x004311e3 image_open [openocd]: 13464 + 0x00431301 image_open [openocd]: 13464 + 0x004237a4 target_array2mem [openocd]: 4376 + 0x0042382b target_array2mem [openocd]: 4376 + 0x00423e74 target_mem2array [openocd]: 4360 + 0x00423ef9 target_mem2array [openocd]: 4360 + 0x00404aed handle_svf_command [openocd]: 2248 + 0x00404b7e handle_svf_command [openocd]: 2248 + 0x00413581 handle_flash_fill_command [openocd]: 2200 + 0x004135fa handle_flash_fill_command [openocd]: 2200 - clean-up code to match style guides - factor code to eliminate duplicated functionality - rewrite code that uses casts to access 16-bit and larger types ----------------------------------------------------------------------- Summary of changes: TODO | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) hooks/post-receive -- Main OpenOCD repository |