{"id":579,"date":"2010-08-24T01:59:27","date_gmt":"2010-08-23T17:59:27","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=579"},"modified":"2010-08-24T02:16:05","modified_gmt":"2010-08-23T18:16:05","slug":"firmware-hackery-on-keychain-spycams-ak36xx-based","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2010\/08\/firmware-hackery-on-keychain-spycams-ak36xx-based\/","title":{"rendered":"Firmware hackery on Keychain &#8220;spycams&#8221; [AK36xx based]"},"content":{"rendered":"<p>As I&#8217;ve been busy with real life &#8482;, its been a while since I took a trip to the computer mall to see what new goodies I could play with.<\/p>\n<p>A friend is in town from Beijing, so took him down to the Shanzhai hell (or heaven depending on PoV) that is Qiu Jiang lu.<\/p>\n<p>I wasn&#8217;t aware that you could buy Keychain video recorders for 80rmb, but you can.  Apparently they&#8217;re even cheaper in eBay &#8211; although I don&#8217;t see how its possible, given that the factories here are pricing higher than they sell for in the States.  Rejects?<\/p>\n<p>Anyhow, I bought 2 keychain video camera&#8217;s, and an MP3 looking one.<\/p>\n<p><a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/imgA.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/imgA.jpg\" alt=\"(swiped from Chuck Lohr&#039;s post)\" title=\"imgA\" width=\"287\" height=\"250\" class=\"alignnone size-full wp-image-590\" \/><\/a><\/p>\n<p>Dissected one and it contains the Anyka AK3651B as the main chip.<\/p>\n<p>The AK36xx series is an SoC (System on a Chip).<\/p>\n<p><a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak36xx.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak36xx.jpg\" alt=\"\" title=\"ak36xx\" width=\"575\" height=\"388\" class=\"alignnone size-full wp-image-589\" srcset=\"https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak36xx.jpg 575w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak36xx-300x202.jpg 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/a><\/p>\n<p>As Anyka appears to be deathly afraid of giving out any useful information about their products, I&#8217;ve had to piece together info from what I found online.<\/p>\n<p>Their own product page here &#8211; <a href=\"http:\/\/www.anyka.com\/enProShow.asp?sortFlag=110&#038;sortName=Application%20Processor&#038;id=105\">http:\/\/www.anyka.com\/enProShow.asp?sortFlag=110&#038;sortName=Application%20Processor&#038;id=105<\/a><br \/>\nsays the following:<\/p>\n<blockquote><p>32-bit Microprocessor Core<br \/>\nIntegrated I\/D cache<br \/>\nMemory Management Unit (MMU)<\/p>\n<p>Video Coprocessor<br \/>\nMPEG4.SP codec<br \/>\nH.263 codec<br \/>\nMotion JPEG codec<\/p>\n<p>Audio Coprocessor<br \/>\nMP3 decoder<br \/>\nWMA decoder<br \/>\nAAC\/AAC+ decoder<br \/>\nAMR codec<br \/>\nReal-time audio stream in PCM\/ADPCM format<\/p>\n<p>Image Coprocessor<br \/>\nJPEG HW codec<\/p>\n<p>Glueless Dual LCD Displays<br \/>\nSupporting MPU LCD<br \/>\nSupporting RGB LCD<br \/>\nProgrammable LCD size and refreshing rate<\/p>\n<p>Connectivity<br \/>\nUSB 2.0 HS OTG<br \/>\nI2S master\/slave<br \/>\nUART<br \/>\nSPI<br \/>\nMMC\/SD<\/p>\n<p>Embedded ADCs and DACs<br \/>\nSAR ADC for touch panel and voltage detect<br \/>\nSigma-Delta ADC for microphone<br \/>\nSigma-Delta DACs for stereo<\/p>\n<p>Built-in Power Amplifier\/Headphone Driver<\/p>\n<p>External Memory Support<br \/>\nSupporting SDRAM<br \/>\nSupporting Nand Flash (SLC\/MLC, with hardware ECC)<\/p>\n<p>Package<br \/>\nLQFP 128-pin\/144-pin\uff0cFBGA 100-pin\/144-pin<\/p><\/blockquote>\n<p>Appears that they&#8217;re mostly used in MP3\/MP4 players, which is why most of my googling on specs was ruined by whiny users asking for someone to please help them with their foobar&#8217;d player.<\/p>\n<p>The first useful links on these are at Chuck&#8217;s pages here &#8211; <a href=\"http:\/\/www.chucklohr.com\/808\/\">http:\/\/www.chucklohr.com\/808\/<\/a><\/p>\n<p>He&#8217;s done a lot of useful work collating information, although some of his deductions are a little strange, so take some things with a pinch of salt.  Lots of good info though.<\/p>\n<p>The main source of info on the hardware side is at <a href=\"http:\/\/www.readerme.com\">http:\/\/www.readerme.com<\/a>, they have a most excellent section of downloads which provide more information on the chips than anything else out there!<\/p>\n<p>We gave them a call and had a chat (one of the benefits of being located in China, is that we obviously speak Chinese in the office!).<br \/>\nThey don&#8217;t speak great Mandarin though &#8211; so it was bad cantonesedarin or Mandonese?   Hmm, have to come up with a word for that!  (similar to Chinglish but mixing Cantonese and Mandarin).<\/p>\n<p>Both sides were laughing but we could at least talk to each other.   &#8220;Mo man tai, dui ma?&#8221;<\/p>\n<p>They actually don&#8217;t sell products, they only do design work for others, but, thats good to know.<br \/>\nThey did point us in the direction of a few trading companies that could do FOB export, but shipping quantities are in the x,000&#8217;s so not so useful yet.<\/p>\n<p>I&#8217;ll see if I can find the actual factories making these tomorrow.  (Although when I say we, I mean the staff).<br \/>\nThey did prove to be an excellent source of data on the chips though if one takes a look at the PDF&#8217;s on their site.<\/p>\n<p>The golden data trove is here &#8211; <a href=\"http:\/\/www.readerme.com\/html\/html\/%E7%9B%B8%E5%85%B3%E4%BA%A7%E5%93%81%E5%8E%9F%E7%90%86%E5%9B%BE%EF%BC%8C%E8%B4%B4%E7%89%87%E5%9B%BE.html\">http:\/\/www.readerme.com\/html\/html\/%E7%9B%B8%E5%85%B3%E4%BA%A7%E5%93%81%E5%8E%9F%E7%90%86%E5%9B%BE%EF%BC%8C%E8%B4%B4%E7%89%87%E5%9B%BE.html<\/a><\/p>\n<p>According to Anyka (\u5b89\u51ef in Chinese) the 36xx chips are a series, so they should have similar functionality.  <\/p>\n<p>While I don&#8217;t have data sheets, or a BSP, I can read the PDF&#8217;s at least to get an idea of where things are laid out.<\/p>\n<p>AK3631B<br \/>\n<a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/3631-pin-layout.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/3631-pin-layout-295x300.gif\" alt=\"\" title=\"3631 pin layout\" width=\"295\" height=\"300\" class=\"alignnone size-medium wp-image-583\" srcset=\"https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/3631-pin-layout-295x300.gif 295w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/3631-pin-layout-1009x1024.gif 1009w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/3631-pin-layout.gif 1217w\" sizes=\"auto, (max-width: 295px) 100vw, 295px\" \/><\/a><\/p>\n<p>AK3651B<br \/>\n<a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak3651b-BGA100.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak3651b-BGA100-296x300.gif\" alt=\"\" title=\"ak3651b BGA100\" width=\"296\" height=\"300\" class=\"alignnone size-medium wp-image-584\" srcset=\"https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak3651b-BGA100-296x300.gif 296w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/ak3651b-BGA100.gif 522w\" sizes=\"auto, (max-width: 296px) 100vw, 296px\" \/><\/a><\/p>\n<p>They do look similar, so probably only minor differences in functionality (probably the newer ones are cheaper?).<br \/>\nAgain, hard to check, as Anyka datasheets appear to be hens teeth.  <\/p>\n<p>I may give them a call also, and see if they&#8217;ll be willing to give us some info about their products, but I&#8217;m not holding my breath on that one.<\/p>\n<p>I&#8217;ve also poked around a bit in the firmware files using strings, and taking a look at headers, and have come up with some preliminary conclusions.<\/p>\n<p>I&#8217;m guessing their SoC is ARM5 based, given what i have found (haven&#8217;t decompiled yet, but looks like that).<\/p>\n<p>Some common strings in the firmware&#8217;s from start:<\/p>\n<p>00000 06 00 00 EA FE FF FF EA<\/p>\n<p>Googling &#8220;06 00 00 EA FE FF FF EA&#8221; comes up with some other people talking about firmware for pxa312 devices, which have exactly that in their boot loader, so, seems likely.<\/p>\n<p>The PXA312 is ARMv5TE&#8230;<\/p>\n<p>I&#8217;m guessing some playing around with radare (<a href=\"http:\/\/radare.nopcode.org\/get\/radare.pdf.html\">http:\/\/radare.nopcode.org\/get\/radare.pdf.html<\/a>) should get some more info about whats going on.<\/p>\n<p>Running strings on the firmware files available shows interesting info:<\/p>\n<blockquote><p>strings \/Documents\/Keychain\\ Camera\/cx311V2.04\/Spiboot_36XX.bin<br \/>\nANYKA362<br \/>\n  6KA49<br \/>\nstart read cfg<br \/>\nfile cnt:%d<br \/>\nfile name:%s<br \/>\nCannot find BIOS<br \/>\nread file info fail<br \/>\nload bios &#8230;&#8230;<br \/>\nmap:%d<br \/>\nfile len:%d<br \/>\nld addr:0x%x<br \/>\nLoad bios from spiflash successfuly!<br \/>\nread BIOS fail<br \/>\nspi boot start<br \/>\nsystem clock: %d<br \/>\nBIOS<\/p>\n<\/blockquote>\n<p>Thats our 4k bootloader, which obviously loads our 1M bios image from SPI flash memory (SPI = Serial Peripheral Interface)<br \/>\nMore on SPI here.<br \/>\n<a href=\"http:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\">http:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus<\/a><\/p>\n<p>Hmm, more reasons for me to get a Bus Pirate now&#8230;<\/p>\n<p>We have a flasher also, although its Windows based.<br \/>\nI&#8217;m guessing some USB sniffing will lead to some magic byte handshake sequence to get into the bootloader via USB, as the BIOS strings point to that.<\/p>\n<p>eg: <\/p>\n<blockquote><p>&#8220;The setup packet is not 8 byte!&#8221;\n<\/p><\/blockquote>\n<p>Also amusing is that its fairly easy to find the FAT32 code embedded in at least one of the firmwares<\/p>\n<p>EB xx 90 &#8230; -> 55 AA (in Sprint1M.bin)<\/p>\n<p><a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/hex-view-of-spring1m.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/hex-view-of-spring1m.gif\" alt=\"\" title=\"hex view of spring1m\" width=\"646\" height=\"218\" class=\"alignnone size-full wp-image-581\" srcset=\"https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/hex-view-of-spring1m.gif 646w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/hex-view-of-spring1m-300x101.gif 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/a><\/p>\n<p>The flasher tool is also nice enough to give us an idea of layout in the 1M flash chip.<\/p>\n<p>You&#8217;ll need to install the Anyka M3 USB driver to talk to the chip, which appears to have the following attributes via USB:<br \/>\nVendor ID: 0471<br \/>\nProduct ID: 0666  (the product of the beast? hehe)<\/p>\n<p>This is a bit naughty, as 0471 is in theory already taken by  Philips (or NXP) according to <a href=\"http:\/\/www.linux-usb.org\/usb.ids\">http:\/\/www.linux-usb.org\/usb.ids<\/a><\/p>\n<p>Its also astoundingly obvious that they used driverworks to make the driver. (From the oh so copied in China vid\/pid, and the strings left in the driver).  An example of this here <a href=\"http:\/\/www.baiheee.com\/OpenSource\/Easy%20USB%2051%20Programer\/Easy%20USB%2051%20Programer_DriveOurBoard.htm\">http:\/\/www.baiheee.com\/OpenSource\/Easy%20USB%2051%20Programer\/Easy%20USB%2051%20Programer_DriveOurBoard.htm<\/a><\/p>\n<p>Want to bet someone read those instructions and its been repeated ad nauseum?<br \/>\nSadly, its so easy to see the minimal effort that&#8217;s gone into things.<\/p>\n<p>Back to our flasher, it says that our 1M chip is laid out as follows:<\/p>\n<blockquote><p>###Project Name<br \/>\nproject name = chaoxian<\/p>\n<p>###Devie Number<br \/>\ndevice channel = 8<\/p>\n<p>###COM<br \/>\ncom bOpen = 0<br \/>\ncom base = 1<br \/>\ncom count = 1<br \/>\ncom baud rate = 38400<\/p>\n<p>path producer sundance2 = producer_sundance2.bin<br \/>\npath producer sundance2A uboot = producer_sundance2A_uboot.bin<br \/>\npath producer sundance2A umass = producer_sundance2A_umass.bin<br \/>\npath nandboot sundance2= Spiboot_36XX.bin<br \/>\npath nandboot sundance2A= Spiboot_36XX.bin<\/p>\n<p>bios run addr = 0x30500000<br \/>\nbios start addr = 0xc0000<br \/>\nbios end addr = 0x1c0000<br \/>\nbios backup start addr = 0x1c0000<br \/>\nbios backup end addr = 0x2c0000<\/p>\n<p>chip type = AK_3225<br \/>\nchip uboot = 1<br \/>\nchip power off gpio = 255<br \/>\nchip usb2 = 0<br \/>\nchip get aid = 0<br \/>\nchip update = 0<br \/>\nchip select loop = 1<br \/>\nchip select nand0 = 1<br \/>\nchip select nand1 = 1<br \/>\nchip select nand2 = 1<br \/>\nchip select nand3 = 1<br \/>\nchip gpio_ce2 = 255<br \/>\nchip gpio_ce3 = 255<\/p>\n<p>ram size = 8<br \/>\nram row = 12<br \/>\nram column = 8<br \/>\nram bank = 4<\/p>\n<p>moduleburn DownloadMode = 2<br \/>\nmoduleburn bDownloadFLS = 1<br \/>\nmoduleburn bDownloadEEP = 1<br \/>\nmoduleburn baudrate = 921600<br \/>\nmoduleburn gpio_dtr = 85<br \/>\nmoduleburn gpio_module_igt = 109<br \/>\nmoduleburn gpio_module_reset = 87<br \/>\nmoduleburn path_fls = LCG2.fls<br \/>\nmoduleburn path_eep = LCG2.eep<\/p>\n<p>fs start addr = 0x6c0000<br \/>\nfs reserver block = 64<br \/>\nfs nonfs reserve size = 4<\/p>\n<p>partition count = 0<\/p>\n<p>download_to_udisk count = 0<\/p>\n<p>download_to_nand count = 3<br \/>\ndownload_to_nand1 = 0, Spring1M_bios.bin, 0x30500000, BIOS<br \/>\ndownload_to_nand2 = 0, Spring.bin, 0x30000000, MMI<br \/>\ndownload_to_nand3 = 0, AkResData.Bin, 0x0, RES<\/p>\n<p>download_to_mtd count = 0<\/p>\n<p>nand supported count = 0\n<\/p><\/blockquote>\n<p>If we take a look at that, our Spring1M_bios.bin starts off at C000<br \/>\n(bios start addr = 0xc0000)<br \/>\n(Deduct a 0 as we&#8217;re not offset by 0x300000000)<\/p>\n<p>A look in a hex editor at that position shows:<\/p>\n<p><a href=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/spring1M_bios-0xc000.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/spring1M_bios-0xc000.gif\" alt=\"\" title=\"spring1M_bios 0xc000\" width=\"649\" height=\"204\" class=\"alignnone size-full wp-image-585\" srcset=\"https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/spring1M_bios-0xc000.gif 649w, https:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/08\/spring1M_bios-0xc000-300x94.gif 300w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/a><\/p>\n<p>Note the 32bit word value &#8211; 0xE1A0C00D<\/p>\n<p>Thats classic ARM, so we _know_ its arm based&#8230;<\/p>\n<blockquote><p>romStart [0xe1a0c00d] mov r12,r13<\/p><\/blockquote>\n<p>Our next line of code is exactly the same as listed here <a href=\"http:\/\/code.google.com\/p\/milestone-overclock\/wiki\/Disassembly\">http:\/\/code.google.com\/p\/milestone-overclock\/wiki\/Disassembly<\/a><\/p>\n<blockquote><p> e1a0c00d        mov     ip, sp<br \/>\n e92dd8f0        push    {r4, r5, r6, r7, fp, ip, lr, pc}<\/p><\/blockquote>\n<p>So its looking like we can basically disassemble the code using  arm-none-linux-gnueabi-objdump<\/p>\n<p>I&#8217;ll leave that for another day, but with a bit more work we could compile our own code for this as we now have a good idea of the target cpu.<\/p>\n<p>The next step would be to get into the bootloader or debug mode via USB, and see what can be seen.<\/p>\n<p>Tools used:<\/p>\n<p>0xED &#8211; <a href=\"http:\/\/www.suavetech.com\/0xed\/0xed.html\">http:\/\/www.suavetech.com\/0xed\/0xed.html<\/a><br \/>\nA nice fast and compact hex viewer for OSX.<\/p>\n<p>strings &#8211; built into most *nix based systems.<\/p>\n<p>Grey matter &#8211; Available to all, unused by many \ud83d\ude09<\/p>\n<p>Now hopefully I can get back to the Webcam firmware stuff as I&#8217;ve been promising to do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I&#8217;ve been busy with real life &#8482;, its been a while since I took a trip to the computer mall to see what new goodies I could play with. A friend is in town from Beijing, so took him down to the Shanzhai hell (or heaven depending on PoV) that is Qiu Jiang lu. [&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":[48,25],"tags":[276,277,278,279,281,280],"class_list":["post-579","post","type-post","status-publish","format-standard","hentry","category-exploits","category-technical-mumbo-jumbo","tag-ak3651b","tag-ak3xx","tag-anyka","tag-ck808","tag-hacking-firmware","tag-keychain-video-camera"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/579","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=579"}],"version-history":[{"count":6,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/579\/revisions"}],"predecessor-version":[{"id":588,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/579\/revisions\/588"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}