How to update NK from SD card? -- (Implemented)

Source: Internet
Author: User

Author: gooogleman@foxmail.com

Some time ago, songtitan Niu mentioned in the forum how to update NK using SD card. As follows:

Http://topic.csdn.net/u/20081009/17/4E0F5E66-C7A0-43D2-B33F-14E132280F70.html

 

You can update NK in CE and bootloader.
1 under CE
You can directly use the file system API to read NK. Bin and put it into the memory buffer. You can use deviceioctl to call the interface of the NAND driver to directly write the NAND Flash.

Benefits: Skip the boot section and parse the fat/FAT32 file system; no requirements on memory size
Disadvantage: The NAND driver must expose the read/write IOCTL and must enter the OS to update the OS. If the OS crashes, it cannot be updated.

2 bootloader
Directly perform the SD controller operation to read and write the SD card, parse the fat/FAT32 format, and find the NK. bin, and can read it into the memory, and then assume that NK. if the bin is downloaded to the memory, it is burned to the NAND Flash.

Benefits: you can update the OS as long as the bootloader is not mounted;
Disadvantage: You need to resolve the boot secion and fat/FAT32 file systems by yourself. You need at least the remaining RAM with the same size as NK. Bin.

 

If BSP does not support SD-based NK update under bootloader, it will take a lot of work to study for itself. The best shortcut is to "get" The SD update code of other platforms, the changes are only part of the SD host controller.

==================================== Now my job is to figure out how to implement this ================================

The company asked to implement SD update NK in the bootloader stage, and said it was too difficult to implement touch screen menus in the streaking stage to implement touch screen operations. If you have to implement it, you must add the GUI. the bootloader is so big that it makes no sense. I now think there is a feasible method: to stop using the SD card to update NK, but to back up a NK in flash, and put the backup NK ON THE started NK during the update. In this way, the modification of bootloader is simple, and it is not difficult to implement it after wince. Now flash has more than 1 GB, and the loss of capacity is not a problem, and the SD card also makes room-Haha, well, just imitate ghost to make an embedded recovery genie.

========================================================== ========================================================== ====

-After several days of thinking, I think it is a bit inappropriate to back up data on flash, because Flash is sometimes unstable and prone to problems. Now we decided to use the system to update NK. I am honored to have a good old post here ---------------------------------------------- read all the content in Flash Under wince.

Bytes.

--------------------------------------------------------------------------

Hardware: 2410, 64 m nandflash, 64 m Ram

Now I want to read all the content from address 0 to nandflash under wince,
What should I do!

It is like backing up a ghost on a desktop computer. The difference is that we need to read the data where nandflash is empty!

Urgent. Thank you.

--------------------------------------

Depends on whether your file system supports. because the file system can only identify the partition, the blank areas without partitions cannot be accessed through the wince API. generally, Flash has a dedicated reader to directly copy the content of the chip, that is, the tool used as the master chip during production.

--------------------------------------

I'm afraid I can only write a simple Flash Driver by myself, and read it from start to end. The fat file system of Wince certainly cannot read in the order of the flash physical address.

--------------------------------------

The last layer of NAND is the disk interface, so there is no corresponding API for you to read all the content.

If the driver can be modified, let the driver open a special iocontrl code to you, enter the address range, and the output is to put all the data within the address range to the specified Buf pointer address. Modify the fmd_oemiocontrol function for the drive of NAND Flash.

-----------------------------------------------------------------

It is a standard stream interface. In fact, you can still use the DSK driver, but you have designed an iocontrol_code that is not originally available. When the iocontrol () function of the device is passed down, iocontrol in the drive of NAND Flash directly determines that if the parameter is met, all data within the specified range will be read to the specified address space.

There is a small error on the 9th floor. The READ function of the NAND driver has performed ECC verification. The data read through functions such as fmd_nand_read does not need ECC verification.

------------------------------------------------------------------------


Reply to reference so927 on the 13th floor:

Reply to reference the jlctt on the 12th floor:
Modify the fmd_oemiocontrol code in FMD, open the fmd_readsector/fmd_writesector interface for access, and then use deviceiocontrol to access the entire NAND Flash.

I understand what you mean. I think this can also be done. Thank you for reminding me,

But there is another question: Will I read the bad block together? Do I need to check whether it is a bad block for each read?

Yes, you need

========================================================== = Copy end ============================================== =

 

-- In the past few days, I first learned how to read and write the SD card program in EVC. At first, I thought I could malloc dozens of MB of memory like a PC, the results showed that it was very slow to read a K tablet. It seems that the idea of one-time read/write of 30 m is not feasible. Today, the 30 m Kernel File is successfully read and written in segments. The following is the key code.

