summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootloader/x1000/recovery.c1
-rw-r--r--bootloader/x1000/utils.c73
-rw-r--r--bootloader/x1000/x1000bootloader.h1
-rw-r--r--firmware/target/mips/ingenic_x1000/nand-x1000.h1
4 files changed, 76 insertions, 0 deletions
diff --git a/bootloader/x1000/recovery.c b/bootloader/x1000/recovery.c
index c53fa376b9..e6cc041d99 100644
--- a/bootloader/x1000/recovery.c
+++ b/bootloader/x1000/recovery.c
@@ -68,6 +68,7 @@ static const struct menuitem debug_menu_items[] = {
68#ifdef HAVE_SCREENDUMP 68#ifdef HAVE_SCREENDUMP
69 {MENUITEM_ACTION, "Enable screenshots", &screenshot_enable}, 69 {MENUITEM_ACTION, "Enable screenshots", &screenshot_enable},
70#endif 70#endif
71 {MENUITEM_ACTION, "Flash info", &show_flash_info},
71#ifdef OF_PLAYER_ADDR 72#ifdef OF_PLAYER_ADDR
72 {MENUITEM_ACTION, "Dump OF player", &dump_of_player}, 73 {MENUITEM_ACTION, "Dump OF player", &dump_of_player},
73#endif 74#endif
diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c
index 4d3fb69e57..17eb502e1b 100644
--- a/bootloader/x1000/utils.c
+++ b/bootloader/x1000/utils.c
@@ -31,6 +31,7 @@
31#include "linuxboot.h" 31#include "linuxboot.h"
32#include "screendump.h" 32#include "screendump.h"
33#include "nand-x1000.h" 33#include "nand-x1000.h"
34#include "sfc-x1000.h"
34 35
35/* Set to true if a SYS_USB_CONNECTED event is seen 36/* Set to true if a SYS_USB_CONNECTED event is seen
36 * Set to false if a SYS_USB_DISCONNECTED event is seen 37 * Set to false if a SYS_USB_DISCONNECTED event is seen
@@ -338,3 +339,75 @@ void dump_entire_flash(void)
338 dump_flash_file("/flash.img", 0, 2048 * 64 * 1024); 339 dump_flash_file("/flash.img", 0, 2048 * 64 * 1024);
339#endif 340#endif
340} 341}
342
343static void probe_flash(int log_fd)
344{
345 static uint8_t buffer[CACHEALIGN_UP(32)] CACHEALIGN_ATTR;
346
347 /* Use parameters from maskrom */
348 const uint32_t clock_freq = X1000_EXCLK_FREQ; /* a guess */
349 const uint32_t dev_conf = jz_orf(SFC_DEV_CONF,
350 CE_DL(1), HOLD_DL(1), WP_DL(1),
351 CPHA(0), CPOL(0),
352 TSH(0), TSETUP(0), THOLD(0),
353 STA_TYPE_V(1BYTE), CMD_TYPE_V(8BITS),
354 SMP_DELAY(0));
355 const size_t readid_len = 4;
356
357 /* NOTE: This assumes the NAND driver is inactive. If this is not true,
358 * this will seriously mess up the NAND driver. */
359 sfc_open();
360 sfc_set_dev_conf(dev_conf);
361 sfc_set_clock(clock_freq);
362
363 /* Issue reset */
364 sfc_exec(NANDCMD_RESET, 0, NULL, 0);
365 mdelay(10);
366
367 /* Try various read ID commands (cf. Linux's SPI NAND identify routine) */
368 sfc_exec(NANDCMD_READID(0, 0), 0, buffer, readid_len|SFC_READ);
369 fdprintf(log_fd, "readID opcode = %02x %02x %02x %02x\n",
370 buffer[0], buffer[1], buffer[2], buffer[3]);
371
372 sfc_exec(NANDCMD_READID(1, 0), 0, buffer, readid_len|SFC_READ);
373 fdprintf(log_fd, "readID address = %02x %02x %02x %02x\n",
374 buffer[0], buffer[1], buffer[2], buffer[3]);
375
376 sfc_exec(NANDCMD_READID(0, 8), 0, buffer, readid_len|SFC_READ);
377 fdprintf(log_fd, "readID dummy = %02x %02x %02x %02x\n",
378 buffer[0], buffer[1], buffer[2], buffer[3]);
379
380 /* Try reading Ingenic SFC boot block */
381 sfc_exec(NANDCMD_PAGE_READ(3), 0, NULL, 0);
382 mdelay(500);
383 sfc_exec(NANDCMD_READ_CACHE_SLOW(2), 0, buffer, 16|SFC_READ);
384
385 fdprintf(log_fd, "sfc params0 = %02x %02x %02x %02x\n",
386 buffer[ 0], buffer[ 1], buffer[ 2], buffer[ 3]);
387 fdprintf(log_fd, "sfc params1 = %02x %02x %02x %02x\n",
388 buffer[ 4], buffer[ 5], buffer[ 6], buffer[ 7]);
389 fdprintf(log_fd, "sfc params2 = %02x %02x %02x %02x\n",
390 buffer[ 8], buffer[ 9], buffer[10], buffer[11]);
391 fdprintf(log_fd, "sfc params3 = %02x %02x %02x %02x\n",
392 buffer[12], buffer[13], buffer[14], buffer[15]);
393
394 sfc_close();
395}
396
397void show_flash_info(void)
398{
399 if(check_disk(true) != DISK_PRESENT)
400 return;
401
402 int fd = open("/flash_info.txt", O_WRONLY|O_CREAT|O_TRUNC);
403 if(fd < 0) {
404 splashf(5*HZ, "Cannot create log file");
405 return;
406 }
407
408 splashf(0, "Probing flash...");
409 probe_flash(fd);
410
411 close(fd);
412 splashf(3*HZ, "Dumped flash info\nSee flash_info.txt");
413}
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h
index 81c7f2aaa4..e74a6a3b68 100644
--- a/bootloader/x1000/x1000bootloader.h
+++ b/bootloader/x1000/x1000bootloader.h
@@ -197,6 +197,7 @@ int dump_flash_file(const char* file, uint32_t addr, uint32_t length);
197void dump_of_player(void); 197void dump_of_player(void);
198void dump_of_recovery(void); 198void dump_of_recovery(void);
199void dump_entire_flash(void); 199void dump_entire_flash(void);
200void show_flash_info(void);
200 201
201void recovery_menu(void) __attribute__((noreturn)); 202void recovery_menu(void) __attribute__((noreturn));
202 203
diff --git a/firmware/target/mips/ingenic_x1000/nand-x1000.h b/firmware/target/mips/ingenic_x1000/nand-x1000.h
index 150361b739..5e6d1f09bc 100644
--- a/firmware/target/mips/ingenic_x1000/nand-x1000.h
+++ b/firmware/target/mips/ingenic_x1000/nand-x1000.h
@@ -49,6 +49,7 @@
49#define NANDCMD_GET_FEATURE SFC_CMD(0x0f, SFC_TMODE_1_1_1, 1, 0, SFC_PFMT_ADDR_FIRST, 1) 49#define NANDCMD_GET_FEATURE SFC_CMD(0x0f, SFC_TMODE_1_1_1, 1, 0, SFC_PFMT_ADDR_FIRST, 1)
50#define NANDCMD_SET_FEATURE SFC_CMD(0x1f, SFC_TMODE_1_1_1, 1, 0, SFC_PFMT_ADDR_FIRST, 1) 50#define NANDCMD_SET_FEATURE SFC_CMD(0x1f, SFC_TMODE_1_1_1, 1, 0, SFC_PFMT_ADDR_FIRST, 1)
51#define NANDCMD_PAGE_READ(x) SFC_CMD(0x13, SFC_TMODE_1_1_1, x, 0, SFC_PFMT_ADDR_FIRST, 0) 51#define NANDCMD_PAGE_READ(x) SFC_CMD(0x13, SFC_TMODE_1_1_1, x, 0, SFC_PFMT_ADDR_FIRST, 0)
52#define NANDCMD_READ_CACHE_SLOW(x) SFC_CMD(0x03, SFC_TMODE_1_1_1, x, 8, SFC_PFMT_ADDR_FIRST, 1)
52#define NANDCMD_READ_CACHE(x) SFC_CMD(0x0b, SFC_TMODE_1_1_1, x, 8, SFC_PFMT_ADDR_FIRST, 1) 53#define NANDCMD_READ_CACHE(x) SFC_CMD(0x0b, SFC_TMODE_1_1_1, x, 8, SFC_PFMT_ADDR_FIRST, 1)
53#define NANDCMD_READ_CACHE_x4(x) SFC_CMD(0x6b, SFC_TMODE_1_1_4, x, 8, SFC_PFMT_ADDR_FIRST, 1) 54#define NANDCMD_READ_CACHE_x4(x) SFC_CMD(0x6b, SFC_TMODE_1_1_4, x, 8, SFC_PFMT_ADDR_FIRST, 1)
54#define NANDCMD_PROGRAM_LOAD(x) SFC_CMD(0x02, SFC_TMODE_1_1_1, x, 0, SFC_PFMT_ADDR_FIRST, 1) 55#define NANDCMD_PROGRAM_LOAD(x) SFC_CMD(0x02, SFC_TMODE_1_1_1, x, 0, SFC_PFMT_ADDR_FIRST, 1)