libpayload: Let GDB stub read/write memory with aligned MMIO words
Looks like we got our first SoC that actually insists on using word-sized accesses for its MMIO registers with the Rk3288. This patch changes the GDB command handler for reading and writing memory to always perform word-sized accesses. This isn't really perfect since the remote GDB interface is just not really meant to interact with MMIO (e.g. you shouldn't use this on something with read side effects), but for most of our purposes it should be good enough. BUG=chrome-os-partner:18390 TEST=Remote GDB works on Veyron even when writing MMIO registers. Change-Id: I2ae52636593499f70701582811f1b692c1ea8fcc Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/208554 Reviewed-by: David Hendricks <dhendrix@chromium.org>
This commit is contained in:
parent
a6141d13d4
commit
028940934e
1 changed files with 27 additions and 10 deletions
|
|
@ -16,9 +16,13 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <endian.h>
|
||||
#include <gdb.h>
|
||||
#include <libpayload.h>
|
||||
|
||||
/* MMIO word size is not standardized, but *usually* 32 (even on ARM64) */
|
||||
typedef u32 mmio_word_t;
|
||||
|
||||
static const int timeout_us = 100 * 1000;
|
||||
static const char output_overrun[] = "GDB output buffer overrun (try "
|
||||
"increasing reply.size)!\n";
|
||||
|
|
@ -55,7 +59,7 @@ void gdb_transport_teardown(void)
|
|||
|
||||
/* Hex digit character <-> number conversion (illegal chars undefined!). */
|
||||
|
||||
static s8 from_hex(unsigned char c)
|
||||
static u8 from_hex(unsigned char c)
|
||||
{
|
||||
static const s8 values[] = {
|
||||
-1, 10, 11, 12, 13, 14, 15, -1,
|
||||
|
|
@ -74,30 +78,43 @@ static char to_hex(u8 v)
|
|||
return digits[v & 0xf];
|
||||
}
|
||||
|
||||
/* Message encode/decode functions */
|
||||
/* Message encode/decode functions (must access whole aligned words for MMIO) */
|
||||
|
||||
void gdb_message_encode_bytes(struct gdb_message *message, const void *data,
|
||||
int length)
|
||||
{
|
||||
const u8 *bytes = data;
|
||||
die_if(message->used + length * 2 > message->size, output_overrun);
|
||||
const mmio_word_t *aligned =
|
||||
(mmio_word_t *)ALIGN_DOWN((uintptr_t)data, sizeof(*aligned));
|
||||
mmio_word_t word = be32toh(readl(aligned++));
|
||||
while (length--) {
|
||||
message->buf[message->used++] = to_hex(*bytes >> 4);
|
||||
message->buf[message->used++] = to_hex(*bytes & 0xf);
|
||||
bytes++;
|
||||
u8 byte = (word >> ((((void *)aligned - data) - 1) * 8));
|
||||
message->buf[message->used++] = to_hex(byte >> 4);
|
||||
message->buf[message->used++] = to_hex(byte & 0xf);
|
||||
if (length && ++data == (void *)aligned)
|
||||
word = be32toh(readl(aligned++));
|
||||
}
|
||||
}
|
||||
|
||||
void gdb_message_decode_bytes(const struct gdb_message *message, int offset,
|
||||
void *data, int length)
|
||||
{
|
||||
u8 *bytes = data;
|
||||
die_if(offset + 2 * length > message->used, "Decode overrun in GDB "
|
||||
"message: %.*s", message->used, message->buf);
|
||||
mmio_word_t *aligned =
|
||||
(mmio_word_t *)ALIGN_DOWN((uintptr_t)data, sizeof(*aligned));
|
||||
int shift = ((void *)(aligned + 1) - data) * 8;
|
||||
mmio_word_t word = be32toh(readl(aligned)) >> shift;
|
||||
while (length--) {
|
||||
*bytes = from_hex(message->buf[offset++]) << 4;
|
||||
*bytes += from_hex(message->buf[offset++]);
|
||||
bytes++;
|
||||
word <<= 8;
|
||||
word |= from_hex(message->buf[offset++]) << 4;
|
||||
word |= from_hex(message->buf[offset++]);
|
||||
if (++data - (void *)aligned == sizeof(*aligned))
|
||||
writel(htobe32(word), aligned++);
|
||||
}
|
||||
if (data != (void *)aligned) {
|
||||
shift = ((void *)(aligned + 1) - data) * 8;
|
||||
clrsetbits_be32(aligned, ~((1 << shift) - 1), word << shift);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue