11#include "irx_imports.h"
16IRX_ID(
"ROMWRITE", 7, 1);
23 const char *m_nand_name;
24 const char *m_nand_desc;
25 int m_page_size_noecc;
26 int m_page_size_withecc;
27 int m_pages_per_block;
39static void thread_proc(
void *userdata);
40static void do_toggle_dev9addr_inner(
int len,
int cnt);
41static void set_boot_video_mode(
int flg);
42static void do_set_flag(
int flg);
43static void do_set_secr_code(
char code1,
char code2);
44static void do_handle_atfile_image(
int part,
const char *str);
45static void do_set_atfile_147_dir(
const char *str);
46static int do_start_write_proc(
void);
47static int do_format_device(
int abspart);
48static int do_write_partition(
int part);
49static int check_badblock_count(
void);
50static int get_nand_partition_offset(
int part,
int abspart);
51static int get_nand_partition_size(
int part,
int abspart);
52static int get_nand_block_size_div_32_div_64(
void);
53static int get_nand_block_size_div_32(
void);
54static void do_dma_write_bytes_multi(
void *ptr,
int pageoffs,
int pagecnt);
55static int do_list_files(
int part);
56static void do_output_bb_info(
int blocksd,
int abspart,
int bboffs);
57static int do_verify(
void *buf1,
void *buf2,
int len);
60#define USER_PRINTF(...) Kprintf(__VA_ARGS__)
62#define STATUS_PRINTF(...) Kprintf(__VA_ARGS__)
66 {0xEC, 0xDA, 0xFFFFFFFF, 0x15, 0xFFFFFFFF},
68 "8bit width, 256MBytes",
75 {0xEC, 0xDC, 0x10, 0x95, 0x54},
77 "8bit width, 512MBytes",
84 {0xEC, 0xD3, 0x51, 0x95, 0x58},
86 "8bit width, 1GBytes",
92 {{0x0, 0x0, 0x0, 0x0, 0x0}, NULL, NULL, 0, 0, 0, 0}};
94static char g_secr_code[2];
98static int g_boot_video_mode;
100static char *g_page_buf;
102static int g_badblock_count;
103static char g_product_code_tmp[32];
104static u8 *g_blockinfo_str_buf;
105static u16 *g_blockinfo_dat_buf;
107static char g_atfile_part_image[8][0x100];
108static char g_atfile_info_image[0x100];
109static char g_atfile_147_dir[0x100];
112static void do_format_nand_device(
char devindchr)
117 do_set_flag(0x10000);
120 do_set_flag(0x20000);
123 do_set_flag(0x30000);
126 do_set_flag(0xF0000);
130 STATUS_PRINTF(
" -f%c: Format NAND(atfile:) device\n", devindchr);
133static char *do_read_product_code(
int fd)
135 read(fd, g_product_code_tmp,
sizeof(g_product_code_tmp));
136 STATUS_PRINTF(
" ---> OK, set product code - \"%s\"\n", &g_product_code_tmp[16]);
138 return &g_product_code_tmp[4];
141int _start(
int ac,
char **av)
149 const char *product_code;
155 USER_PRINTF(
"SYS147 ROM Writer (version 0x%04x)\n\n", 0x701);
157 USER_PRINTF(
"usage: %s [OPTION]... [FILE]...\n",
"romwrite.irx");
159 USER_PRINTF(
" -m, --main ............. MainPCB mode (Send PRINTF to EE)\n");
161 USER_PRINTF(
" -s0 .................... Set default security code\n");
163 USER_PRINTF(
" -sr .................... Read \"s147secr.147\" and set security code\n");
165 USER_PRINTF(
" -f(f2, f4, f8) ......... Format NAND(atfile:) device\n");
167 USER_PRINTF(
" -0([1..7]) filename .... Write \"atfile[0..7]:\" image file\n");
169 USER_PRINTF(
" -d directory ........... Search \"atfile*.147\" in the directory and Write\n");
171 USER_PRINTF(
" -i filename ............ Write \"atfile9:info\" image from file\n");
173 USER_PRINTF(
" -l ..................... Read NAND device and Display all file list\n");
175 USER_PRINTF(
" -v, --vga .............. Set boot video mode (VGA)\n");
177 return MODULE_NO_RESIDENT_END;
180 g_badblock_count = 1;
181 USER_PRINTF(
"\n====== romwrite(version 0x%04x): Check argument ======\n", 0x701);
183 for ( i = 1; i < ac; i += 1 )
185 if ( !strcmp(av[i],
"-m") || !strcmp(av[i],
"--main") )
187 USER_PRINTF(
" -m, --main : MainPCB mode (Send PRINTF to EE)\n");
192 if ( !strcmp(av[i],
"-v") || !strcmp(av[i],
"--vga") )
194 USER_PRINTF(
" -v, --vga : Set boot video mode (VGA)\n");
196 set_boot_video_mode(2);
200 for ( i = 1; i < ac; i += 1 )
202 if ( av[i][0] !=
'-' )
214 image_file_idx = strtol(av[i] + 1, 0, 10);
215 STATUS_PRINTF(
" -%d : Write \"atfile%d:\" image file\n", image_file_idx, image_file_idx);
216 do_set_flag(1 << image_file_idx);
218 do_handle_atfile_image(image_file_idx, av[i]);
221 STATUS_PRINTF(
" -d : Search \"atfile*.147\" in the directory and Write\n");
223 do_set_flag(0x2000000);
224 do_set_atfile_147_dir(av[i]);
227 do_format_nand_device(av[i][2]);
230 STATUS_PRINTF(
" -i : Write \"atfile9:info\" image\n");
233 do_handle_atfile_image(9, av[i]);
236 STATUS_PRINTF(
" -l : Read NAND device and Display all file list\n");
237 do_set_flag(0x4000000);
243 STATUS_PRINTF(
" -s0: Set default security code\n");
244 do_set_flag(0x1000000);
245 do_set_secr_code(0xFF, 0xFF);
248 STATUS_PRINTF(
" -sr: Read \"s147secr.147\" file\n");
249 do_set_flag(0x1000000);
251 fd = open(av[i], O_RDONLY);
254 STATUS_PRINTF(
" ---> File not found, set default code\n");
255 do_set_secr_code(0xFF, 0xFF);
258 product_code = do_read_product_code(fd);
259 do_set_secr_code(product_code[0], product_code[1]);
263 STATUS_PRINTF(
" -s : Set immediate secrity code\n");
265 secrcode1 = strtol(av[i], 0, 10);
267 secrcode2 = strtol(av[i], 0, 10);
268 do_set_flag(0x1000000);
269 do_set_secr_code(secrcode1, secrcode2);
279 thparam.thread = thread_proc;
280 thparam.priority = 0x7A;
281 thparam.stacksize = 0x80000;
283 thid = CreateThread(&thparam);
285 return MODULE_NO_RESIDENT_END;
286 StartThread(thid, 0);
287 return MODULE_RESIDENT_END;
290static void thread_proc(
void *userdata)
293 USE_S147_DEV9_MEM_MMIO();
296 if ( do_start_write_proc() )
298 STATUS_PRINTF(
"\n****** Aborted ******\n\n");
301 s147_dev9_mem_mmio->m_watchdog_flag2 = 0;
302 s147_dev9_mem_mmio->m_led = 1;
304 s147_dev9_mem_mmio->m_watchdog_flag2 = 0;
305 s147_dev9_mem_mmio->m_led = 0;
309 STATUS_PRINTF(
"====== Completed ======\n\n");
312 for ( i = 1; i < 20; i += 1 )
314 s147_dev9_mem_mmio->m_watchdog_flag2 = 0;
315 do_toggle_dev9addr_inner(5 * i, 50);
317 for ( i = 20; i > 0; i -= 1 )
319 s147_dev9_mem_mmio->m_watchdog_flag2 = 0;
320 do_toggle_dev9addr_inner(5 * i, 50);
325static void do_toggle_dev9addr_inner(
int len,
int cnt)
328 USE_S147_DEV9_MEM_MMIO();
330 for ( i = 0; i < cnt; i += 1 )
334 s147_dev9_mem_mmio->m_led = 3;
335 DelayThread(10 * len);
339 s147_dev9_mem_mmio->m_led = 0;
340 DelayThread(10 * (100 - len));
347static unsigned int generate_acio_delay_val(
char dmat_val,
char rddl_val,
char wrdl_val)
349 return (((dmat_val - 1) & 0xF) << 24) | (((rddl_val - 1) & 0xF) << 4) | 0xA01A0100 | ((wrdl_val - 1) & 0xF);
356static void set_boot_video_mode(
int flg)
358 g_boot_video_mode = flg;
361static void do_set_flag(
int flg)
366static void do_set_secr_code(
char code1,
char code2)
368 g_secr_code[0] = code1;
369 g_secr_code[1] = code2;
372static void do_handle_atfile_image(
int part,
const char *str)
376 strcpy(g_atfile_info_image, str);
379 if ( part >= 0 && part < 8 && g_atfile_part_image[part] != str )
382 strcpy(g_atfile_part_image[part], str);
386static void do_set_atfile_147_dir(
const char *str)
388 strcpy(g_atfile_147_dir, str);
391static int do_start_write_proc(
void)
398 USE_S147_DEV9_MEM_MMIO();
400 close(open(
"ctrl99:watchdog-stop", O_RDONLY));
401 if ( (g_curflag & 0x1000000) != 0 )
403 STATUS_PRINTF(
"====== Set security code ======\n");
404 s147_dev9_mem_mmio->m_security_unlock_set1 = g_secr_code[0];
405 s147_dev9_mem_mmio->m_security_unlock_set2 = g_secr_code[1];
408 STATUS_PRINTF(
"====== Device information ======\n");
409 s147nand_26_nand_readid(nandid);
410 g_device_info = do_parse_device_info((
char *)nandid);
411 if ( !g_device_info )
413 STATUS_PRINTF(
" ID = %02X/%02X/%02X/%02X/%02X\n", nandid[0], nandid[1], nandid[2], nandid[3], nandid[4]);
414 STATUS_PRINTF(
"\nError: Unknown Device\n");
417 STATUS_PRINTF(
" ID = %02X/%02X/%02X/%02X/%02X\n", nandid[0], nandid[1], nandid[2], nandid[3], nandid[4]);
418 STATUS_PRINTF(
" \"%s\", %s\n", g_device_info->m_nand_name, g_device_info->m_nand_desc);
420 " PageSize = %d + %d (Bytes)\n",
421 g_device_info->m_page_size_noecc,
422 g_device_info->m_page_size_withecc - g_device_info->m_page_size_noecc);
423 STATUS_PRINTF(
" Pages/Block = %d (Pages)\n", g_device_info->m_pages_per_block);
424 STATUS_PRINTF(
" BlockSize = %d (Blocks)\n", g_device_info->m_block_size);
427 g_blockinfo_str_buf = (u8 *)AllocSysMemory(ALLOC_FIRST, g_device_info->m_block_size, 0);
428 g_blockinfo_dat_buf = (u16 *)AllocSysMemory(ALLOC_FIRST,
sizeof(u16) * g_device_info->m_block_size, 0);
430 if ( !g_blockinfo_str_buf || !g_blockinfo_dat_buf )
432 STATUS_PRINTF(
"\nError: AllocSysMemory failed\n\n");
435 nandinf = s147nand_16_getnandinfo();
437 nandinf->m_page_size_noecc = g_device_info->m_page_size_noecc;
438 nandinf->m_page_size_withecc = g_device_info->m_page_size_withecc;
439 nandinf->m_pages_per_block = g_device_info->m_pages_per_block;
440 nandinf->m_block_size = g_device_info->m_block_size;
441 nandinf->m_page_count = g_device_info->m_block_size * g_device_info->m_pages_per_block;
444 switch ( g_curflag & 0xFF0000 )
447 logaddrtable = do_format_device(2);
450 logaddrtable = do_format_device(4);
453 logaddrtable = do_format_device(8);
456 logaddrtable = do_format_device(0);
463 s147nand_6_checkformat();
464 close(open(
"atfile9:acdelay", O_RDONLY));
465 if ( (g_curflag & 0x2000000) != 0 )
467 STATUS_PRINTF(
"====== Search directory ======\n");
468 for ( part = 0; part < 8; part += 1 )
472 if ( s147nand_10_get_nand_partition_size(part) <= 0 )
474 STATUS_PRINTF(
" atfile%d: Unformatted - Do nothing\n", part);
477 sprintf(g_atfile_part_image[part],
"%satfile%d.147", g_atfile_147_dir, part);
478 fd = open(g_atfile_part_image[part], O_RDONLY);
484 do_set_flag(1 << part);
485 do_handle_atfile_image(part, g_atfile_part_image[part]);
487 STATUS_PRINTF(
" \"%s\" is found\n", g_atfile_part_image[part]);
489 STATUS_PRINTF(
" \n");
491 for ( part = 0; part < 8; part += 1 )
493 if ( ((1 << part) & g_curflag) == 0 )
495 STATUS_PRINTF(
"====== Write \"%s\" to atfile%d: ======\n", g_atfile_part_image[part], part);
496 logaddrtable = do_write_partition(part);
499 STATUS_PRINTF(
" \n");
501 if ( (g_curflag & 0x200) != 0 )
503 STATUS_PRINTF(
"====== Write \"%s\" to \"atfile9:info\" ======\n", g_atfile_info_image);
504 logaddrtable = do_write_partition(9);
507 STATUS_PRINTF(
" \n");
509 if ( (g_curflag & 0x4000000) != 0 )
511 STATUS_PRINTF(
"====== Display file list ======\n");
512 logaddrtable = s147nand_12_load_logaddrtable();
515 STATUS_PRINTF(
" Error: Unformatted device (%d)\n", logaddrtable);
518 for ( part = 0; part < 8; part += 1 )
524static int do_format_device(
int abspart)
528 int nand_partition_offset;
531 USE_S147_DEV9_MEM_MMIO();
533 STATUS_PRINTF(
"====== Format NAND device ======\n");
534 STATUS_PRINTF(
" [1/3]Block Erase and Check Bad Blocks\n");
535 STATUS_PRINTF(
" BadBlock =");
536 for ( blocks = 0; blocks < g_device_info->m_block_size; blocks += 1 )
540 s147_dev9_mem_mmio->m_led = (blocks >> 4) & 3;
541 eraseres = blocks ? s147nand_24_eraseoffset(s147nand_27_blocks2pages(blocks)) :
542 s147nand_25_nand_blockerase(s147nand_27_blocks2pages(0));
546 g_blockinfo_str_buf[blocks] =
'X';
547 STATUS_PRINTF(
" %d", blocks);
550 g_blockinfo_str_buf[blocks] =
'=';
553 STATUS_PRINTF(
" %d*(%d)", blocks, eraseres);
557 STATUS_PRINTF(
"\n\n");
558 STATUS_PRINTF(
" [2/3]Replace Bad Blocks ('B':Boot, 'I':Info, 'X':Broken, 'R':Reserved, '@':Occupied)\n");
559 g_blockinfo_dat_buf[0] = 0xEEEE;
560 g_blockinfo_str_buf[0] =
'B';
561 nand_partition_offset = get_nand_partition_offset(8, 8);
562 for ( blocks = 1; blocks < nand_partition_offset - 1; blocks += 1 )
564 if ( g_blockinfo_str_buf[blocks] !=
'=' )
566 g_blockinfo_dat_buf[blocks] = 0xEEEE;
567 g_blockinfo_str_buf[blocks] =
'R';
570 if ( g_blockinfo_str_buf[nand_partition_offset - 1] ==
'X' )
572 bbcnt1 = check_badblock_count();
575 g_blockinfo_dat_buf[nand_partition_offset - 1] = bbcnt1;
576 g_blockinfo_dat_buf[bbcnt1] = 0xCCCC;
577 g_blockinfo_str_buf[bbcnt1] =
'@';
583 g_blockinfo_dat_buf[nand_partition_offset - 1] = 0xAAAA;
584 bboffs = nand_partition_offset - 1;
588 for ( blocks = nand_partition_offset; blocks < g_device_info->m_block_size; blocks += 1 )
590 if ( g_blockinfo_str_buf[blocks] !=
'X' )
592 g_blockinfo_dat_buf[blocks] = 0xAAAA;
595 bbcnt1 = check_badblock_count();
598 g_blockinfo_dat_buf[blocks] = bbcnt1;
599 g_blockinfo_dat_buf[bbcnt1] = 0xCCCC;
600 g_blockinfo_str_buf[bbcnt1] =
'@';
605 STATUS_PRINTF(
" Error: Too many bad blocks to replace\n");
608 for ( blocks = 0; blocks < g_device_info->m_block_size; blocks += 1 )
610 do_output_bb_info(blocks, abspart, bboffs);
611 s147_dev9_mem_mmio->m_watchdog_flag2 = 0;
614 STATUS_PRINTF(
" [3/3]Write Boot Sector and Logical Address Table\n");
615 memset(&g_nand_partbuf.m_hdr, 0,
sizeof(g_nand_partbuf.m_hdr));
616 strncpy(g_nand_partbuf.m_hdr.m_sig,
"S147NAND", 9);
617 g_nand_partbuf.m_hdr.m_bootsector_ver_1 = 3;
618 g_nand_partbuf.m_hdr.m_bootsector_ver_2 = 0;
619 for ( i = 0; i < 8; i += 1 )
621 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_offset = get_nand_partition_offset(i, abspart);
622 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_size = get_nand_partition_size(i, abspart);
624 " atfile%d: StartBlock = 0x%04x(%4d) / BlockSize = 0x%04x(%4d)\n",
626 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_offset,
627 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_offset,
628 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_size,
629 g_nand_partbuf.m_hdr.m_nand_partition_info[i].m_size);
631 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_offset = get_nand_partition_offset(8, abspart);
632 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_size = get_nand_partition_size(8, abspart);
634 " system : StartBlock = 0x%04x(%4d) / BlockSize = 0x%04x(%4d)\n",
635 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_offset,
636 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_offset,
637 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_size,
638 g_nand_partbuf.m_hdr.m_nand_partition_8_info.m_size);
640 g_nand_partbuf.m_hdr.m_nand_seccode[0] = g_secr_code[0];
641 g_nand_partbuf.m_hdr.m_nand_seccode[1] = g_secr_code[1];
642 g_nand_partbuf.m_hdr.m_nand_vidmode[0] = g_boot_video_mode;
643 strncpy(g_nand_partbuf.m_hdr.m_nand_desc, g_device_info->m_nand_name,
sizeof(g_nand_partbuf.m_hdr.m_nand_desc));
644 g_nand_partbuf.m_hdr.m_page_size_noecc = g_device_info->m_page_size_noecc;
645 g_nand_partbuf.m_hdr.m_page_size_withecc = g_device_info->m_page_size_withecc;
646 g_nand_partbuf.m_hdr.m_pages_per_block = g_device_info->m_pages_per_block;
647 g_nand_partbuf.m_hdr.m_block_size = g_device_info->m_block_size;
648 g_nand_partbuf.m_hdr.m_acmem_delay_val = 0;
649 g_nand_partbuf.m_hdr.m_acio_delay_val = generate_acio_delay_val(3, 3, 3);
650 s147nand_22_nand_write_dma(&g_nand_partbuf.m_hdr, 0, 0,
sizeof(g_nand_partbuf.m_hdr));
651 do_dma_write_bytes_multi(g_blockinfo_dat_buf, 1,
sizeof(u16) * g_device_info->m_block_size);
655static int do_write_partition(
int part)
664 int expected_readres;
666 USE_S147_DEV9_MEM_MMIO();
669 expected_readres = 0;
673 partblocks1 = (s147nand_9_get_nand_partition(8) - 1) * g_device_info->m_pages_per_block;
674 if ( partblocks1 < 0 )
676 STATUS_PRINTF(
" Error: No partition #0 table\n");
679 fd = open(g_atfile_info_image, O_RDONLY);
682 STATUS_PRINTF(
" Error: File not found - \"%s\"\n", g_atfile_info_image);
688 partblocks1 = s147nand_9_get_nand_partition(part) * g_device_info->m_pages_per_block;
689 if ( partblocks1 < 0 )
691 STATUS_PRINTF(
" Error: Invalid unit number\n");
694 fd = open(g_atfile_part_image[part], O_RDONLY);
697 STATUS_PRINTF(
" Error: File not found - \"%s\"\n", g_atfile_part_image[part]);
702 g_page_buf = (
char *)AllocSysMemory(ALLOC_FIRST, g_device_info->m_page_size_noecc, 0);
706 STATUS_PRINTF(
"\nError: AllocSysMemory failed\n\n");
713 bytes = lseek(fd, 0, SEEK_END);
714 if ( g_device_info->m_page_size_noecc < bytes )
716 STATUS_PRINTF(
" Error: INFO image file is too large - \"%s\"\n", g_atfile_info_image);
717 STATUS_PRINTF(
" FileSize(%d) > info(%d)\n", bytes, g_device_info->m_page_size_noecc);
722 lseek(fd, 0, SEEK_SET);
723 expected_readres = 8;
724 actual_readres = read(fd, g_page_buf, expected_readres);
725 if ( actual_readres < expected_readres )
729 if ( strncmp(g_page_buf,
"S147INFO", 8) )
731 STATUS_PRINTF(
" Error: \"%s\" is not a S147INFO-image file\n", g_atfile_info_image);
746 bytes = lseek(fd, 0, SEEK_END);
748 s147nand_10_get_nand_partition_size(part) * g_device_info->m_pages_per_block * g_device_info->m_page_size_noecc;
749 if ( partsizebytes < bytes )
751 STATUS_PRINTF(
" Error: ROM image file is too large - \"%s\"\n", g_atfile_part_image[part]);
752 STATUS_PRINTF(
" FileSize(%d) > atfile%d(%d)\n", bytes, part, partsizebytes);
757 lseek(fd, 0, SEEK_SET);
758 expected_readres = 0x20;
759 actual_readres = read(fd, g_page_buf, expected_readres);
760 if ( actual_readres < expected_readres )
764 if ( strncmp(g_page_buf,
"S147ROM", 8) )
766 STATUS_PRINTF(
" Error: \"%s\" is not a S147ROM-image file\n", g_atfile_part_image[part]);
771 pages = s147nand_30_bytes2pagesnoeccround(bytes);
772 blocks = s147nand_29_pages2blockround(pages);
785 STATUS_PRINTF(
" FileSize = %dbytes SectorSize=%dsectors BlockSize=%dblocks\n", bytes, pages, blocks);
786 lseek(fd, 0, SEEK_SET);
788 pageoffs = partblocks1;
790 for ( xind1 = 0; xind1 < blocks; xind1 += 1 )
795 " atfile%d(%d/%d): LogBlock=%d (PhyBlock=%d) ",
799 s147nand_28_pages2blocks(pageoffs),
800 s147nand_13_translate_blockoffs(s147nand_28_pages2blocks(pageoffs)));
801 s147_dev9_mem_mmio->m_led = s147nand_28_pages2blocks(pageoffs) & 3;
802 if ( (g_curflag & 0xFF0000) == 0 )
804 STATUS_PRINTF(
"Erase -> ");
805 if ( s147nand_11_erasetranslatepageoffs(pageoffs) == -1470020 )
807 STATUS_PRINTF(
"\nromwrite: Bad block error, use \"-f\" option.\n");
812 STATUS_PRINTF(
"Write -> Verify\n");
813 for ( xind3 = 0; xind3 < g_device_info->m_pages_per_block; )
822 xindbytes = bytes - xind2 * g_device_info->m_page_size_noecc;
823 expected_readres = (xindbytes > 0x20000) ? 0x20000 : xindbytes;
827 memset(g_nand_partbuf.m_buf, 0, g_device_info->m_page_size_noecc);
828 expected_readres = (g_device_info->m_page_size_noecc < bytes) ? g_device_info->m_page_size_noecc : bytes;
831 actual_readres = read(fd, g_nand_partbuf.m_buf, expected_readres);
832 if ( actual_readres < expected_readres )
838 for ( i = 0; i <= 0x1FFFF; i += g_device_info->m_page_size_noecc )
840 s147nand_8_multi_write_dma(((
char *)g_nand_partbuf.m_buf) + i, pageoffs, 1);
841 s147nand_7_multi_read_dma(g_page_buf, pageoffs, 1);
842 if ( do_verify(((
char *)g_nand_partbuf.m_buf) + i, g_page_buf, g_device_info->m_page_size_noecc) )
845 "romwrite: Verify error - LogBlock=%d LogPage=%d\n", s147nand_28_pages2blocks(pageoffs), pageoffs);
853 if ( xind2 >= pages )
866 if ( actual_readres < expected_readres )
867 STATUS_PRINTF(
" Error: File-I/O fault (%d)\n", actual_readres);
875 FreeSysMemory(g_page_buf);
881static int check_badblock_count(
void)
886 for ( ; g_badblock_count < get_nand_partition_offset(8, 8) - 1; g_badblock_count += 1 )
888 if ( g_blockinfo_str_buf[g_badblock_count] ==
'R' )
890 retval = g_badblock_count;
891 g_badblock_count += 1;
898static int get_nand_partition_offset(
int part,
int abspart)
901 return get_nand_block_size_div_32();
904 if ( part < 0 || part >= abspart )
906 if ( abspart == -1 && g_device_info->m_block_size == (
int)0x80000000 )
910 return get_nand_block_size_div_32_div_64();
912 return g_device_info->m_block_size / abspart * part;
915 return g_device_info->m_block_size / 4;
918static int get_nand_partition_size(
int part,
int abspart)
921 return get_nand_block_size_div_32_div_64() - get_nand_block_size_div_32();
924 if ( part < 0 || part >= abspart )
926 if ( abspart == -1 && g_device_info->m_block_size == (
int)0x80000000 )
928 return g_device_info->m_block_size / abspart - (part ? 0 : get_nand_block_size_div_32_div_64());
931 return (part == 1) ? (3 * (g_device_info->m_block_size / 4)) : 0;
932 return g_device_info->m_block_size / 4 - get_nand_block_size_div_32_div_64();
935static int get_nand_block_size_div_32_div_64(
void)
937 return get_nand_block_size_div_32() + g_device_info->m_block_size / 64;
940static int get_nand_block_size_div_32(
void)
942 return g_device_info->m_block_size / 32;
945static void do_dma_write_bytes_multi(
void *ptr,
int pageoffs,
int pagecnt)
950 bytecnt = s147nand_30_bytes2pagesnoeccround(pagecnt);
951 for ( i = 0; i < bytecnt; i += 1 )
952 s147nand_22_nand_write_dma(
953 (
char *)ptr + ((g_device_info->m_page_size_noecc >> 2) << 2) * i,
956 g_device_info->m_page_size_noecc);
959static int do_list_files(
int part)
974 pageoffs = s147nand_9_get_nand_partition(part) * g_device_info->m_pages_per_block;
977 for ( xind1 = 0; xind1 < 64; xind1 += 1 )
979 s147nand_7_multi_read_dma(g_nand_partbuf.m_buf, pageoffs + xind1, 1);
980 for ( i = 0; i < 64; i += 1 )
982 if ( (xind1 << 6) - 1 + i == -1 )
984 if ( strncmp(g_nand_partbuf.m_dir.m_sig,
"S147ROM", 8) )
986 STATUS_PRINTF(
" \"%s%d:\" ... No data\n",
"atfile", part);
987 STATUS_PRINTF(
" -----------------------------\n\n");
990 hdrret = g_nand_partbuf.m_dir.m_entrycnt;
991 STATUS_PRINTF(
" \"%s%d:\"\n",
"atfile", part);
992 STATUS_PRINTF(
" -----------------------------\n");
996 if ( (xind1 << 6) - 1 + i >= hdrret )
1001 strcpy(pathtmp, g_nand_partbuf.m_direntry[i].m_name);
1002 if ( g_nand_partbuf.m_direntry[i].m_type ==
'D' )
1004 strcat(pathtmp,
"/");
1011 STATUS_PRINTF(
" %9d %s\n", g_nand_partbuf.m_direntry[i].m_size, pathtmp);
1018 STATUS_PRINTF(
" -----------------------------\n");
1019 STATUS_PRINTF(
" %d directories, %d files\n", dircnt, filcnt);
1020 STATUS_PRINTF(
"\n");
1024static void do_output_bb_info(
int blocksd,
int abspart,
int bboffs)
1027 if ( (blocksd & 0x3F) == 0 )
1028 STATUS_PRINTF(
" %04X(%4d):", blocksd, blocksd);
1029 STATUS_PRINTF(
"%c", (blocksd == bboffs) ?
'I' : g_blockinfo_str_buf[blocksd]);
1030 if ( (blocksd & 0xF) == 15 )
1032 if ( (blocksd & 0x3F) ==
'?' )
1033 STATUS_PRINTF(
"\n");
1036static int do_verify(
void *buf1,
void *buf2,
int len)
1040 for ( i = 0; i < len / 4; i += 1 )
1041 if ( ((u32 *)buf1)[i] != ((u32 *)buf2)[i] )
1042 return ((u32 *)buf1)[i] - ((u32 *)buf2)[i];
1051 for ( i = 0; g_nand_type_info[i].m_nand_name; i += 1 )
1056 for ( j = 0; j < 5; j += 1 )
1057 if ( ((
int)g_nand_type_info[i].m_id[j] == -1) || ((u8)g_nand_type_info[i].m_id[j] == (u8)nandid[j]) )
1060 return &g_nand_type_info[i];
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)