Hung-Te Lin (hun...@chromium.org) just uploaded a new patch set to gerrit, 
which you can find at http://review.coreboot.org/2199

-gerrit

commit 957be1481b7695d1f48ab9877071d8353304db5f
Author: Hung-Te Lin <hun...@chromium.org>
Date:   Mon Jan 28 15:53:34 2013 +0800

    cbfstool: Make endian detection functions to work without prior setup.
    
    The 'host_bigendian' variable (and functions rely on it like ntohl/htonl)
    requires system detection by calling static which_endian() first, which may 
be
    easily forgotten by developers.  It's now changed as a public function in
    common.c and doesn't need initialization anymore.
    
    Change-Id: I13dabd1ad15d2d6657137d29138e0878040cb205
    Signed-off-by: Hung-Te Lin <hun...@chromium.org>
---
 util/cbfstool/cbfs-mkstage.c |  2 +-
 util/cbfstool/cbfstool.c     | 14 --------------
 util/cbfstool/common.c       | 13 +++++++++++++
 util/cbfstool/common.h       | 11 +++++++----
 4 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/util/cbfstool/cbfs-mkstage.c b/util/cbfstool/cbfs-mkstage.c
index ef5182a..4374bda 100644
--- a/util/cbfstool/cbfs-mkstage.c
+++ b/util/cbfstool/cbfs-mkstage.c
@@ -77,7 +77,7 @@ int parse_elf_to_stage(unsigned char *input, unsigned char 
**output,
        if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB) {
                elf_bigendian = 1;
        }
-       if (elf_bigendian != host_bigendian) {
+       if (elf_bigendian != is_big_endian()) {
                elf32_to_native = swap32;
        }
 
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 1ad270b..11f1914 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -496,18 +496,6 @@ static void usage(char *name)
        print_supported_filetypes();
 }
 
-/* Small, OS/libc independent runtime check for endianess */
-int host_bigendian = 0;
-
-static void which_endian(void)
-{
-       static const uint32_t inttest = 0x12345678;
-       uint8_t inttest_lsb = *(uint8_t *)&inttest;
-       if (inttest_lsb == 0x12) {
-               host_bigendian = 1;
-       }
-}
-
 int main(int argc, char **argv)
 {
        size_t i;
@@ -518,8 +506,6 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       which_endian();
-
        param.cbfs_name = argv[1];
        char *cmd = argv[2];
        optind += 2;
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 8b4b4b4..6e362d9 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -27,6 +27,19 @@
 #include "cbfs.h"
 #include "elf.h"
 
+/* Utilities */
+
+/* Small, OS/libc independent runtime check for endianess */
+int is_big_endian(void)
+{
+       static const uint32_t inttest = 0x12345678;
+       uint8_t inttest_lsb = *(uint8_t *)&inttest;
+       if (inttest_lsb == 0x12) {
+               return 1;
+       }
+       return 0;
+}
+
 size_t getfilesize(const char *filename)
 {
        size_t size;
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index bd5ef65..5315e69 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -21,13 +21,16 @@
 #define __CBFSTOOL_COMMON_H
 
 #include <stdint.h>
+
+/* Endianess */
 #include "swab.h"
 #ifndef __APPLE__
-#define ntohl(x)  (host_bigendian?(x):swab32(x))
-#define htonl(x)  (host_bigendian?(x):swab32(x))
+#define ntohl(x)       (is_big_endian() ? (x) : swab32(x))
+#define htonl(x)       (is_big_endian() ? (x) : swab32(x))
 #endif
-#define ntohll(x) (host_bigendian?(x):swab64(x))
-#define htonll(x) (host_bigendian?(x):swab64(x))
+#define ntohll(x)      (is_big_endian() ? (x) : swab64(x))
+#define htonll(x)      (is_big_endian() ? (x) : swab64(x))
+extern int is_big_endian(void);
 
 /* Message output */
 extern int verbose;

-- 
coreboot mailing list: coreboot@coreboot.org
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to