S3C6410 uses ---10 to add menu menu to uboot of SD card and NAND FLASH

Publisher:SparklingDreamsLatest update time:2018-04-15 Source: eefocusKeywords:S3C6410  NAND  FLASH  uboot Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When burning with ok6410, you need to type a lot of commands every time, which is time-consuming and laborious. I remember that when I used TQ2440 before, there would be a menu when u-boot started. Just press a number key to burn the kernel, which was very convenient.
Now this SD card has comprehensive functions. It can not only boot directly from the SD card, but also burn the u-boot zImage rootfs in the nand flash. Hehe.
Now add this function to the u-boot of ok6410.
1. Modify the u-boot1.1.6 of the SD card
1. common/main.c

  1. void main_loop (void)

  2.      .......  

  3.     if (bootdelay >= 0 && s && !abortboot (bootdelay)) {

  4.     }


  5.     //If a key is pressed during the startup process, the execution process is interrupted

  6.     run_command("menu",0);   

  7.     

  8.     //If the menu returns, enter the u-boot shell

  9.     #ifdef CFG_HUSH_PARSER
        parse_file_outer();

  10.     ......   

  11. }

2. The process of executing menu,
run_command("menu", 0), will eventually execute do_menu.
do_menu prints out the command menu at the beginning, and then executes different commands according to different selections.
So the added file common/cmd_menu.c is as follows:

  1. #include

  2. #include

  3. #include

  4. #include


  5. void print_menu_usage(void)

  6. {

  7.     printf("rn##### SD boot Menu #####rn");

  8.     printf("[1] Download u-boot bootloader to Nand Flashrn");

  9.     printf("[2] Download Linux Kernel to Nand Flashrn");

  10.     printf("[3] Download CRAMFS image to Nand Flashrn");

  11.     printf("[4] Download YAFFS image to Nand Flashrn");

  12.     printf("[5] Boot the systemrn");

  13.     printf("[6] Format the Nand Flashrn");

  14.     printf("[0] Set the boot parametersrn");

  15.     printf("[a] Download User Program (eg: uCOS-II or TQ2440_Test)rn");

  16.     printf("[b] Download LOGO Picture (.bin) to Nand Flash rn");

  17.     printf("[q] quit from menurn");

  18.     printf("Enter your selection: ");

  19. }


  20. int do_menu(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

  21. {

  22.     int c;

  23.     char cmd_buf[200];

  24.     while(1)

  25.     {

  26.         print_menu_usage();

  27.         c = getc();

  28.         printf("%cn", c);

  29.         switch (c)

  30.         {

  31.             case '1':

  32.             {

  33.                 strcpy(cmd_buf, "fatload mmc 0:1 50008000 u-boot.bin_nand; nand erase 0 100000; nand write.uboot 50008000 0 10000");

  34.                 run_command(cmd_buf, 0);

  35.                 break;

  36.             }

  37.             case '2':

  38.             {

  39.                 strcpy(cmd_buf, "fatload mmc 0:1 50008000 zImage_nand; nand erase 100000 500000; nand write.e 50008000 100000 500000");

  40.                 run_command(cmd_buf, 0);

  41.                 break;

  42.             }

  43.             case '3':

  44.             {

  45.                 //strcpy(cmd_buf, "fatload mmc 0:1 50008000 u-boot.bin; nand erase 0 100000; nand write.uboot 50008000 0 10000");

  46.                 //run_command(cmd_buf, 0);

  47.                 break;

  48.             }

  49.             case '4':

  50.             {

  51.                 //strcpy(cmd_buf, "fatload mmc 0:1 50008000 rootfs.yaffs; nand erase 600000 4A4000; nand write.yaffs2 50008000 600000 4A4000");

  52.                 //strcpy(cmd_buf, "fatload mmc 0:1 50008000 rootfs.yaffs; nand erase 600000 $(filesize); nand write.yaffs2 50008000 600000 $(filesize)");            

  53.                 //Note: nand erase 600000 $(filesize), if there is a bad block, data cannot be written, so this place can be fixed to a larger value, such as

  54.                 // 0x1400000=20M, so the size of rootfs.yaffs cannot exceed 20M,

  55.                 //Consider whether to add a nand flash partition here: nand erase root, erase the entire root partition, so you don't have to worry about whether there are bad blocks

  56.                 strcpy(cmd_buf, "fatload mmc 0:1 50008000 rootfs.yaffs; nand erase 600000 1400000; nand write.yaffs2 50008000 600000 $(filesize)");                          

  57.                 run_command(cmd_buf, 0);

  58.                 break;

  59.             }

  60.             case '5':

  61.             {

  62.                 strcpy(cmd_buf, "bootm 50008000");

  63.                 run_command(cmd_buf, 0);

  64.                 break;

  65.             }

  66.             case 'q':

  67.                 return;

  68.             default:

  69.                 printf("command not found\n");

  70.                 break;

  71.         }

  72.     }

  73. }


  74. U_BOOT_CMD(

  75.         menu, 5, 1, do_menu,

  76.         "menu - manipulate BMP image datan",

  77.         "menu long help: TNND mu you"

  78.         );

3. Add to Makefile
Finally, add a line to common/Makefile

  1. COBJS+= cmd_menu.o

Note: When combining commands, what if you don't know the size of the file to be burned in nand write? It doesn't matter, there is a variable $(filesize). As long as you add this, any problem will no longer be difficult.
The above 50008000 is the memory address to be read when booting from the SD card; if booting from Nand flash, change the above 50008000 to C0008000


2. Test
2.1 sd card
      a. Because data is read from the SD card and the first partition, the first partition format must be FAT32 when partitioning the SD card.
      b. Compile u-boot.bin: 
                The code should use the u-boot included in the CD, which supports booting from nand flash.
                Make forlinx_nand_ram256_config, then generate u-boot.bin
                and copy it to the first partition of the SD card, and rename it to u-boot.bin_nand (to be consistent with the name in the u-boot code)
      c. Compile zImage
                code with linux-3.0.1 included in the CD, make and generate zImage
                and copy it to the first partition of the SD card, and rename it to zImage_nand (to be consistent with the name in the u-boot code)
      d. Generate rootfs.yaffs
                with FileSystem-Yaffs2.tar.gz included in the CD, After decompression, it is too big, so delete the unnecessary ones.
                The busybox in it seems to be dynamically linked, so compile a static busybox yourself, and finally generate rootfs.yaffs
                sudo /opt/6410/4.3.2/bin/mkyaffs2image-nand2g FileSystem-Yaffs2 rootfs.yaffs
                nand flash is 2G, so use the command mkyaffs2image-nand2g
               to copy rootfs.yaffs to the first partition of the SD card (to be consistent with the name in the u-boot code)
         Note: If you are not sure whether there is a problem with the rootfs itself, you can start from nfs first to see if it is normal.
                  If it is normal, use mkyaffs2image-nand2g to make a yaffs image and burn it into the nand flash.


3. NAND Flash added to menu
  3.1 The files of NAND flash are obtained through USB, of course, it can also be obtained through TFTP (TFTP has not been tried, but the principle is the same)

  1. Will strcpy(cmd_buf, "fatload mmc 0:1 50008000 u-boot.bin_nand; nand erase 0 100000; nand write.uboot 50008000 0 10000");

  2. Change to -->:

  3. strcpy(cmd_buf, "dnw c0008000; nand erase 0 100000; nand write.uboot c0008000 0 10000");

  4. Or --> (haven't tried this)

  5. strcpy(cmd_buf, "tftp c0008000 u-boot.bin; nand erase 0 100000; nand write.uboot c0008000 0 10000");

3.2 Solve a small problem of USB transmission.
     The following is the printed log:
    the downloaded file size is 0x420000, the nand flash erase size is 0x1400000, but it becomes 0x7fa00000 when nand write.yaffs2.

  1. Enter your selection: 3

  2. OTG cable 

  3. Now, Waiting for DNW to transmit data

  4. Download Download Address: 0xc0008000, Download Filesize:0x420000 

  5. Checksum is being calculated....calc checksum=0xba1c, read checksum=0xba1c, start:


  6. Checksum OK


  7. NAND erase: device 0 offset 0x600000, size 0x1400000

  8. Skipping bad block at 0x00780000 

  9. Erasing at 0x1980000 -- 100% complete.

  10. OK


  11. NAND write: device 0 offset 0x600000, size 0x7fa00000

  12. Input block length is not page aligned

  13. Data did not fit into device, due to bad blocks

  14.  2141192192 bytes written: ERROR


  15. ##### NAND boot Menu #####

This is because after the USB transfer is completed, the size of the received file is not saved.
The solution is as follows: 
in cpu/s3c64xx/usbd-otg-hs.c

  1. void s3c_usb_verify_checksum(void)

  2. {

  3.     u8 *cs_start, *cs_end;

  4.     u16 dnCS;

  5.     u16 checkSum;

  6.     int i;

  7.     printf("Checksum is being calculated.");

  8.     char buf[12];

  9.     long size;

  10.     /* checksum calculation */

  11.     cs_start = (u8*)otg.dn_addr;

  12.     cs_end = (u8*)(otg.dn_addr+otg.dn_filesize-10);

  13.     checkSum = 0;

  14.     while(cs_start < cs_end) {

  15.         checkSum += *cs_start++;

  16.         if(((u32)cs_start&0xfffff)==0) printf(".");

  17.     }


  18.     dnCS = *(u16 *)cs_end;

  19.     printf("calc checksum=0x%x, read checksum=0x%x, start:n", checkSum, dnCS);


  20.     if (checkSum == dnCS)

  21.     {

  22.         //Add the following paragraph to record the size of the received file    

  23.        size = otg.dn_filesize-10;

  24.        sprintf(buf, "%lX", size);

  25.        printf("nChecksum OK down filesize=%ldn", size);

  26.        setenv("filesize", buf);

  27.     }

  28.     else

  29.     {

  30.         printf("nChecksum Value => MEM:%x DNW:%xn",checkSum,dnCS);

  31.         printf("Checksum failed.nn");

  32.     }


  33. }


Keywords:S3C6410  NAND  FLASH  uboot Reference address:S3C6410 uses ---10 to add menu menu to uboot of SD card and NAND FLASH

Previous article:Analysis of the process of writing yaffs2 file system using ---11uboot on S3C6410
Next article:S3C6410 usage --- SD initialization and reading and writing analysis in 7uboot

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号