summaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorStefan Reinauer <reinauer@chromium.org>2011-10-21 14:24:57 -0700
committerStefan Reinauer <stefan.reinauer@coreboot.org>2011-10-24 20:29:29 +0200
commita1e4824f73602a411826b27160a8818049ce0f97 (patch)
tree777dcf31f4eddaaf0c68078814bd27fb63f03524 /util/cbfstool/cbfstool.c
parent3c976791b06c75e8983266b3551f133d89924376 (diff)
downloadcoreboot-a1e4824f73602a411826b27160a8818049ce0f97.tar.xz
Various fixes to cbfstool.
- add ntohll and htonll (as coreboot parses 64bit fields now) - use the same byte swapping code across platforms - detect endianess early - fix lots of warnings - Don't override CFLAGS in Makefile Change-Id: Iaea02ff7a31ab6a95fd47858d0efd9af764a3e5f Signed-off-by: Stefan Reinauer <reinauer@google.com> Reviewed-on: http://review.coreboot.org/313 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index f017b2e2e0..b8abb515bf 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -19,7 +19,9 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "common.h"
#include "cbfs.h"
@@ -196,7 +198,6 @@ static int cbfs_add_stage(int argc, char **argv)
static int cbfs_create(int argc, char **argv)
{
char *romname = argv[1];
- char *cmd = argv[2];
if (argc < 5) {
printf("not enough arguments to 'create'.\n");
return 1;
@@ -239,7 +240,6 @@ static int cbfs_locate(int argc, char **argv)
static int cbfs_print(int argc, char **argv)
{
char *romname = argv[1];
- char *cmd = argv[2];
void *rom = loadrom(romname);
if (rom == NULL) {
@@ -254,7 +254,6 @@ static int cbfs_print(int argc, char **argv)
static int cbfs_extract(int argc, char **argv)
{
char *romname = argv[1];
- char *cmd = argv[2];
void *rom = loadrom(romname);
if (rom == NULL) {
@@ -271,7 +270,7 @@ static int cbfs_extract(int argc, char **argv)
return extract_file_from_cbfs(romname, argv[3], argv[4]);
}
-struct command commands[] = {
+static const struct command commands[] = {
{CMD_ADD, "add", cbfs_add},
{CMD_ADD_PAYLOAD, "add-payload", cbfs_add_payload},
{CMD_ADD_STAGE, "add-stage", cbfs_add_stage},
@@ -281,7 +280,7 @@ struct command commands[] = {
{CMD_EXTRACT, "extract", cbfs_extract},
};
-void usage(void)
+static void usage(void)
{
printf
("cbfstool: Management utility for CBFS formatted ROM images\n\n"
@@ -302,6 +301,20 @@ void usage(void)
print_supported_filetypes();
}
+/* Small, OS/libc independent runtime check
+ * for endianess
+ */
+int host_bigendian = 0;
+
+static void which_endian(void)
+{
+ char test[4] = "1234";
+ uint32_t inttest = *(uint32_t *) test;
+ if (inttest == 0x31323334) {
+ host_bigendian = 1;
+ }
+}
+
int main(int argc, char **argv)
{
int i;
@@ -311,6 +324,8 @@ int main(int argc, char **argv)
return 1;
}
+ which_endian();
+
char *cmd = argv[2];
for (i = 0; i < ARRAY_SIZE(commands); i++) {