summaryrefslogtreecommitdiff
path: root/lib/x1000-installer/test_lib/nand-x1000.h
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-11-23 20:13:52 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-11-27 15:28:19 -0500
commit06423cab58569ef01eb526e5f0d2f5c0c8917aa0 (patch)
treeb1a356600f6f218de8d8d1ad1e839aff65c96a0f /lib/x1000-installer/test_lib/nand-x1000.h
parent98f1271aec1fd461ab20a1ae145bba630a5750fb (diff)
downloadrockbox-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_lib/nand-x1000.h')
-rw-r--r--lib/x1000-installer/test_lib/nand-x1000.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/lib/x1000-installer/test_lib/nand-x1000.h b/lib/x1000-installer/test_lib/nand-x1000.h
new file mode 100644
index 0000000000..f34f2ce026
--- /dev/null
+++ b/lib/x1000-installer/test_lib/nand-x1000.h
@@ -0,0 +1,112 @@
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/* Stripped down fake version of X1000 NAND API for testing purposes,
23 * uses a normal file to store the data */
24
25#ifndef __NAND_X1000_H__
26#define __NAND_X1000_H__
27
28#include <stdint.h>
29#include <stddef.h>
30#include <stdbool.h>
31
32#define NAND_SUCCESS 0
33#define NAND_ERR_UNKNOWN_CHIP (-1)
34#define NAND_ERR_PROGRAM_FAIL (-2)
35#define NAND_ERR_ERASE_FAIL (-3)
36#define NAND_ERR_UNALIGNED (-4)
37#define NAND_ERR_OTHER (-5)
38#define NAND_ERR_INJECTED (-6)
39
40/* keep max page size in sync with the NAND chip table in the .c file */
41#define NAND_DRV_SCRATCHSIZE 32
42#define NAND_DRV_MAXPAGESIZE 2112
43
44typedef uint32_t nand_block_t;
45typedef uint32_t nand_page_t;
46
47enum nand_trace_type {
48 NTT_READ,
49 NTT_PROGRAM,
50 NTT_ERASE,
51};
52
53enum nand_trace_exception {
54 NTE_NONE,
55 NTE_DOUBLE_PROGRAMMED,
56 NTE_CLEARED,
57};
58
59struct nand_trace {
60 enum nand_trace_type type;
61 enum nand_trace_exception exception;
62 nand_page_t addr;
63};
64
65typedef struct nand_chip {
66 /* Base2 logarithm of the number of pages per block */
67 unsigned log2_ppb;
68
69 /* Size of a page's main / oob areas, in bytes. */
70 unsigned page_size;
71 unsigned oob_size;
72
73 /* Total number of blocks in the chip */
74 unsigned nr_blocks;
75} nand_chip;
76
77typedef struct nand_drv {
78 /* Backing file */
79 int fd;
80 int metafd;
81 int lock_count;
82
83 unsigned refcount;
84 uint8_t* scratch_buf;
85 uint8_t* page_buf;
86 const nand_chip* chip;
87 unsigned ppb;
88 unsigned fpage_size;
89} nand_drv;
90
91extern const char* nand_backing_file;
92extern const char* nand_meta_file;
93
94extern struct nand_trace* nand_trace;
95extern size_t nand_trace_capacity;
96extern size_t nand_trace_length;
97
98extern void nand_trace_reset(size_t size);
99extern void nand_inject_error(int rc);
100
101extern nand_drv* nand_init(void);
102
103extern void nand_lock(nand_drv* drv);
104extern void nand_unlock(nand_drv* drv);
105
106extern int nand_open(nand_drv* drv);
107extern void nand_close(nand_drv* drv);
108extern int nand_block_erase(nand_drv* drv, nand_block_t block);
109extern int nand_page_program(nand_drv* drv, nand_page_t page, const void* buffer);
110extern int nand_page_read(nand_drv* drv, nand_page_t page, void* buffer);
111
112#endif /* __NAND_X1000_H__ */