blob: ce2e3e0e7a2463b4482c99b5d6fe06606795598b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include <common.h>
#include <command.h>
#include <linux/stat.h>
#include <malloc.h>
#include <fs.h>
#define MAGIC 0x19691228
static int do_alternate (cmd_tbl_t *cmdtp, int argc, char *argv[])
{
void *buf;
size_t size;
ulong *ptr, val = 0, bitcount = 0;
if (argc != 2) {
u_boot_cmd_usage(cmdtp);
return 0;
}
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 __maybe_unused char cmd_alternate_help[] =
"Usage: alternate <file>"
"\n";
U_BOOT_CMD_START(alternate)
.maxargs = CONFIG_MAXARGS,
.cmd = do_alternate,
.usage = "count zero bits in a file",
U_BOOT_CMD_HELP(cmd_alternate_help)
U_BOOT_CMD_END
|