[coreboot-gerrit] Patch set updated for coreboot: f11b9b7 libpayload: Let GDB stub read/write memory with aligned MMIO words

Marc Jones (marc.jones@se-eng.com) gerrit at coreboot.org
Fri Jan 9 07:31:29 CET 2015


Marc Jones (marc.jones at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8130

-gerrit

commit f11b9b75df337ba8479bdb1707f77d33b38ed11a
Author: Julius Werner <jwerner at chromium.org>
Date:   Wed Jul 16 18:39:58 2014 -0700

    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.
    
    Original-Change-Id: I2ae52636593499f70701582811f1b692c1ea8fcc
    Original-Signed-off-by: Julius Werner <jwerner at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/208554
    Original-Reviewed-by: David Hendricks <dhendrix at chromium.org>
    (cherry picked from commit 028940934e6b45a02122b61bb859588bf8671938)
    Signed-off-by: Marc Jones <marc.jones at se-eng.com>
    
    Change-Id: I4185a6efe9a5211525781acd0a167b821e854211
---
 payloads/libpayload/gdb/transport.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/payloads/libpayload/gdb/transport.c b/payloads/libpayload/gdb/transport.c
index 596ceb5..22983e1 100644
--- a/payloads/libpayload/gdb/transport.c
+++ b/payloads/libpayload/gdb/transport.c
@@ -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);
 	}
 }
 



More information about the coreboot-gerrit mailing list