#include "rtos/rtos.h"
#include "transport/transport.h"
#include "arm_cti.h"
+#include "smp.h"
/* default halt wait timeout (ms) */
#define DEFAULT_HALT_TIMEOUT 5000
static LIST_HEAD(target_reset_callback_list);
static LIST_HEAD(target_trace_callback_list);
static const int polling_interval = TARGET_DEFAULT_POLLING_INTERVAL;
+static LIST_HEAD(empty_smp_targets);
static const struct jim_nvp nvp_assert[] = {
{ .name = "assert", NVP_ASSERT },
/* release the targets SMP list */
if (target->smp) {
- struct target_list *head = target->head;
- while (head) {
- struct target_list *pos = head->next;
+ struct target_list *head, *tmp;
+
+ list_for_each_entry_safe(head, tmp, target->smp_targets, lh) {
+ list_del(&head->lh);
head->target->smp = 0;
free(head);
- head = pos;
}
+ if (target->smp_targets != &empty_smp_targets)
+ free(target->smp_targets);
target->smp = 0;
}
}
}
+static int target_jim_set_reg(Jim_Interp *interp, int argc,
+ Jim_Obj * const *argv)
+{
+ if (argc != 2) {
+ Jim_WrongNumArgs(interp, 1, argv, "dict");
+ return JIM_ERR;
+ }
+
+ int tmp;
+ Jim_Obj **dict = Jim_DictPairs(interp, argv[1], &tmp);
+
+ if (!dict)
+ return JIM_ERR;
+
+ const unsigned int length = tmp;
+ struct command_context *cmd_ctx = current_command_context(interp);
+ assert(cmd_ctx);
+ const struct target *target = get_current_target(cmd_ctx);
+
+ for (unsigned int i = 0; i < length; i += 2) {
+ const char *reg_name = Jim_String(dict[i]);
+ const char *reg_value = Jim_String(dict[i + 1]);
+ struct reg *reg = register_get_by_name(target->reg_cache, reg_name,
+ false);
+
+ if (!reg || !reg->exist) {
+ Jim_SetResultFormatted(interp, "unknown register '%s'", reg_name);
+ return JIM_ERR;
+ }
+
+ uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8));
+
+ if (!buf) {
+ LOG_ERROR("Failed to allocate memory");
+ return JIM_ERR;
+ }
+
+ str_to_buf(reg_value, strlen(reg_value), buf, reg->size, 0);
+ int retval = reg->type->set(reg, buf);
+ free(buf);
+
+ if (retval != ERROR_OK) {
+ Jim_SetResultFormatted(interp, "failed to set '%s' to register '%s'",
+ reg_value, reg_name);
+ return JIM_ERR;
+ }
+ }
+
+ return JIM_OK;
+}
+
/**
* Returns true only if the target has a handler for the specified event.
*/
"from target memory",
.usage = "arrayname bitwidth address count",
},
+ {
+ .name = "set_reg",
+ .mode = COMMAND_EXEC,
+ .jim_handler = target_jim_set_reg,
+ .help = "Set target register values",
+ .usage = "dict",
+ },
{
.name = "eventlist",
.handler = handle_target_event_list,
return JIM_ERR;
}
+ /* set empty smp cluster */
+ target->smp_targets = &empty_smp_targets;
+
/* set target number */
target->target_number = new_target_number();
const char *targetname;
int retval, len;
struct target *target = NULL;
- struct target_list *head, *curr, *new;
- curr = NULL;
- head = NULL;
+ struct target_list *head, *new;
retval = 0;
LOG_DEBUG("%d", argc);
* argv[3] ...
*/
+ struct list_head *lh = malloc(sizeof(*lh));
+ if (!lh) {
+ LOG_ERROR("Out of memory");
+ return JIM_ERR;
+ }
+ INIT_LIST_HEAD(lh);
+
for (i = 1; i < argc; i++) {
targetname = Jim_GetString(argv[i], &len);
if (target) {
new = malloc(sizeof(struct target_list));
new->target = target;
- new->next = NULL;
- if (!head) {
- head = new;
- curr = head;
- } else {
- curr->next = new;
- curr = new;
- }
+ list_add_tail(&new->lh, lh);
}
}
/* now parse the list of cpu and put the target in smp mode*/
- curr = head;
-
- while (curr) {
- target = curr->target;
+ foreach_smp_target(head, lh) {
+ target = head->target;
target->smp = 1;
- target->head = head;
- curr = curr->next;
+ target->smp_targets = lh;
}
if (target && target->rtos)
"and write the 8/16/32 bit values",
.usage = "arrayname bitwidth address count",
},
+ {
+ .name = "set_reg",
+ .mode = COMMAND_EXEC,
+ .jim_handler = target_jim_set_reg,
+ .help = "Set target register values",
+ .usage = "dict",
+ },
{
.name = "reset_nag",
.handler = handle_target_reset_nag,