C/C ++ code
   
   
  1. // It is feasible for me to read 30 m Files and store them in one file. It's time to modify the flash drive. Go back and close the post at night.
  2. // ============================ Read data from the file in segments, 30 K each time, read 1024 times, A total of 30 m ==============================
  3. For (unsigned int COUNT = 0; count <readcount; count ++)
  4. {
  5. Setfilepointer (hfile, m_filepointer, null, file_begin);/* move the file pointer to the beginning of the file */
  6. If (ret = 0 xffffffff)
  7. {
  8. MessageBox (_ T ("failed to move the file pointer to the specified object! "));
  9. Return;
  10. }
  11. Pcharbuff = (char *) malloc (readsize); // 30 kb of memory is applied each time.
  12. Ret = readfile (hfile, pcharbuff, readsize, & actlen, null);/* read data from the file in segments, 30 K each time */
  13. If (ret = false)
  14. MessageBox (_ T ("An error occurred while reading the file! "));
  15. // -------------------- Write read file to wogo. nb0 -----------------------
  16. // -- Read 30 K and write 30 K
  17. Setfilepointer (htestfile, m_filepointer, null, file_begin);/* move the file pointer to the beginning of the file */
  18. If (ret = 0 xffffffff)
  19. {
  20. MessageBox (_ T ("failed to move the file pointer to the specified object! "));
  21. Return;
  22. }
  23. Ret = writefile (htestfile, pcharbuff, readsize, & writelen, null);/* write data to the file */
  24. If (ret = false)
  25. MessageBox (_ T ("failed to write file! "));
  26. Free (void *) pcharbuff); // release the memory
  27. M_filepointer = m_filepointer + readsize; // move the pointer down to 30 K each time
  28. // If (COUNT = 1023)
  29. //{
  30. // MessageBox (_ T ("file read successful! "));
  31. //}
  32. }
-- In addition to understanding the wince virtual memory application, we can also conclude that: whether it is a binary file or a text file,
The read/write functions are the same. To read binary data and display it, you cannot use the text file display method.
==================================== Flash Driver modification section ========== ======================================

Bytes
-- Applications directly control flash

============================================= The method for updating NK is successfully run using WinCE ======================================

-- Key points are now published.

I. Add the following code to FMD:

  1. //------------------------------------------------------------------------------
  2. // ----------------------------- Direct communication between applications and flash ------- hope you can see the inspiration ---
  3. //------------------------------------------------------------------------------
  4. Static DWORD g_dwstartsector = 2*64;
  5. Bool fmd_oemiocontrol (DWORD dwiocontrolcode, pbyte pinbuf, DWORD ninbufsize, pbyte poutbuf, DWORD noutbufsize, pdword pbytesreturned)
  6. {
  7. Switch (dwiocontrolcode)
  8. {
  9. Case 0x77777777:
  10. For (unsigned int I = 2; I <= 242; I ++) // 30 m NK occupies 240 Blocks
  11. Fmd_eraseblock (I); // detect the area occupied by NK for 30 m
  12. Retailmsg (1, (text ("fmd_oemiocontrol: Recognized IOCTL. fmd_eraseblock (0x % x)./R/N"), dwiocontrolcode ));
  13. Break;
  14. Case 0x12345678:
  15. // The area occupied by NK writing. This depends on the function in eboot to know the specific starting block.
  16. // Retailmsg (1, (text ("fmd_oemiocontrol: Recognized IOCTL. fmd_writesector (0x % x)./R/N"), dwiocontrolcode ));
  17. Retailmsg (1, (text ("fmd_oemiocontrol: Recognized IOCTL. fmd_writesector (0x % x)./R/N"), ninbufsize ));
  18. Retailmsg (1, (text ("fmd_oemiocontrol: ninbufsize = % d./R/N"), ninbufsize ));
  19. // For (unsigned int K = 0; k <ninbufsize; k ++)
  20. //{
  21. // Fmd_writesector (g_dwstartsector, pinbuf, null, 1 );
  22. // G_dwstartsector = g_dwstartsector + 1;
  23. //}
  24. // The parameter of the fmd_writesector function is critical. pinbuf is input by the application and the size can only be one page.
  25. // Code of fmd_writesector can be inferred, and pinbuf can only be one page
  26. Fmd_writesector (g_dwstartsector, pinbuf, null, 1 );
  27. If (g_dwstartsector <= 242*64)
  28. G_dwstartsector = g_dwstartsector + 1;
  29. Break;
  30. Default:
  31. Retailmsg (1, (text ("fmd_oemiocontrol: Unrecognized IOCTL (0x % x)./R/N"), dwiocontrolcode ));
  32. Return (false );
  33. }
  34. Return true;
  35. }

Reprinted Please note: the author wogoyixikexie @ gliet. Guilin University of electronic science and technology, a Department of Science and Technology Association. If you have any mistakes, I hope you can leave a message to point out. If you have a better method, please leave a message after your blog. I will be grateful for your criticism and sharing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.