diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-05-06 00:22:56 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-05-06 08:37:26 +0100 |
commit | 15ad1c42db95b178b6125b8084148ed4463f1472 (patch) | |
tree | 4cb0a41b3dd077319a79c825d2ee666176254c7d /firmware/target/mips/ingenic_x1000/fiiom3k | |
parent | 244aad750c0148265f03c9da8a33b4e0a9f85468 (diff) | |
download | rockbox-15ad1c42db95b178b6125b8084148ed4463f1472.tar.gz rockbox-15ad1c42db95b178b6125b8084148ed4463f1472.zip |
X1000: simplify NAND driver
- Removed unnecessary layers of generic code
- Software ECC is gone since we don't need it now (and maybe not ever)
- Removed bounce buffering, so callers must now align buffers
Change-Id: I33fbac9d9d12a4657980b8618c7d62bfa91e2ea0
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k')
3 files changed, 24 insertions, 99 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c index cdd7276bee..154785ee0b 100644 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c +++ b/firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "installer.h" | 22 | #include "installer.h" |
23 | #include "nand-x1000.h" | 23 | #include "nand-x1000.h" |
24 | #include "system.h" | ||
24 | #include "core_alloc.h" | 25 | #include "core_alloc.h" |
25 | #include "file.h" | 26 | #include "file.h" |
26 | 27 | ||
@@ -40,22 +41,27 @@ | |||
40 | 41 | ||
41 | static int install_from_buffer(const void* buf) | 42 | static int install_from_buffer(const void* buf) |
42 | { | 43 | { |
44 | int status = INSTALL_SUCCESS; | ||
45 | int mf_id, dev_id; | ||
46 | |||
43 | if(nand_open()) | 47 | if(nand_open()) |
44 | return ERR_FLASH_OPEN_FAILED; | 48 | return ERR_FLASH_OPEN_FAILED; |
45 | 49 | if(nand_identify(&mf_id, &dev_id)) { | |
46 | int status = INSTALL_SUCCESS; | 50 | status = ERR_FLASH_OPEN_FAILED; |
51 | goto _exit; | ||
52 | } | ||
47 | 53 | ||
48 | if(nand_enable_writes(true)) { | 54 | if(nand_enable_writes(true)) { |
49 | status = ERR_FLASH_DISABLE_WP_FAILED; | 55 | status = ERR_FLASH_DISABLE_WP_FAILED; |
50 | goto _exit; | 56 | goto _exit; |
51 | } | 57 | } |
52 | 58 | ||
53 | if(nand_erase_bytes(0, BOOT_IMAGE_SIZE)) { | 59 | if(nand_erase(0, BOOT_IMAGE_SIZE)) { |
54 | status = ERR_FLASH_ERASE_FAILED; | 60 | status = ERR_FLASH_ERASE_FAILED; |
55 | goto _exit; | 61 | goto _exit; |
56 | } | 62 | } |
57 | 63 | ||
58 | if(nand_write_bytes(0, BOOT_IMAGE_SIZE, buf)) { | 64 | if(nand_write(0, BOOT_IMAGE_SIZE, (const uint8_t*)buf)) { |
59 | status = ERR_FLASH_WRITE_FAILED; | 65 | status = ERR_FLASH_WRITE_FAILED; |
60 | goto _exit; | 66 | goto _exit; |
61 | } | 67 | } |
@@ -72,12 +78,17 @@ static int install_from_buffer(const void* buf) | |||
72 | 78 | ||
73 | static int dump_to_buffer(void* buf) | 79 | static int dump_to_buffer(void* buf) |
74 | { | 80 | { |
81 | int status = INSTALL_SUCCESS; | ||
82 | int mf_id, dev_id; | ||
83 | |||
75 | if(nand_open()) | 84 | if(nand_open()) |
76 | return ERR_FLASH_OPEN_FAILED; | 85 | return ERR_FLASH_OPEN_FAILED; |
86 | if(nand_identify(&mf_id, &dev_id)) { | ||
87 | status = ERR_FLASH_OPEN_FAILED; | ||
88 | goto _exit; | ||
89 | } | ||
77 | 90 | ||
78 | int status = INSTALL_SUCCESS; | 91 | if(nand_read(0, BOOT_IMAGE_SIZE, (uint8_t*)buf)) { |
79 | |||
80 | if(nand_read_bytes(0, BOOT_IMAGE_SIZE, buf)) { | ||
81 | status = ERR_FLASH_READ_FAILED; | 92 | status = ERR_FLASH_READ_FAILED; |
82 | goto _exit; | 93 | goto _exit; |
83 | } | 94 | } |
@@ -90,12 +101,14 @@ static int dump_to_buffer(void* buf) | |||
90 | int install_bootloader(const char* path) | 101 | int install_bootloader(const char* path) |
91 | { | 102 | { |
92 | /* Allocate memory to hold image */ | 103 | /* Allocate memory to hold image */ |
93 | int handle = core_alloc("boot_image", BOOT_IMAGE_SIZE); | 104 | size_t bufsize = BOOT_IMAGE_SIZE + CACHEALIGN_SIZE - 1; |
105 | int handle = core_alloc("boot_image", bufsize); | ||
94 | if(handle < 0) | 106 | if(handle < 0) |
95 | return ERR_OUT_OF_MEMORY; | 107 | return ERR_OUT_OF_MEMORY; |
96 | 108 | ||
97 | int status = INSTALL_SUCCESS; | 109 | int status = INSTALL_SUCCESS; |
98 | void* buffer = core_get_data(handle); | 110 | void* buffer = core_get_data(handle); |
111 | CACHEALIGN_BUFFER(buffer, bufsize); | ||
99 | 112 | ||
100 | /* Open the boot image */ | 113 | /* Open the boot image */ |
101 | int fd = open(path, O_RDONLY); | 114 | int fd = open(path, O_RDONLY); |
@@ -132,13 +145,15 @@ int install_bootloader(const char* path) | |||
132 | int dump_bootloader(const char* path) | 145 | int dump_bootloader(const char* path) |
133 | { | 146 | { |
134 | /* Allocate memory to hold image */ | 147 | /* Allocate memory to hold image */ |
135 | int handle = core_alloc("boot_image", BOOT_IMAGE_SIZE); | 148 | size_t bufsize = BOOT_IMAGE_SIZE + CACHEALIGN_SIZE - 1; |
149 | int handle = core_alloc("boot_image", bufsize); | ||
136 | if(handle < 0) | 150 | if(handle < 0) |
137 | return -1; | 151 | return -1; |
138 | 152 | ||
139 | /* Read data from flash */ | 153 | /* Read data from flash */ |
140 | int fd = -1; | 154 | int fd = -1; |
141 | void* buffer = core_get_data(handle); | 155 | void* buffer = core_get_data(handle); |
156 | CACHEALIGN_BUFFER(buffer, bufsize); | ||
142 | int status = dump_to_buffer(buffer); | 157 | int status = dump_to_buffer(buffer); |
143 | if(status) | 158 | if(status) |
144 | goto _exit; | 159 | goto _exit; |
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/nand-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/nand-fiiom3k.c deleted file mode 100644 index 7c8a306bae..0000000000 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/nand-fiiom3k.c +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
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 "nand-x1000.h" | ||
23 | #include "nand-target.h" | ||
24 | #include "sfc-x1000.h" | ||
25 | |||
26 | /* Unbelievably FiiO has completely disabled the use of ECC for this chip | ||
27 | * in their Linux kernel, even though it has perfectly good spare areas. | ||
28 | * There's no internal ECC either. | ||
29 | * | ||
30 | * Using nanddump to read the spare areas reveals they're filled with 0xff, | ||
31 | * and the publicly released Linux source has the ecc_strength set to 0. | ||
32 | */ | ||
33 | static const nand_chip_data ato25d1ga = { | ||
34 | .name = "ATO25D1GA", | ||
35 | .mf_id = 0x9b, | ||
36 | .dev_id = 0x12, | ||
37 | .dev_conf = NAND_INIT_SFC_DEV_CONF, | ||
38 | /* XXX: datasheet says 104 MHz but FiiO seems to run this at 150 MHz. | ||
39 | * Didn't find any issues doing this so might as well keep the behavior. | ||
40 | */ | ||
41 | .clock_freq = NAND_INIT_CLOCK_SPEED, | ||
42 | .block_size = 64, | ||
43 | .page_size = 2048, | ||
44 | .spare_size = 64, | ||
45 | .rowaddr_width = 3, | ||
46 | .coladdr_width = 2, | ||
47 | .flags = NANDCHIP_FLAG_QUAD, | ||
48 | }; | ||
49 | |||
50 | const nand_chip_desc target_nand_chip_descs[] = { | ||
51 | {&ato25d1ga, &nand_chip_ops_std}, | ||
52 | {NULL, NULL}, | ||
53 | }; | ||
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/nand-target.h b/firmware/target/mips/ingenic_x1000/fiiom3k/nand-target.h deleted file mode 100644 index 1238d7e452..0000000000 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/nand-target.h +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
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 | #ifndef __NAND_TARGET_H__ | ||
23 | #define __NAND_TARGET_H__ | ||
24 | |||
25 | /* The max page size (main + spare) of all NAND chips used by this target */ | ||
26 | #define NAND_MAX_PAGE_SIZE (2048 + 64) | ||
27 | |||
28 | /* The clock speed to use for the SFC controller during chip identification */ | ||
29 | #define NAND_INIT_CLOCK_SPEED 150000000 | ||
30 | |||
31 | /* Initial value to program SFC_DEV_CONF register with */ | ||
32 | #define NAND_INIT_SFC_DEV_CONF \ | ||
33 | jz_orf(SFC_DEV_CONF, CE_DL(1), HOLD_DL(1), WP_DL(1), \ | ||
34 | CPHA(0), CPOL(0), TSH(7), TSETUP(0), THOLD(0), \ | ||
35 | STA_TYPE_V(1BYTE), CMD_TYPE_V(8BITS), SMP_DELAY(1)) | ||
36 | |||
37 | #endif /* __NAND_TARGET_H__ */ | ||