diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2010-07-22 05:00:13 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-07-23 08:35:25 +0200 |
commit | d8c86961b333a9c88cf2aa4282a43b8382e9b810 (patch) | |
tree | cf8b39db96805a2ed876ba14f6824a96ebffc906 /arch/blackfin/boards/ipe337/cmd_alternate.c | |
parent | d879de38e8430eeb9b37b7b6a2ac3341b0b029f7 (diff) | |
download | barebox-d8c86961b333a9c88cf2aa4282a43b8382e9b810.tar.gz barebox-d8c86961b333a9c88cf2aa4282a43b8382e9b810.tar.xz |
move boards to arch/<architecure>/boards
this will allow each arch to handle the boards more simply and depending on
there need
the env var BOARD will refer to the current board dirent
for sandbox as we have only one board the board dirent is arch/sandbox/board
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/blackfin/boards/ipe337/cmd_alternate.c')
-rw-r--r-- | arch/blackfin/boards/ipe337/cmd_alternate.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/arch/blackfin/boards/ipe337/cmd_alternate.c b/arch/blackfin/boards/ipe337/cmd_alternate.c new file mode 100644 index 0000000000..2883c77d32 --- /dev/null +++ b/arch/blackfin/boards/ipe337/cmd_alternate.c @@ -0,0 +1,56 @@ +#include <common.h> +#include <command.h> +#include <linux/stat.h> +#include <malloc.h> +#include <fs.h> + +#define MAGIC 0x19691228 + +static int do_alternate(struct command *cmdtp, int argc, char *argv[]) +{ + void *buf; + size_t size; + ulong *ptr, val = 0, bitcount = 0; + + if (argc != 2) + return COMMAND_ERROR_USAGE; + + buf = read_file(argv[1], &size); + if (!buf) + return 1; + + ptr = buf; + if ((*ptr) != MAGIC) { + printf("Wrong magic! Expected 0x%08x, got 0x%08x.\n", MAGIC, *ptr); + return 1; + } + + ptr++; + + while ((ulong)ptr <= (ulong)buf + size && !(val = *ptr++)) + bitcount += 32; + + if (val) { + do { + if (val & 1) + break; + bitcount++; + } while (val >>= 1); + } + + printf("Bitcount : %d\n", bitcount); + + free(buf); + return (bitcount & 1) ? 3 : 2; +} + +static const __maybe_unused char cmd_alternate_help[] = +"Usage: alternate <file>" +"\n"; + +BAREBOX_CMD_START(alternate) + .cmd = do_alternate, + .usage = "count zero bits in a file", + BAREBOX_CMD_HELP(cmd_alternate_help) +BAREBOX_CMD_END + |