Thursday, August 6, 2009

Workaround for showstopper card write corruption

I've been lately throwing some serious time on this issue. It is a slow process because each trial-and-error iteration takes about 5 minutes (must write hundreds of MB to get the corruption to show up). I'm checking the SD/MMC code line by line with the aid of the leaked JZ4740 manuals (which are far far far from being clear), comparing the driver kernel code to the uCOS-II code also released by Ingenic (I've got the feeling it is a bit more up to date) and so on. I've fixed the DMA round robin prioriry bug, which was of course not the cause of the corruption, fixed some other apparent bugs in the jz_mmc.c code, and I'm testing everything that comes to my mind, including slowing down the SD/MMC clock. But it is a slow process, please be patient. There's also the possibility that I can have access to further Ingenic documentation (will comment on this in another post) which could help on this issue.

Well, the good news is that one of the things I tried worked: setting the SD/MMC interface in 1-bit mode (instead of 4-bit) seems to fix the corruption. The downside is that the throughput goes down the drain (yeah, you guessed it, one fourth of throughput of the 4-bit mode). I was about to say that this pretty much rules out a DMA related problem, but I'm not sure that's 100% true since lower throughput also means lower stress on the DMA subsystem which could avoid the glitch or corner case causing the corruption. Anyway, the main suspect is still the SD/MMC interface, either the silicon or the A320 hardware. My bet so far is that the code is not properly detecting and handling an error condition that arises during writes.

I'll be preparing today a new release of dual-boot and system packages. Besides the SD/MMC interface in 1-bit mode, it will include some other improvements like support for partitionless cards.

26 comments:

  1. Great news Booboo, i'd rather have a slow medium then a corrupted medium ;) As a thank you i just donated ^^

    ReplyDelete
  2. Is it possible to do reads in 4-bit mode and writes in 1-bit mode? Or can reads also get corrupted?

    ReplyDelete
  3. @mth

    Corruption happens on writes only.

    What you propose is in theory possible, but very complex to implement. In linux there is a core code that handles standard card commands and then there are "host" drivers which just provide the functions to do the low level communication with the card. Separate 4-bit reads and 1-bit writes would require extensive changes to both the core and the host driver code.

    ReplyDelete
  4. booboo, i was wondering, is it possible to include 'shutdown' in the rootfs? Or is there another way to actually power down the machine without first rebooting into the native OS?

    ReplyDelete
  5. @Ochal

    Powerdown is one of the yet missing features. If you hold the power slider for 5 seconds dingux will reboot.

    I've go some schematics of similar chinese PMP using the JZ4740 that gave a hint on how power off is implemented, so it should be soon working (don't know what "soon" is with summer vacation right around the corner, sorry).

    ReplyDelete
  6. perhaps its a hardware error.
    Are there any plans to add a option to mount the internal SSD?

    fdisk, won't display anything and mounting any device fails.

    ReplyDelete
  7. @n

    No, dingux is not mounting the internal NAND flash and most likely will never until it is mature enough as to replace the firmware and so be itself installed on the NAND.

    This is because in NAND devices there is a translation layer between physical flash memory and the block device upon which file systems are mounted. This layer manages wear leveling, bad blocks and such, and EACH OS IMPLEMENTS IT ITS OWN WAY. This means the linux way is not compatible with the original firmware's way. Of course linux could be adapted, but first the original firmware translation scheme would have to be reverse engineered, and it is a HUGE task, plus mistakes would be VERY expensive (imagine a bug that trashes the contents of internal flash).

    ReplyDelete
  8. Booboo, having the bootloader default to linux would be cool though ;) Sometimes i forget to press select :D

    ReplyDelete
  9. no i don't want it to be default. thats because dingux is not working properly right now.

    ReplyDelete
  10. Sience, fair enough ;)

    @Booboo: Any news about the new release?

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. @Ochal

    Delayed. I'm leaving on vacation today and had a mad day tidying up at work (it's 03:20 local time and I'm leaving office now). I think I'll be back online tomorrow evening and will upload the new release.

    ReplyDelete
  14. No problem, enjoy your vacation! ;)

    ReplyDelete
  15. On the subject of defaults, I wonder if the bootloader couldn't just use some sort of configuration file (sort of like Syslinux for example, though obviously much simpler.) First, this could make it possible to set whether or not it boots linux by default on an individual basis such that it can still default to the original OS but allow those who want it to boot straight to linux to set it to do so. It seems to me like it shouldn't be too hard to implement a simple way of just checking such a setting (perhaps even just simply looking for the presence of a particular file, let's say linux.def.) A more complex system (which obviously would have to come later if it did) might be able to do things like specify different startup scripts and even what kernel to load (useful if anyone ever wanted to use the same card for two different model A320s.)

    Probably not easy to implement and maybe it would be too improbable, but I just thought I'd point out the possibility at least. (Personally, I'm glad it still defaults to the original OS. I use my A320 for stuff like reading more than anything else in fact and often have music playing in the background. I don't think anyone has ported anything for Dingux to do this much yet.)


    BTW, one thing I was wondering about. Originally I thought Dingux wasn't working with FAT32, but later found out that this was because it won't work with the formatting I was using. Namely, I was using the Panasonic SD formatter. They claim that normal formatting isn't actually correctly to SD specs and that their tool formats in such a way as to fully follow specs. (And really I don't think they have any specific reason to lie given that they let people download the software for free and run it on any memory card reader or card.) Up until now, it has worked on everything I've ever tried it on (including every card reader I've used and the stock OS on the A320,) but for some reason it doesn't work with the Dingux bootloader. I was wondering first if there really was any benefit to the Panasonic SD formatter, and, if so, is there any chance the Dingux bootloader could support it?

    ReplyDelete
  16. The Panasonic SD formatter makes the transfer rate much faster in my experience. It also makes the card more responsive in terms of browsing directories in Windows.

    I think what it does is format the card using a 4K cluster size.

    ReplyDelete
  17. Using 4k clusters should be possible in Linux aswell, wether that is the sole reason why it would be more 'responsive' i'm not too sure, a flash medium shouldn't be affected much by cluster size i think? You already have zero seek times

    ReplyDelete
  18. Qi Hardware folks has the same problem:

    http://nanl.de/blog/2009/08/openwrt-on-the-ben-nanonote/

    ReplyDelete
  19. Hi! I got today my Dingoo. I'm using a 16GB micro Sd with mini adapter and dingux doesn't work with it, it freezes in Dingux screen. The SD workss great with original firmware. Also, I copied all files on a 2GB SD and Dingux works fine from there, so it's not an instalation problem, it seems to be that Dingux doesn't work on my SD (Sandisk). Also, I tried runnig dingux from 2GB sd, and when it's loaded, change the SD and tried running any app. It freezes again. Will compatibility be improved in future versions?

    ReplyDelete
  20. Alphos, might be the formatting of the SD card itself, tried reformatting it?

    ReplyDelete
  21. Hi,

    I run Dingux on a 2gb card and its worked perfectly from day one. Let's me save on all games which have save states, including the SCUMMVM games.

    ReplyDelete
  22. @Ochal

    Thanks. I'm already in touch with them, but theirs looks like it's a different problem. They have trouble recognizing the card while in our case everything works fine except for occasional data corruption on writes.

    ReplyDelete
  23. Thanks Ochal, but it's a different problem. I contacted yesterday by email with Booboo because blogger always gave me errors when I was triying posting that comment, but now I see It was finally posted!!

    ReplyDelete
  24. I tried to flash my dingoo with new dual boot installer. All steps was correct, but when dingoo have to turn on and boot linux nothing happened!
    All my attempts to load/reload the device was unsuccessful. The screen did not turn. When connected to usb - device is not identified on PC. What should I do?

    ReplyDelete
  25. Excuse me for my panic. In process, my dingoo suddenly is ended charge of accumulator. Therefore dingoo was not turn on. All ok.

    ReplyDelete