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

2025-12-04 19:13:01 adminnnnm 3

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

  {

  ……

  ifbootdelay>=0&&s&&!abortbootbootdelay)){ }

  // 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_usagevoid

  {

  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_Testrn");

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

  printf"[q] quit from menurn");

  printf"Enter your selection: ");

  }

  intdo_menucmd_tbl_t*cmdtp,intflag,intargc,char*argv[]

  {

  intc;

  char cmd_buf[200];

  while1

  {

  print_menu_usage();

  c=getc();

  printf"%cn",c);

  switchc

  {

  case'1':

  {

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

  run_commandcmd_buf,0);

  break;

  }

  case'2':

  {

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

  run_commandcmd_buf,0);

  break;

  }

      case'3':

  {

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

  //run_commandcmd_buf,0);

  break;

  }

  case'4':

  {

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

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

  //Noticenand erase 600000 $filesize),If there are bad blocks, there will be data that cannot be written, so we can fix a big number hereas:

  // 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

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

  run_commandcmd_buf,0);

  break;

  }

  case'5':

  {

  strcpycmd_buf,"bootm 50008000");

  run_commandcmd_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_nandthe 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_nandsame 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 linkingwe 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 cardsame 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.


香港(Hong Kong)

TEL: +852-5370-8364

E-mail: contact@cs-semi.com

Addr: RM 2206, 23/F, Ho King Comm CTR, 2-16 Fayuen ST, Mongkok Kowloon, Hong Kong

韩国(South Korea)

TEL: +82-10-6243-3558

E-mail: contact@cs-semi.com

Address:1302 U-Tower, 767, Sinsu-ro, Suji-gu, Yongin-si, Gyeonggi-do, Korea

中国(深圳)

电话:+86 135-6078-6601

E-mail: contact@cs-semi.com

地址:深圳市坪山新区坪山街道金牛西路16号华瀚科技工业园2号楼203

电话咨询
案例作品
我们的团队
QQ客服