target: Remove last accesses to private structure from outside.

Only include target_internal.h from inside target files.
This commit is contained in:
Gareth McMullin 2016-06-30 14:18:05 +12:00
parent 1cd03b3fa4
commit 5c5f76d60e
23 changed files with 68 additions and 70 deletions

View File

@ -26,9 +26,8 @@
#include "exception.h"
#include "adiv5.h"
#include "swdptap.h"
#include "command.h"
#include "morse.h"
#include "gdb_packet.h"
#include "target.h"
#include "target_internal.h"
#define SWDP_ACK_OK 0x01
#define SWDP_ACK_WAIT 0x02
@ -58,7 +57,6 @@ int adiv5_swdp_scan(void)
ack = swdptap_seq_in(3);
if((ack != SWDP_ACK_OK) || swdptap_seq_in_parity(&dp->idcode, 32)) {
DEBUG("\n");
morse("NO TARGETS.", 1);
free(dp);
return -1;
}
@ -71,9 +69,6 @@ int adiv5_swdp_scan(void)
adiv5_swdp_error(dp);
adiv5_dp_init(dp);
if(!target_list) morse("NO TARGETS.", 1);
else morse(NULL, 0);
return target_list?1:0;
}

View File

@ -34,6 +34,15 @@
# include "traceswo.h"
#endif
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
struct command_s {
const char *cmd;
cmd_handler handler;
const char *help;
};
static bool cmd_version(void);
static bool cmd_help(target *t);
@ -81,7 +90,6 @@ bool debug_bmp;
int command_process(target *t, char *cmd)
{
struct target_command_s *tc;
const struct command_s *c;
int argc = 0;
const char **argv;
@ -101,19 +109,14 @@ int command_process(target *t, char *cmd)
/* Accept a partial match as GDB does.
* So 'mon ver' will match 'monitor version'
*/
if(!strncmp(argv[0], c->cmd, strlen(argv[0])))
if ((argc == 0) || !strncmp(argv[0], c->cmd, strlen(argv[0])))
return !c->handler(t, argc, argv);
}
if (!t)
return -1;
for (tc = t->commands; tc; tc = tc->next)
for(c = tc->cmds; c->cmd; c++)
if(!strncmp(argv[0], c->cmd, strlen(argv[0])))
return !c->handler(t, argc, argv);
return -1;
return target_command(t, argc, argv);
}
bool cmd_version(void)
@ -128,7 +131,6 @@ bool cmd_version(void)
bool cmd_help(target *t)
{
struct target_command_s *tc;
const struct command_s *c;
gdb_out("General commands:\n");
@ -138,11 +140,7 @@ bool cmd_help(target *t)
if (!t)
return -1;
for (tc = t->commands; tc; tc = tc->next) {
gdb_outf("%s specific commands:\n", tc->specific_name);
for(c = tc->cmds; c->cmd; c++)
gdb_outf("\t%s -- %s\n", c->cmd, c->help);
}
target_command_help(t);
return true;
}

View File

@ -29,14 +29,10 @@
*/
#include "general.h"
#include "exception.h"
#include "jtagtap.h"
#include "jtag_scan.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"
#include "morse.h"
#include <unistd.h>
@ -606,7 +602,6 @@ static int cortexa_halt_wait(target *t)
case EXCEPTION_ERROR:
/* Oh crap, there's no recovery from this... */
target_list_free();
morse("TARGET LOST.", 1);
return SIGLOST;
case EXCEPTION_TIMEOUT:
/* Timeout isn't a problem, target could be in WFI */

View File

@ -29,10 +29,9 @@
#include "exception.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"
#include "morse.h"
#include <unistd.h>
@ -507,7 +506,6 @@ static int cortexm_halt_wait(target *t)
case EXCEPTION_ERROR:
/* Oh crap, there's no recovery from this... */
target_list_free();
morse("TARGET LOST.", 1);
return SIGLOST;
case EXCEPTION_TIMEOUT:
/* Timeout isn't a problem, target could be in WFI */

View File

@ -37,10 +37,8 @@
*/
#include "general.h"
#include "jtagtap.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"

View File

@ -24,14 +24,6 @@
#include "target.h"
int command_process(target *t, char *cmd);
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
struct command_s {
const char *cmd;
cmd_handler handler;
const char *help;
};
#endif

