annotate target-utils/pln-ppb-test/erase.c @ 1011:6d9b10633f10

etmsync Pirelli IMEI retrieval: fix poor use of printf() Bug reported by Vadim Yanitskiy <fixeria@osmocom.org>: the construct where a static-allocated string was passed to printf() without any format arguments causes newer compilers to report a security problem. Given that formatted output is not needed here, just fixed string output, change printf() to fputs(), and direct the error message to stderr while at it.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 May 2024 17:29:57 +0000
parents f34261bb3355
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
2 * erase command for PPB special mode
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "types.h"
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 void
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
9 cmd_erase(argbulk)
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 char *argbulk;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
12 char *argv[2];
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
13 u_long addr;
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u16 buf[256];
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int i;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
17 if (parse_args(argbulk, 1, 1, argv, 0) < 0)
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 return;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (parse_hexarg(argv[0], 8, &addr) < 0) {
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
20 printf("ERROR: argument must be a valid 32-bit hex address\n");
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (addr & 1) {
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 printf("ERROR: unaligned address\n");
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
990
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
27 *(volatile u16 *)addr = 0x80;
f34261bb3355 pln-ppb-test: implement PPB erase
Mychaela Falconia <falcon@freecalypso.org>
parents: 989
diff changeset
28 *(volatile u16 *)addr = 0x30;
989
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 for (i = 0; i < 256; i++)
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 buf[i] = *(volatile u16 *)addr;
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 for (i = 0; i < 256; i++)
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 printf("%04X%c", buf[i], (i & 15) == 15 ? '\n' : ' ');
a5bff8104b45 pln-ppb-test: implement program operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }