{"id":861,"date":"2012-06-16T23:18:58","date_gmt":"2012-06-16T15:18:58","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=861"},"modified":"2012-06-16T23:52:08","modified_gmt":"2012-06-16T15:52:08","slug":"jz4755-jamma-board-reverse-engineering-part-3-king-of-game-board","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2012\/06\/jz4755-jamma-board-reverse-engineering-part-3-king-of-game-board\/","title":{"rendered":"JZ4755 Jamma Board Reverse Engineering Part 3 (King of Game Board)"},"content":{"rendered":"<p>Following up from my previous posts on this, looks like my idea&#8217;s are correct about the size of the NAND for setup, and my NAND read stuff works.  Yay for me.<\/p>\n<p>Lets recap:<\/p>\n<p>JZ4755 boot sequence is as follows:<\/p>\n<p>CPU powers up.<br \/>\nChecks BOOT_SEL line, takes appropriate action.<\/p>\n<p><code>boot_sel[1:0]<br \/>\n00\tUnused<br \/>\n01\tInitialization via USB port: Receives a block of data through the USB (device) port,<br \/>\nand stores it in internal SRAM.<br \/>\n10\tInitialization via NAND memory with 512-byte pages at Chip Select 1 (CS1):<br \/>\n11\tInitialization via NAND memory with 2048-byte pages at Chip Select 1 (CS1):<\/code><\/p>\n<p>In our board, if we press BOOT, this pulls the pin low, so CPU see&#8217;s 01, and waits for an IPL from USB.<br \/>\nIf we leave it to boot normally, then it reads from NAND.<\/p>\n<p>So far so good.<\/p>\n<p>Lets see if anyone was watching carefully \ud83d\ude42<br \/>\nOur board NAND chip has a page size of 8192+OOB<br \/>\nOur *CPU Hardware* supports either 512bytes or 2048bytes page size on boot.<br \/>\nOur IPL (aka NAND.BIN) must be 8K in size or less, as the CPU has 8k only, and it copies the bootloader to that obeying BOOT_SEL.  <\/p>\n<p>Lets look at what happens.<\/p>\n<p>If I read out the NAND (NREAD 0 8192 0 0)  with our carefully set sizing, I see the following:<\/p>\n<p><code>0000 - 2047 (2k in size) -  DATA  FF 55 55 .. 02 00 0C<br \/>\n2048 - 2549 (512bytes in size)  - BLANK<br \/>\n2560 - 4607 (2k in size) - DATA (padded at end with FF's to 2k size) 21 20 00 .. 85 8c 90+ FF -> 2048 end<br \/>\n4608 - 6655 (2k in size) - DATA  (padded at end with FF's to 2k size) <\/code><\/p>\n<p>So, we have roughly about 6k odd of data, out of our 8k max. Its a bit weirdly laid out though, and has some holes in there, so its _not_ correct \ud83d\ude41<\/p>\n<p>Lets look at the RAW NAND DUMP (NREAD_RAW 0 8192 0 0).  Our raw page size is 8192.<\/p>\n<p><code>Page 0<br \/>\n00000 - 02047 (2k in size) - DATA  FF 55 55 .. 02 00 0C (same as before)<br \/>\n02048 - 02102 (55 bytes)   - (presumed OOB \/ ECC stuff...) NEW<br \/>\nPage 1<br \/>\n08192 - 10239 (2k in size) - DATA 21 20 00 .. 10 80 00.  Our 85 8c 90 above is actually part of the 55byte sequence, so definitely our NREAD is incorrect, as we're suddenly short data.<br \/>\n10240 - 10294 (55 bytes )  - (presumed OOB \/ ECC stuff...) NEW<br \/>\nPage 2<br \/>\n16384 - 18431 (2k in size) - DATA (padded with 0's from 17892 - 18431), so our NAND loader data is roughly 5.5KBish.<br \/>\n18432 - 18486 (55 bytes )  - (presumed OOB \/ ECC stuff...) NEW<br \/>\nPage 3<br \/>\n25026 onwards FF's - so uninitialized.<\/code><\/p>\n<p>So, with that, we know that NREAD doesn&#8217;t quite work for our first 4 pages (page 0 &#8211; 3), and we either need to NREAD_RAW, or possibly use a 2048byte page size in order to read the NAND.BIN properly.<\/p>\n<p>Thats only necessary for the first 4 pages in the NAND though.<br \/>\nOnce the NAND.BIN MINIOS bootstrap is running, it should be able to cope with our proper data size.<\/p>\n<p>How does it do that though?<\/p>\n<p>MINIOS Bootloader starts up, as it gets added to the CPU boot sequence detailed above, then it looks for 3 things in 3 places \ud83d\ude42<\/p>\n<p>Our mystery locations for that are:<\/p>\n<p>Page 61<br \/>\nPage 62<br \/>\nPage 63<\/p>\n<p>Page 61 contains our NAND size stuff, which as we know from above, our Bootloader *can&#8217;t* use, as its only 2k or 512byte set at the hardware level initially.<\/p>\n<p>Page 61 in mine has 12 bytes.  This looks exceedingly good as I know that my work is, er, working \ud83d\ude42<\/p>\n<p><code>USBBoot :> nreadraw 61 24 0 0<br \/>\nReading RAW from No.0 device No.0 flash....<br \/>\n0x00000000 :00 20 00 00 c0 01 00 00 00 01 00 00<\/p>\n<p>00 20 00 00 = 8192 PAGE SIZE<br \/>\nc0 01 00 00 = 448  OOBSIZE<br \/>\n00 01 00 00 = 256 PAGE PER BLOCK<br \/>\n<\/code><\/p>\n<p>Lets look at the 3 bytes.<\/p>\n<p>First 16bit word is = 8192  &#8211; thats our Page Size<br \/>\nSecond 16bit word is = 448  &#8211; thats our OOB size (oob = out of block, usually used for CRC or Error etc, as NAND can go BAD if you write to it frequently)<br \/>\nThird 16bit word is = 256 &#8211; thats how many pages per block we have.<\/p>\n<p>Block 61, and Block 62 are the same.  Basically 62 is a backup of 61.  If the NAND.BIN MINIOS loader can&#8217;t read Block 61 12 bytes, it tries Block 62.  If neither work, you&#8217;ll need to reflash, or replace the NAND&#8230;<\/p>\n<p>Block 63 contains a whole 10 bytes.  This is the UID of the device.  Mine is set to 0.  Lazy buggers \ud83d\ude42<\/p>\n<p>Ok, so now we booted, and the MINIOS bootstraploader \/ NAND.BIN has read our NAND size, then what?<\/p>\n<p>Well, you&#8217;ll need to disassemble the code to see (eg as part of my previous post), but essentially it calls the next thing in line.<\/p>\n<p>This can be Linux, or something else. In the board, the OS used is MINIOS, so it loads something else &#8211; aka MINIOS.<\/p>\n<p>MINIOS is actually uCOS-II &#8211; You can find details on that from Micrium, as they licence it out.<br \/>\nIngenic has a custom version of uCOS-II for their board.  uCOS-II is also a RTOS (Real Time OS).<\/p>\n<p>You can read more on MINIOS here &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/MicroC\/OS-II\">http:\/\/en.wikipedia.org\/wiki\/MicroC\/OS-II<\/a><\/p>\n<p>Anyway, lets get back to work, and less chatter \ud83d\ude42<\/p>\n<p>NAND.BIN passes control onto whatever is sitting at Page 128 (this can be changed, but in the JAMMA board, and in the GameBox GBX-0001), the next loader is at Page 128.<\/p>\n<p>As I don&#8217;t have much info on the MINIOS side, I got a lot of this info from other places.  Mostly the MINIOS_CFG.INI in the Ingenic FTP Site, plus some gracious help from Joseba Epalza (thanks!) at <a href=\"http:\/\/www.zonadepruebas.com\">www.zonadepruebas.com<\/a>.  He supplied a Gamebox dump, and asked me a few questions, which made me re-examine things, which was extremely useful as then I could bounce idea&#8217;s and findings off of someone else.<\/p>\n<p>The Gamebox hardware and the Jamma hardware is extremely similar, so the NAND dump in both is good for both of us to double check each others work.  Unfortunately, I don&#8217;t speak <del datetime=\"2012-06-16T15:19:01+00:00\">Portuguese<\/del> Spanish, so we both relied on Google Translate to talk via email today, but we seem to be doing ok \ud83d\ude42<\/p>\n<p>Onto the tech side again, our secondary loader is, in MINIOS terms, called LOADER.BIN<\/p>\n<p>This sits at Page 128<br \/>\nLOADER.BIN tries to read a file called DEF_BOOT.BIN for configuration settings, as that tells LOADER.BIN where the rest of the filesystem is!<\/p>\n<p>In theory, Page 256 contains<br \/>\nDEF_BOOT.BIN<\/p>\n<p>I need to go back and recheck that now, as my dumps are a bit messy, and I need to check on actual hardware, vs the many whoops I renamed that wrong files I now have messing up my desktop.<br \/>\nI also need to check if I need to read as 2k block size\/or raw to get the correct data in these pages, as one place online says that the secondary bootloader (LOADER.BIN) also assumes 2k size.<\/p>\n<p>Other bits:<\/p>\n<p>IMG_BOOT.BIN &#8211; bootup code if used.<br \/>\nMINIOS.BIN &#8211; the OS.<br \/>\nRES.BIN &#8211; Resources used by MINIOS.BIN<\/p>\n<p>The rest&#8230; (FAT16 Filesystem which is readable over USB via normal boot)<br \/>\n&#8212;<\/p>\n<p>Ignoring my first 8k not quite correct dumped dumps + possibly borked secondary loader stuff, the rest of the data dump looks accurate.<\/p>\n<p>I have what looks like RES.BIN stuff, I have a MINIOS, and I can see interesting things.<\/p>\n<p>Interesting things below:<\/p>\n<p><code>Dump pos 0x100200 - seems to have the RES.BIN filesystem  in mine - <\/p>\n<p>mobile_tv.bin<br \/>\ndesktop.bin<br \/>\nudc_battery.bin<br \/>\nsysconfig.bin<br \/>\ntoolsbox.bin<br \/>\ncalendar.bin<br \/>\nebook.bin<br \/>\nworldclock.bin<br \/>\nrussblock.bin<br \/>\nfmradio.bin<br \/>\nrecorder.bin<br \/>\nmp3_compress.bin<br \/>\nviewer.bin<br \/>\njpgdec.bin<br \/>\npngdec.bin<br \/>\nbmpdec.bin<br \/>\ngifdec.bin<br \/>\nAudioTag.bin <-- significant, means case sensitive\nvplayer.bin\nfplayer.bin\naplayer.bin\nvideo.bin\nalarm.bin\ngameplay.bin\ngba_lib.bin\nnes_lib.bin\nsnes_lib.bin\nmd_lib.bin\nticru_lib.bin\ndcDecoder.bin\ndvEncoder.bin\ndcdv.bin\nmpcodecs_ad_liba52.bin\nmpcodecs_ad_hwac3.bin\nffmpeg64.bin\nffmpeg_vd_mpegmisc.bin\nffmpeg_vd_mpegmisc2.bin\nffpmeg_vd_mpegvideo.bin\nmpcodecs_vs_libmpeg2.bin\nffmpeg_vd_svq3.bin\nmpcodecs_vd_realvid.bin\naux_task.bin\n\n\ndesktoplib_simplen.bin\ndesktoplib_drawer.bin\ndesktoplib_slide.bin\ndesktoplib_tradition.bin <- chinese traditional\ndesktoplib_arena.bin\ndesktoplib_diorama.bin<\/code><\/p>\n<p>So, I know that that part is correct at least, as it really truly looks like proper data \ud83d\ude42<br \/>\nOther things of note.<\/p>\n<p>Our FAT part of the NAND, that is USB accessible is referred to internally as nfl: (Nand FLash I expect).<\/p>\n<p>Looks like our loader looks for these files in the user side:<\/p>\n<p>nfl:\\system\\music.img<br \/>\nnfl:\\system\\ebook.img<br \/>\nnfl:\\system\\desktop.img<br \/>\nnfl:\\system\\record.img<br \/>\nnfl:\\system\\system.cfg<br \/>\nnfl:\\system\\UPDATE.BIN  <\/p>\n<p>Filename strings are NULL terminated.<\/p>\n<p>There is also this:<\/p>\n<p>nfl:\\GAME  \\gamegameList<\/p>\n<p>This seems to be our mapping of game.zip -> proper name file (having taken a look at that).<br \/>\nWhich, is why when I added FBANext compatible stuff to the user FS, it complained that it was garbage, but still worked.  Lazy lazy lazy hardcoded file list, tsk tsk.<\/p>\n<p>Other other observations -<br \/>\nI was wrong on my guess about DMENU - its actually the bog standard uCOS-II File System dialog in use.<br \/>\nI was wrong about FBANext being used, it looks more like FBAPlus PSP was used, and our version still has the Exit to PSP dialog still in there, as well as the menu options for the framerate etc.  I guess I need to see how to bring that up, as that *is* useful!<br \/>\nMine says JZ4740 1.0sp1  Nov 19 2011 in the ROM.  Guess codebase for MINIOS is JZ4740 based?<\/p>\n<p>Lastly, and even more useful, there apparently is a Mini console - Mini CONSOLE V1.0<br \/>\nI need to see how to setup access, as that looks quite interesting...<\/p>\n<p>Guess I need to see if I can get the Ingenic RTOS\/uCOS-II stuff, unfortunately their FTP site has it, but the RAR file is broken, so it doesn't unrar completely.  This means we're missing all of the good bits that we need for reference.  I can give them a call Monday though, and see if they'd be interested in helping me out.  <\/p>\n<p>Pretty good progress though \ud83d\ude42<\/p>\n<p>Good reference on this:<br \/>\n<a href=\"http:\/\/code.google.com\/p\/dingoo-linux\/wiki\/DualBoot\">http:\/\/code.google.com\/p\/dingoo-linux\/wiki\/DualBoot<\/a><br \/>\n<a href=\"http:\/\/www.vogeeky.co.cc\/software\/minios\/struktura-minios\">http:\/\/www.vogeeky.co.cc\/software\/minios\/struktura-minios<\/a> (Russian)<br \/>\n<a href=\"http:\/\/micrium.com\/page\/downloads\/ports\/mips_technologies\">http:\/\/micrium.com\/page\/downloads\/ports\/mips_technologies<\/a> - MiniOS Mips code.  Useful more for how MINIOS does its stuff, than relevance to us.<br \/>\n<a href=\"http:\/\/forum.arcadecontrols.com\/index.php?topic=108550\">http:\/\/forum.arcadecontrols.com\/index.php?topic=108550<\/a> - The thread where I've been posting other findings on this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following up from my previous posts on this, looks like my idea&#8217;s are correct about the size of the NAND for setup, and my NAND read stuff works. Yay for me. Lets recap: JZ4755 boot sequence is as follows: CPU powers up. Checks BOOT_SEL line, takes appropriate action. boot_sel[1:0] 00 Unused 01 Initialization via USB [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[390,48,282,25],"tags":[414,391,416,413,393,417,415],"class_list":["post-861","post","type-post","status-publish","format-standard","hentry","category-arcade-machines","category-exploits","category-firmware-2","category-technical-mumbo-jumbo","tag-ingenic","tag-jamma","tag-jz4755","tag-mips","tag-reverse-engineering","tag-rtos","tag-ucos-ii"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=861"}],"version-history":[{"count":5,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":866,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/861\/revisions\/866"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}