I'm making eeprom(8) work on FDT-enabled armv7 platforms.  Those are
little-endian, but the FDT is defined to be big-endian.  So eeprom(8)
needs to byteswap 32-bit "cells" for printing.

The second bit makes sure we zero the op_name when we start
enumerating properties.  Without this we run the risk of skipping the
properties of the root node since the lookup of random stack garbage
fails.

ok?


Index: optree.c
===================================================================
RCS file: /cvs/src/usr.sbin/eeprom/optree.c,v
retrieving revision 1.6
diff -u -p -r1.6 optree.c
--- optree.c    14 Jan 2009 21:05:53 -0000      1.6
+++ optree.c    21 May 2016 18:21:05 -0000
@@ -37,6 +37,7 @@ op_print(struct opiocdesc *opio, int dep
 {
        char *p;
        int i, special;
+       uint32_t cell;
 
        opio->op_name[opio->op_namelen] = '\0';
        printf("%*s%s: ", depth * 4, " ", opio->op_name);
@@ -79,7 +80,8 @@ op_print(struct opiocdesc *opio, int dep
                            i += sizeof(int)) {
                                if (i)
                                        printf(".");
-                               printf("%08x", *(int *)(long)&opio->op_buf[i]);
+                               cell = *(uint32_t *)&opio->op_buf[i];
+                               printf("%08x", betoh32(cell));
                        }
                        if (i < opio->op_buflen) {
                                if (i)
@@ -111,6 +113,7 @@ op_nodes(int fd, int node, int depth)
        char op_name[BUFSIZE];
        struct opiocdesc opio;
 
+       memset(op_name, 0, sizeof(op_name));
        opio.op_nodeid = node;
        opio.op_buf = op_buf;
        opio.op_name = op_name;

Reply via email to