diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-11-23 20:13:52 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-11-27 15:28:19 -0500 |
commit | 06423cab58569ef01eb526e5f0d2f5c0c8917aa0 (patch) | |
tree | b1a356600f6f218de8d8d1ad1e839aff65c96a0f /lib/x1000-installer/test/main.c | |
parent | 98f1271aec1fd461ab20a1ae145bba630a5750fb (diff) | |
download | rockbox-06423cab58569ef01eb526e5f0d2f5c0c8917aa0.tar.gz rockbox-06423cab58569ef01eb526e5f0d2f5c0c8917aa0.zip |
x1000-installer: Initial commit of new framework
This is a new flash installer framework for the X1000 targets.
A bunch of this code is *UNTESTED* but there is an external test
harness which allows the library to be built and tested on a PC.
Once tests are written and the bugs are ironed out this framework
will replace the existing installer code.
New features:
- Update tarballs are MD5-checksummed to guarantee integrity.
- The flash map is no longer fixed -- updates are self describing and
carry a map file which specifies the areas to update.
- Can take full or partial backups with checksums computed on the fly.
- Supports an additional verification mode which reads back data after
writing to ensure the flash contents were not silently corrupted.
Change-Id: I29a89190c7ff566019f6a844ad0571f01fb7192f
Diffstat (limited to 'lib/x1000-installer/test/main.c')
-rw-r--r-- | lib/x1000-installer/test/main.c | 98 |
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 | |||
30 | static struct xf_nandio nio; | ||
31 | |||
32 | static 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 | |||
50 | void 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 | |||
66 | int 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 | |||
72 | int 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 | } | ||