From 80868e44ac7859b5f71adc2d34148ff1521b1950 Mon Sep 17 00:00:00 2001 From: Brian Swetland Date: Wed, 5 Aug 2015 18:58:43 -0700 Subject: [app][mdebug] improve error reporting, enable reboot command --- app/mdebug/rswd.c | 20 +++++++++++++------- app/mdebug/rswdp.h | 7 +++++++ app/mdebug/swd-m0sub.c | 8 +++++--- 3 files changed, 25 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/mdebug/rswd.c b/app/mdebug/rswd.c index 336b6e5e..94c75cef 100644 --- a/app/mdebug/rswd.c +++ b/app/mdebug/rswd.c @@ -21,6 +21,8 @@ #include #include +#include + #include "swd.h" #include "rswdp.h" @@ -56,6 +58,10 @@ static u8 optable[16] = { static const char *board_str = TARGET; static const char *build_str = "fw v0.9 (" __DATE__ ", " __TIME__ ")"; +static void _reboot(void) { + platform_halt(HALT_ACTION_REBOOT, HALT_REASON_SW_RESET); +} + /* TODO bounds checking -- we trust the host far too much */ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) { unsigned msg, op, n; @@ -80,8 +86,8 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) { case CMD_SWD_WRITE: while (n-- > 0) { rxc--; - if (swd_write(optable[op], *rx++)) { - status = 3; + status = swd_write(optable[op], *rx++); + if (status) { goto done; } } @@ -89,11 +95,11 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) { case CMD_SWD_READ: tx[txc++] = RSWD_MSG(CMD_SWD_DATA, 0, n); while (n-- > 0) { - if (swd_read(optable[op], tx + txc)) { + status = swd_read(optable[op], tx + txc); + if (status) { txc++; while (n-- > 0) tx[txc++] = 0xfefefefe; - status = 3; goto done; } txc++; @@ -102,8 +108,8 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) { case CMD_SWD_DISCARD: while (n-- > 0) { u32 tmp; - if (swd_read(optable[op], &tmp)) { - status = 3; + status = swd_read(optable[op], &tmp); + if (status) { goto done; } } @@ -132,7 +138,7 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) { swdp_trace = op; continue; case CMD_BOOTLOADER: - //func = reboot_bootloader; + func = _reboot; continue; case CMD_SET_CLOCK: n = swd_set_clock(n); diff --git a/app/mdebug/rswdp.h b/app/mdebug/rswdp.h index 42ef81c6..a41e9e46 100644 --- a/app/mdebug/rswdp.h +++ b/app/mdebug/rswdp.h @@ -73,6 +73,13 @@ #define CMD_RX_MAXDATA 0x33 /* arg=bytes, declares senders rx buffer size */ #define CMD_CLOCK_KHZ 0x34 /* arg=khz, reports active clock rate */ +/* CMD_STATUS error codes */ +#define ERR_NONE 0 +#define ERR_INTERNAL 1 +#define ERR_TIMEOUT 2 +#define ERR_IO 3 +#define ERR_PARITY 4 + #define RSWD_VERSION 0x0100 /* CMD_SWD_OP operations - combine for direct AP/DP io */ diff --git a/app/mdebug/swd-m0sub.c b/app/mdebug/swd-m0sub.c index 20f9ab40..de3ec9d2 100644 --- a/app/mdebug/swd-m0sub.c +++ b/app/mdebug/swd-m0sub.c @@ -1,7 +1,7 @@ /* swdp-m0sub.c * * Copyright 2015 Brian Swetland - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,6 +29,8 @@ #include #include +#include "rswdp.h" + #define PIN_LED PIN(1,1) #define PIN_RESET PIN(2,5) #define PIN_RESET_TXEN PIN(2,6) @@ -116,7 +118,7 @@ void swd_init(void) { writel((1 << 11) | (1 << 14) | (1 << 15), SGPIO_OEN); writel(0, M4_TXEV); - writel(M0_SUB_RST, RESET_CTRL0); + writel(M0_SUB_RST, RESET_CTRL0); writel(0x18000000, M0SUB_ZEROMAP); writel(0xffffffff, 0x18004000); memcpy((void*) 0x18000000, zero_bin, sizeof(zero_bin)); @@ -152,7 +154,7 @@ int swd_read(unsigned hdr, unsigned *val) { data = readl(COMM_ARG1); p = readl(COMM_ARG2); if (p != parity(data)) { - return 2; + return ERR_PARITY; } //printf("rd s=%d p=%d d=%08x\n", n, p, data); *val = data; -- cgit v1.2.3