summaryrefslogtreecommitdiff
path: root/lib/x1000-installer/test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/x1000-installer/test/main.c')
-rw-r--r--lib/x1000-installer/test/main.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/x1000-installer/test/main.c b/lib/x1000-installer/test/main.c
new file mode 100644
index 0000000000..e952fb9d86
--- /dev/null
+++ b/lib/x1000-installer/test/main.c
@@ -0,0 +1,98 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "xf_nandio.h"
23#include "xf_error.h"
24#include "xf_update.h"
25#include "file.h"
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30static struct xf_nandio nio;
31
32static struct xf_map testmap[] = {
33 {
34 .name = "src/xf_error.c",
35 .offset = 0x00000000,
36 .length = 0x00004000,
37 },
38 {
39 .name = "src/xf_update.c",
40 .offset = 0x00010000,
41 .length = 0x00004000,
42 },
43 {
44 .name = "src/xf_package.c",
45 .offset = 0x00020000,
46 .length = 0x00001800,
47 },
48};
49
50void checkrc(int rc)
51{
52 if(rc == XF_E_SUCCESS)
53 return;
54
55 if(rc == XF_E_NAND) {
56 printf("NAND error: %d\n", nio.nand_err);
57 } else {
58 printf("error: %s\n", xf_strerror(rc));
59 printf(" CurBlock = %lu\n", (unsigned long)nio.cur_block);
60 printf(" CurOffset = %lu\n", (unsigned long)nio.offset_in_block);
61 }
62
63 exit(1);
64}
65
66int openstream_file(void* arg, const char* file, struct xf_stream* stream)
67{
68 (void)arg;
69 return xf_open_file(file, O_RDONLY, stream);
70}
71
72int main(int argc, char* argv[])
73{
74 (void)argc;
75 (void)argv;
76
77 nand_trace_reset(65535);
78
79 int rc = xf_nandio_init(&nio);
80 checkrc(rc);
81
82 rc = xf_updater_run(XF_UPDATE, &nio,
83 testmap, sizeof(testmap)/sizeof(struct xf_map),
84 openstream_file, NULL);
85 checkrc(rc);
86
87 for(size_t i = 0; i < nand_trace_length; ++i) {
88 const char* types[] = {"READ", "PROGRAM", "ERASE"};
89 const char* excep[] = {"NONE", "DOUBLE_PROGRAMMED", "CLEARED"};
90 printf("%s %s %lu\n",
91 types[nand_trace[i].type],
92 excep[nand_trace[i].exception],
93 (unsigned long)nand_trace[i].addr);
94 }
95
96 xf_nandio_destroy(&nio);
97 return 0;
98}