How to add menu to the uboot of NAND Flash and SD card

2025-03-06 15:38:31 admin

For SD NAND, when using the ok6410 to program, we need to write a lot of commands each time, which is time-consuming and laborious. But using the TQ2440 to program, there will be a menu when the u-boot starts. You can just press a number key to burn-in the kernel image, which is very convenient.

 

Now this SD NAND is with comprehensive functions. It can not only be started directly from the SD card, but also can be used to write u-boot zImage rootfs in NAND Flash.

 

Pls check below steps for adding this function to the u-boot of the ok6410.

 

  First:Modify u-boot1.1.6 of SD card

  1. common/main.c

  void main_loop (void)

  {

  ……

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

  // If the execution process is interrupted by pressing a button during startup

  run_command("menu",0);

// If the menu returns, enter into the u-boot shell

  #ifdef CFG_HUSH_PARSER

  parse_file_outer();

  ……

  }

2. Run the menu procedure

  run_command("menu", 0),perform do_menu eventually

do_menu Firstly, print out the command menu, and then run different commands according to different selections.

  Add common/cmd_menu.c,as below:

  #include

  #include

  #include

  #include

  void print_menu_usage(void)

  {

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

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

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

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

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

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

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

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

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

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

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

  printf("Enter your selection: ");

  }

  intdo_menu(cmd_tbl_t*cmdtp,intflag,intargc,char*argv[])

  {

  intc;

  char cmd_buf[200];

  while(1)

  {

  print_menu_usage();

  c=getc();

  printf("%cn",c);

  switch(c)

  {

  case'1':

  {

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

  run_command(cmd_buf,0);

  break;

  }

  case'2':

  {

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

  run_command(cmd_buf,0);

  break;

  }

      case'3':

  {

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

  //run_command(cmd_buf,0);

  break;

  }

  case'4':

  {

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

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

  //Notice:nand erase 600000 $(filesize),If there are bad blocks, there will be data that cannot be written, so we can fix a big number here,as:

  // 0x1400000=20M,So the capacity of rootfs.yaffs <= 20M,

  // Consider whether to add partition the NAND Flash: nand erase root to erase the entire root partition, so you don't have to worry about whether there are bad blocks

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

  run_command(cmd_buf,0);

  break;

  }

  case'5':

  {

  strcpy(cmd_buf,"bootm 50008000");

  run_command(cmd_buf,0);

  break;

  }

  case'q':

  return;

  default:

  printf("command not foundn");

  break;

  }

  }

  }

  U_BOOT_CMD(

  menu,5,1,do_menu,

  "menu - manipulate BMP image datan",

  "menu long help: TNND mu you"

  );

  3. add it into Makefile

  Add COBJS+=cmd_menu.o into the common/Makefile

  Note: When combining commands, what should I do if I do not know the size of the burn? It doesn't matter. There is a variable $(filesize).

The above 50008000 is the memory address to be read when starting from the SD card; If you boot from Nand Flash, change the above 50008000 to C0008000

  

Second: Test

  2.1 sd card

a. The data is read from the SD card and the first partition, so the format of the first partition must be FAT32

 

  b. Compile u-boot.bin:

  The code should use the u-boot in CD, which support to start in NAND Flash

  make forlinx_nand_ram256_config, then make u-boot.bin

Copy it to the first partition of SD card, and change to  u-boot.bin_nand(the same with the code name of u-boot)

 

  c. Compile zImage

  Code linux-3.0.1 in CD , make to zImage

Copy it to the first partition of SD card, and change name to  zImage_nand(same with the code name in u-boot)

 

  d. build rootfs.yaffs

  Unzip the FileSystem-Yaffs2.tar.gz,in CD, if the size is too big, we can delete files we don’t need.

  The busybox in CD is dynamic linking,we can edit a static busybox, generate rootfs.yaffs

  sudo /opt/6410/4.3.2/bin/mkyaffs2image-nand2g FileSystem-Yaffs2 rootfs.yaffs

  NAND Flash is 2G, we should use instruction mkyaffs2image-nand2g

  Copy rootfs.yaffs to the first partition of SD card(same with the code name in u-boot)

Note: If you are not sure whether rootfs itself is okay or not, you can start from nfs to see whether it is normal. If it is okay, then you can use it.

Mkyaffs2image-nand2g, made it a yaffs image and program it into NAND Flash.


If you have any questions, please contact us

Email:line@longsto.com

Tel & Email

Tel:+86 13691982107(priority)+86 17727831243

Email:line@longsto.com

info@longsto.com

Complaint:ceo@longsto.com |+8613923450403

Address: Room 1907, Block B, Zhantao Technology Building, Minzhi Street, Longhua District, Shenzhen City, Guangdong Province, China.

HOME
Product
Technical Q&A
Contact