那么首先我们来了解几条u-boot支持的操作内存的命令(以FS4412为例)
md :md命令即memory display 也就是将某个内存地址中的值显示出来,用法如下
FS4412 # md 114001e0
114001e0: 00000000 00000000 00000555 00000000 ........U.......
114001f0: 00000000 00000000 00000555 0000003f ........U... ? ...
11400200 : 22222227 000000ba 00005555 00000000 '"""....UU......
11400210: 00000005 00000000 00005555 00000000 ........UU......
11400220: 11333337 0000002f 00000005 00000000 733./...........
11400230: 00000005 00000000 00000005 00000000 ................
11400240: 00000000 00000000 00005555 00000000 ........UU......
11400250: 00000000 00000000 00005555 00000000 ........UU......
11400260: 11111111 00000000 000000ff 00000000 ................
11400270: 00000000 00000000 000000ff 00000000 ................
11400280: 00000005 00000000 00005555 00000000 ........UU......
11400290: 00000005 00000000 00005555 00000000 ........UU......
114002a0: 11111115 0000000c 00000055 00000000 ........U.......
114002b0: 00000005 00000000 00000055 00000000 ........U.......
114002c0: 00002222 0000000f 00005555 000000ff ""......UU......
114002d0: 00000000 00000000 00005555 000000ff ........UU......
mm:mm命令即memory modify 也就是改变某个内存地址中的值,用法如下
FS4412 # mm 11400260
11400260: 00000000 ? 11111111
11400264 : 00000000 ? ff
11400268 : 00000155 ? ff
1140026c : 00000000 ?
(输入q可以退出该指令,不然的话每次输入一个值,回车后就会进入下一个地址)
nm:nm命令跟mm命令比较相似,只是nm命令只改变一个内存地址的值,回车后不会跳到下一个内存地址,而是直接显示你当前内存地址中的值,用法如下
FS4412 # nm 11400264
11400264: 0000001f ? 0
11400264 : 00000000 ? q
FS4412 #
u-boot源码中这些命令的实现
找一个u-boot源码包,解压,并进入common目录
cd u-boot-2010.03-FS4412/common
ls (可以看到这里有很多相关的文件)
ace_sha1.c cmd_echo.c cmd_jffs2.c cmd_nand.c cmd_ubi.c env_common.o libcommon.a
ace_sha1.o cmd_echo.o cmd_license.c cmd_net.c cmd_ubifs.c env_dataflash.c lynxkdi.c
bedbug.c cmd_eeprom.c cmd_load.c cmd_net.o cmd_universe.c env_eeprom.c main.c
cmd_ambapp.c cmd_elf.c cmd_load.o cmd_nvedit.c cmd_usb.c env_embedded.c main.o
cmd_bdinfo.c cmd_elf.o cmd_log.c cmd_nvedit.o cmd_usbd.c env_flash.c Makefile
cmd_bdinfo.o cmd_exit.c cmd_mac.c cmd_onenand.c cmd_usbd.o env_mgdisk.c memsize.c
cmd_bedbug.c cmd_ext2.c cmd_max8997.c cmd_otp.c cmd_version.c env_nand.c memsize.o
cmd_bmp.c cmd_ext2.o cmd_max8997.o cmd_pci.c cmd_version.o env_nowhere.c miiphyutil.c
cmd_boot.c cmd_fastboot.c cmd_mdmupgrade.c cmd_pcmcia.c cmd_vfd.c env_nvram.c modem.c
cmd_bootldr.c cmd_fastboot.o cmd_mdmupgrade.o cmd_pcmcia.o cmd_ximg.c env_onenand.c serial.c
cmd_bootm.c cmd_fat.c cmd_mem.c cmd_portio.c cmd_ximg.o env_sf.c s_record.c
cmd_bootm.o cmd_fat.o cmd_mem.o cmd_reginfo.c cmd_yaffs2.c exports.c s_record.o
cmd_boot.o cmd_fdc.c cmd_mfsl.c cmd_reiser.c command.c exports.o stdio.c
cmd_cache.c cmd_fdos.c cmd_mgdisk.c cmd_sata.c command.o fdt_support.c stdio.o
cmd_console.c cmd_fdt.c cmd_mii.c cmd_scsi.c console.c flash.c system_map.c
cmd_console.o cmd_flash.c cmd_misc.c cmd_setexpr.c console.o flash.o update.c
cmd_cplbinfo.c cmd_fpga.c cmd_misc.o cmd_sf.c ddr_spd.c hush.c usb.c
cmd_cramfs.c cmd_help.c cmd_mmc.c cmd_source.c decompress_ext4.c hwconfig.c usb_kbd.c
cmd_dataflash_mmc_mux.c cmd_help.o cmd_mmc_fdisk.c cmd_source.o decompress_ext4.o image.c usb_storage.c
cmd_date.c cmd_i2c.c cmd_mmc_fdisk.o cmd_spibootldr.c dlmalloc.c image.o xyzModem.c
cmd_dcr.c cmd_ide.c cmd_mmc.o cmd_spi.c dlmalloc.o iomux.c xyzModem.o
cmd_df.c cmd_immap.c cmd_movi.c cmd_strings.c dlmalloc.src kallsyms.c
cmd_diag.c cmd_irq.c cmd_movi.o cmd_terminal.c env_auto.c kgdb.c
cmd_display.c cmd_itest.c cmd_mp.c cmd_test.c env_auto.o kgdb_stubs.c
cmd_dtt.c cmd_itest.o cmd_mtdparts.c cmd_tsi148.c env_common.c lcd.c
vi cmd_mem.c
C++ Code
U_BOOT_CMD(
md, 3, 1, do_mem_md,
"memory display",
"[.b, .w, .l] address [# of objects]"
);
U_BOOT_CMD(
mm, 2, 1, do_mem_mm,
"memory modify (auto-incrementing address)",
"[.b, .w, .l] address"
);
U_BOOT_CMD(
nm, 2, 1, do_mem_nm,
"memory modify (constant address)",
"[.b, .w, .l] address"
);