osmo-sdr/utils/vmelinearize/src/main.c @ master
1 | c46bad77 | Christian Daniel | #include <stdio.h>
|
---|---|---|---|
2 | #include <stdlib.h>
|
||
3 | #include <string.h>
|
||
4 | #include "utils.h"
|
||
5 | #include "hardware.h"
|
||
6 | |||
7 | static int printSyntax() |
||
8 | {
|
||
9 | fprintf(stderr, "Error: Invalid command line!\n\n" |
||
10 | "syntax: vmelin input-algo input-data > output\n" |
||
11 | "\n" |
||
12 | "input-algo: algo-file produced by Diamond\n" |
||
13 | "input-data: data-file produced by Diamond\n" |
||
14 | "> output: linearized file for USB-DFU (this is stdout!)\n"); |
||
15 | |||
16 | return EXIT_FAILURE; |
||
17 | }
|
||
18 | |||
19 | static int linearize(const void* algo, size_t algoSize, const void* bin, size_t binSize) |
||
20 | {
|
||
21 | g_ispAlgo = (uint8_t*)algo; |
||
22 | g_ispAlgoSize = algoSize; |
||
23 | g_ispData = (uint8_t*)bin; |
||
24 | g_ispDataSize = binSize; |
||
25 | |||
26 | return ispEntryPoint(); |
||
27 | }
|
||
28 | |||
29 | int main(int argc, char* argv[]) |
||
30 | {
|
||
31 | int i; |
||
32 | int res = -1; |
||
33 | void* bin; |
||
34 | size_t binSize; |
||
35 | void* algo; |
||
36 | size_t algoSize; |
||
37 | |||
38 | if(argc != 3) |
||
39 | return printSyntax(); |
||
40 | |||
41 | if((algo = loadFile(argv[1], &algoSize)) == NULL) |
||
42 | return EXIT_FAILURE; |
||
43 | if((bin = loadFile(argv[2], &binSize)) == NULL) |
||
44 | return EXIT_FAILURE; |
||
45 | |||
46 | res = linearize(algo, algoSize, bin, binSize); |
||
47 | |||
48 | // add some padding to force the DFU statemachine play through
|
||
49 | for(i = 0; i < 2048; i++) |
||
50 | printf("%c", 0xff); |
||
51 | |||
52 | return (res < 0) ? EXIT_FAILURE : EXIT_SUCCESS; |
||
53 | }
|