cbfstool: Make endian detection functions to work without prior setup.

The 'host_bigendian' variable (and functions relying on it like ntohl/htonl)
requires host detection by calling static which_endian() first -- which may be
easily forgotten by developers.  It's now a public function in common.c and
doesn't need initialization anymore.

Change-Id: I13dabd1ad15d2d6657137d29138e0878040cb205
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2199
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Hung-Te Lin
2013-01-28 15:53:34 +08:00
parent d723c5b554
commit 332795cc59
4 changed files with 21 additions and 19 deletions

View File

@@ -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;