View File

@ -87,13 +87,9 @@ const char *target_tdesc(target *t);
const char *target_mem_map(target *t);
const char *target_driver_name(target *t);
struct target_command_s {
const char *specific_name;
const struct command_s *cmds;
struct target_command_s *next;
};
#include "target_internal.h"
/* Command interpreter */
void target_command_help(target *t);
int target_command(target *t, int argc, const char *argv[]);
#endif

View File

@ -25,9 +25,7 @@
#include "general.h"
#include "jtagtap.h"
#include "morse.h"
#include "jtag_scan.h"
#include "gdb_packet.h"
#include "target.h"
#include "adiv5.h"
@ -187,7 +185,6 @@ int jtag_scan(const uint8_t *irlens)
jtagtap_next(1, 1);
jtagtap_return_idle();
if(!jtag_dev_count) {
morse("NO TARGETS.", 1);
return 0;
}
@ -224,9 +221,6 @@ int jtag_scan(const uint8_t *irlens)
break;
}
if(!target_list) morse("NO TARGETS.", 1);
else morse(NULL, 0);
return jtag_dev_count;
}

View File

@ -29,6 +29,7 @@
#include "general.h"
#include "target.h"
#include "target_internal.h"
#define SIM_SDID 0x40048024

View File

@ -26,6 +26,7 @@
#include "general.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#define SRAM_BASE 0x20000000

View File

@ -20,6 +20,7 @@
#include "general.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "lpc_common.h"

View File

@ -21,6 +21,7 @@
#include "general.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "lpc_common.h"

View File

@ -19,8 +19,8 @@
*/
#include "general.h"
#include "command.h"
#include "target.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"
#include "lpc_common.h"

View File

@ -18,6 +18,7 @@
*/
#include "general.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "lpc_common.h"

View File

@ -22,9 +22,8 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"

View File

@ -25,9 +25,8 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
static int sam4_flash_erase(struct target_flash *f, uint32_t addr, size_t len);

View File

@ -33,10 +33,8 @@
*/
#include "general.h"
#include "jtagtap.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"

View File

@ -30,10 +30,9 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "command.h"
#include "gdb_packet.h"
static bool stm32f1_cmd_erase_mass(target *t);

View File

@ -31,10 +31,9 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "command.h"
#include "gdb_packet.h"
static bool stm32f4_cmd_erase_mass(target *t);

View File

@ -74,9 +74,8 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "command.h"
#include "target_internal.h"
#include "gdb_packet.h"
#include "cortexm.h"

View File

@ -31,10 +31,9 @@
*/
#include "general.h"
#include "adiv5.h"
#include "target.h"
#include "target_internal.h"
#include "cortexm.h"
#include "command.h"
#include "gdb_packet.h"
static bool stm32l4_cmd_erase_mass(target *t);

View File

@ -20,6 +20,7 @@
#include "general.h"
#include "target.h"
#include "target_internal.h"
target *target_list = NULL;
@ -399,3 +400,23 @@ void target_mem_write8(target *t, uint32_t addr, uint8_t value)
target_mem_write(t, addr, &value, sizeof(value));
}
#include "gdb_packet.h"
void target_command_help(target *t)
{
for (struct target_command_s *tc = t->commands; tc; tc = tc->next) {
gdb_outf("%s specific commands:\n", tc->specific_name);
for(const struct command_s *c = tc->cmds; c->cmd; c++)
gdb_outf("\t%s -- %s\n", c->cmd, c->help);
}
}
int target_command(target *t, int argc, const char *argv[])
{
for (struct target_command_s *tc = t->commands; tc; tc = tc->next)
for(const struct command_s *c = tc->cmds; c->cmd; c++)
if(!strncmp(argv[0], c->cmd, strlen(argv[0])))
return !c->handler(t, argc, argv);
return -1;
}

View File

@ -54,6 +54,20 @@ struct target_flash {
void *buf;
};
typedef bool (*cmd_handler)(target *t, int argc, const char **argv);
struct command_s {
const char *cmd;
cmd_handler handler;
const char *help;
};
struct target_command_s {
const char *specific_name;
const struct command_s *cmds;
struct target_command_s *next;
};
struct target_s {
bool attached;
/* Notify controlling debugger if target is lost */