Monday, September 21, 2015

U-boot Porting JZ2440 - Reduce Code Size && Set User Value

3.8 U-boot 縮小code size,易用性修改

3.8.1 打造自己的環境參數,在燒寫uboot時,常需要手動設定一些環境參數,如set ipaddr、set ethaddr、....,在使用上不方便
首先規劃參數在 nand flash 存放區塊如下圖

uboot_nand flash map

uboot 啟動時讀參數步驟如上 1.2.3
===========================================================
U-Boot 2012.04.01 (Sep 17 2015 - 04:34:23)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
*** Warning - bad CRC, using default environment  <--- nand flash 上無放置環境參數,顯示警告訊息,
                                                                                     查關鍵字using defaul environment
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
SMDK2410 #
SMDK2410 # print
baudrate=115200
bootdelay=5
ethact=dm9000
ipaddr=10.0.0.110
netmask=255.255.255.0
serverip=10.0.0.1
stderr=serial
stdin=serial
stdout=serial

Environment size: 160/65532 bytes
===========================================================
---- default environment Matches (73 in 65 files) ----
Cam_enc_4xx.c (y:\linux_source\uboot\u-boot-2012.04.01\board\ait\cam_enc_4xx): * img_writedfenv: write default environment to ubi volume
Cmd_nvedit.c (common): set_default_env("## Resetting to default environment\n");
Cmd_nvedit.c (common): "default -f - reset default environment\n"
Env_common.c (common): /* if crc was bad, use the default environment */
Env_common.c (common): puts("*** Error - default environment is too large\n\n");
Env_common.c (common): "using default environment\n\n",
Env_common.c (common): puts("Using default environment\n\n");
..........
===========================================================
得知在文件\common\Env_common.c,有環境變量參數,新增加所需參數 / 或刪除不必要參數至smdk2440.h,修改如下 
smdk2440.h
/*
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Marius Groeger <mgroeger@sysgo.de>
 * Gary Jennejohn <garyj@denx.de>
 * David Mueller <d.mueller@elsoft.ch>
 *
 * Configuation settings for the SAMSUNG SMDK2410 board.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#ifndef __CONFIG_H
#define __CONFIG_H

/*
 * High Level Configuration Options
 * (easy to change)
 */
#define CONFIG_ARM920T /* This is an ARM920T Core */
#define CONFIG_S3C24X0 /* in a SAMSUNG S3C24x0-type SoC */
// #define CONFIG_S3C2410 /* specifically a SAMSUNG S3C2410 SoC */
#define CONFIG_S3C2440
#define CONFIG_SMDK2410 /* on a SAMSUNG SMDK2410 Board */

// #define CONFIG_SYS_TEXT_BASE 0x0
#define CONFIG_SYS_TEXT_BASE 0x33f00000

#define CONFIG_SYS_ARM_CACHE_WRITETHROUGH

/* input clock of PLL (the SMDK2410 has 12MHz input clock) */
#define CONFIG_SYS_CLK_FREQ 12000000

#undef CONFIG_USE_IRQ /* we don't need IRQ/FIQ stuff */

#define CONFIG_CMDLINE_TAG /* enable passing of ATAGs */
#define CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG

/*
 * Hardware drivers
 */

#if 0
#define CONFIG_CS8900 /* we have a CS8900 on-board */
#define CONFIG_CS8900_BASE 0x19000300
#define CONFIG_CS8900_BUS16 /* the Linux driver does accesses as shorts */
#else
#define CONFIG_DRIVER_DM9000            1
#define CONFIG_DM9000_BASE              0x20000000
#define DM9000_IO                       CONFIG_DM9000_BASE
#define DM9000_DATA                     (CONFIG_DM9000_BASE + 4)
#endif
/*
 * select serial console configuration
 */
#define CONFIG_S3C24X0_SERIAL
#define CONFIG_SERIAL1 1 /* we use SERIAL 1 on SMDK2410 */

/************************************************************
 * USB support (currently only works with D-cache off)
 ************************************************************/
//#define CONFIG_USB_OHCI
//#define CONFIG_USB_KEYBOARD
//#define CONFIG_USB_STORAGE
//#define CONFIG_DOS_PARTITION

/************************************************************
 * RTC
 ************************************************************/
// #define CONFIG_RTC_S3C24X0


#define CONFIG_BAUDRATE 115200

/*
 * BOOTP options
 */
//#define CONFIG_BOOTP_BOOTFILESIZE
//#define CONFIG_BOOTP_BOOTPATH
//#define CONFIG_BOOTP_GATEWAY
//#define CONFIG_BOOTP_HOSTNAME

/*
 * Command line configuration.
 */
#include <config_cmd_default.h>

#define CONFIG_CMD_BSP
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DATE
// #define CONFIG_CMD_DHCP
#define CONFIG_CMD_ELF
#define CONFIG_CMD_NAND
#define CONFIG_CMD_PING
#define CONFIG_CMD_REGINFO
// #define CONFIG_CMD_USB

#define CONFIG_SYS_HUSH_PARSER
#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
#define CONFIG_CMDLINE_EDITING

/* autoboot */
#define CONFIG_BOOTDELAY 5
#define CONFIG_BOOT_RETRY_TIME -1
#define CONFIG_RESET_TO_RETRY
#define CONFIG_ZERO_BOOTDELAY_CHECK

// #define CONFIG_NETMASK 255.255.255.0
// #define CONFIG_IPADDR 10.0.0.110
// #define CONFIG_SERVERIP 10.0.0.1
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.0.110
#define CONFIG_SERVERIP 192.168.0.254
#define CONFIG_ETHADDR      00:0c:29:2f:4e:70

#if defined(CONFIG_CMD_KGDB)
#define CONFIG_KGDB_BAUDRATE 115200 /* speed to run kgdb serial port */
/* what's this ? it's not used anywhere */
#define CONFIG_KGDB_SER_INDEX 2 /* which serial port to use */
#endif

/*
 * Miscellaneous configurable options
 */
#define CONFIG_SYS_LONGHELP /* undef to save memory */
#define CONFIG_SYS_PROMPT "SMDK2410 # "
#define CONFIG_SYS_CBSIZE 256
/* Print Buffer Size */
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + \
sizeof(CONFIG_SYS_PROMPT)+16)
#define CONFIG_SYS_MAXARGS 16
#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE

#define CONFIG_DISPLAY_CPUINFO /* Display cpu info */

#define CONFIG_SYS_MEMTEST_START 0x30000000 /* memtest works on */
#define CONFIG_SYS_MEMTEST_END 0x33F00000 /* 63 MB in DRAM */

#define CONFIG_SYS_LOAD_ADDR 0x30800000

#define CONFIG_SYS_HZ 1000

/* valid baudrates */
#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200 }

/* support additional compression methods */
#define CONFIG_BZIP2
#define CONFIG_LZO
#define CONFIG_LZMA

#define CONFIG_BOOTARGS     "console=ttySAC0 root=/dev/mtdblock3"
#define CONFIG_BOOTCOMMAND  "nand read 30000000 0xabc 0x200000; bootm 0x30000000"

/*-----------------------------------------------------------------------
 * Stack sizes
 *
 * The stack sizes are set up in start.S using the settings below
 */
#define CONFIG_STACKSIZE (128*1024) /* regular stack */
#ifdef CONFIG_USE_IRQ
#define CONFIG_STACKSIZE_IRQ (4*1024) /* IRQ stack */
#define CONFIG_STACKSIZE_FIQ (4*1024) /* FIQ stack */
#endif

/*-----------------------------------------------------------------------
 * Physical Memory Map
 */
#define CONFIG_NR_DRAM_BANKS 1          /* we have 1 bank of DRAM */
#define PHYS_SDRAM_1 0x30000000 /* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE 0x04000000 /* 64 MB */

#define PHYS_FLASH_1 0x00000000 /* Flash Bank #0 */

#define CONFIG_SYS_FLASH_BASE PHYS_FLASH_1

/*-----------------------------------------------------------------------
 * FLASH and environment organization
 */

#define CONFIG_SYS_FLASH_CFI
#define CONFIG_FLASH_CFI_DRIVER
#define CONFIG_FLASH_CFI_LEGACY
#define CONFIG_SYS_FLASH_LEGACY_512Kx16
#define CONFIG_FLASH_SHOW_PROGRESS 45

#define CONFIG_SYS_MAX_FLASH_BANKS 1
#define CONFIG_SYS_FLASH_BANKS_LIST     { CONFIG_SYS_FLASH_BASE }
//#define CONFIG_SYS_MAX_FLASH_SECT (19)
#define CONFIG_SYS_MAX_FLASH_SECT (128)

#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
#define CONFIG_ENV_IS_IN_FLASH
#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
/#define CONFIG_ENV_OVERWRITE

/*
 * Size of malloc() pool
 * BZIP2 / LZO / LZMA need a lot of RAM
 */
#define CONFIG_SYS_MALLOC_LEN (4 * 1024 * 1024)

#define CONFIG_SYS_MONITOR_LEN (448 * 1024)
#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_FLASH_BASE

/*
 * NAND configuration
 */
#ifdef CONFIG_CMD_NAND

#ifdef CONFIG_S3C2410
#define CONFIG_NAND_S3C2410
#define CONFIG_SYS_S3C2410_NAND_HWECC
#else
#define CONFIG_NAND_S3C2440
#define CONFIG_SYS_S3C2440_NAND_HWECC
#endif

#define CONFIG_SYS_MAX_NAND_DEVICE 1
#define CONFIG_SYS_NAND_BASE 0x4E000000
#endif

/*
 * File system
 */
//#define CONFIG_CMD_FAT
//#define CONFIG_CMD_EXT2
//#define CONFIG_CMD_UBI
//#define CONFIG_CMD_UBIFS
//#define CONFIG_CMD_MTDPARTS
//#define CONFIG_MTD_DEVICE
//#define CONFIG_MTD_PARTITIONS
// #define CONFIG_YAFFS2
//#define CONFIG_RBTREE

/* additions for new relocation code, must be added to all boards */
#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x1000 - \
GENERATED_GBL_DATA_SIZE)

#define CONFIG_BOARD_EARLY_INIT_F


#endif /* __CONFIG_H */

===========================================================
bootargs:表示傳給內核的啟動參數,在設定檔中進行定義
bootcmd:u-boot啟動時,就是執行這個環境變數定義的命令,啟動kernel的
bootdelay:表示u-boot啟動時的倒數計時
#define CONFIG_BOOTARGS     "console=ttySAC0 root=/dev/mtdblock3" 

  • 意思是kernel啟動時,從串口0列印資訊,文件系統在block 3

#define CONFIG_BOOTCOMMAND  "nand read 30000000 0xabc 0x200000; bootm 0x30000000"

  • 表示uboot啟動後執行命令,從0xabc複製大小0x200000到位置30000000 的sdram裡

bootm 0x30000000

  • 表示從30000000啟動kernel

===========================================================
重新編譯,error訊息如下
 ......
common/libcommon.o: In function `do_date':
/home/scyu/share/linux_source/uboot/u-boot-2012.04.01/common/cmd_date.c:60: undefined reference to `rtc_reset'  <--關閉RTC造成錯誤,一併拿掉 cmd_date.c
/home/scyu/share/linux_source/uboot/u-boot-2012.04.01/common/cmd_date.c:63: undefined reference to `rtc_get'
/home/scyu/share/linux_source/uboot/u-boot-2012.04.01/common/cmd_date.c:72: undefined reference to `rtc_set'
/home/scyu/share/linux_source/uboot/u-boot-2012.04.01/common/cmd_date.c:81: undefined reference to `rtc_get'
make: *** [u-boot] Error 1
尋找 /common/Makefile ,
COBJS-$(CONFIG_CMD_DATE) += cmd_date.o
得知需關閉 CONFIG_CMD_DATE,在smdk2440.h中
===========================================================
修改前
U-Boot 2012.04.01 (Sep 17 2015 - 04:34:23)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
SMDK2410 # print
baudrate=115200
bootdelay=5
ethact=dm9000
ipaddr=10.0.0.110
netmask=255.255.255.0
serverip=10.0.0.1
stderr=serial
stdin=serial
stdout=serial

Environment size: 160/65532 bytes
------------------------------------------------------------------------------------
重新編譯
scyu@scyu-VirtualBox:~/share/linux_source/uboot/u-boot-2012.04.01$ ls -l u-boot.bin

-rwxrwxr-x 1 scyu scyu 203608 Sep 18 02:42 u-boot.bin  <-- uboot大小已縮減不超過256k
燒寫、需手動設置環境參數
SMDK2410 # set ipaddr 192.168.0.110
SMDK2410 # set ethaddr 08:00:3e:26:0a:5b
SMDK2410 # setenv gatewayip 192.168.0.254
SMDK2410 # set serverip 192.168.0.254
SMDK2410 # tftp 30000000 u-boot.bin <-- 採用tftp 下載
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
could not establish link
Using dm9000 device
TFTP from server 192.168.0.254; our IP address is 192.168.0.110
Filename 'u-boot.bin'.
Load address: 0x30000000
Loading: T ##############
done
Bytes transferred = 203608 (31b58 hex)
SMDK2410 # protect off all
Un-Protect Flash Bank # 1
SMDK2410 # erase 0 3ffff  <-- 小於256k

....... done
Erased 7 sectors
SMDK2410 # cp.b 30000000 0 40000
Copy to Flash... 9....8....7....6....5....4....3....2....1....done
SMDK2410 # reset
resetting ...

修改後
U-Boot 2012.04.01 (Sep 18 2015 - 02:42:28)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
*** Warning - bad CRC, using default environment <--警告訊息還在

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0  <--倒數訊息出現

NAND read: device 0 offset 0xabc, size 0x200000
Attempt to read non page aligned data
 0 bytes read: ERROR
Wrong Image Format for bootm command
ERROR: can't get kernel image!
SMDK2410 # print <-- 列印系統環境變數,已修改為user value
baudrate=115200
bootargs=console=ttySAC0 root=/dev/mtdblock3
bootcmd=nand read 30000000 0xabc 0x200000; bootm 0x30000000
bootdelay=5
ethact=dm9000
ethaddr=00:0c:29:2f:4e:70
ipaddr=192.168.0.110
netmask=255.255.255.0
serverip=192.168.0.254
stderr=serial
stdin=serial
stdout=serial

Environment size: 305/131068 bytes
===========================================================
3.8.2 建立參數分區,才可使用save指令,否則會寫入錯誤data到nand flash 的參數分區,導致uboot出錯
尋找關鍵字
SMDK2410 # ? save
saveenv - save environment variables to persistent storage
---- saveenv Matches (167 in 128 files) ----
...........
Env_flash.c (common):#if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_FLASH)
Env_flash.c (common):#define CMD_SAVEENV
Env_flash.c (common):#error CONFIG_ENV_ADDR_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_FLASH
Env_flash.c (common):#if defined(CMD_SAVEENV) || defined(CONFIG_ENV_ADDR_REDUND)
Env_flash.c (common):#ifdef CMD_SAVEENV
Env_flash.c (common):int saveenv(void)
Env_flash.c (common):#endif /* CMD_SAVEENV */
Env_flash.c (common):#ifdef CMD_SAVEENV
Env_flash.c (common):int saveenv(void)
Env_flash.c (common):#endif /* CMD_SAVEENV */
Env_mgdisk.c (common):int saveenv(void)
Env_mmc.c (common):#ifdef CONFIG_CMD_SAVEENV
Env_mmc.c (common):int saveenv(void)
Env_mmc.c (common):#endif /* CONFIG_CMD_SAVEENV */
Env_nand.c (common):#if defined(CONFIG_CMD_SAVEENV) && defined(CONFIG_CMD_NAND)
Env_nand.c (common):#define CMD_SAVEENV
Env_nand.c (common):#error CONFIG_ENV_OFFSET_REDUND must have CONFIG_CMD_SAVEENV & CONFIG_CMD_NAND
Env_nand.c (common):#ifdef CMD_SAVEENV
Env_nand.c (common):int saveenv(void)
Env_nand.c (common):int saveenv(void) <-- 相關文件
Env_nand.c (common):#endif /* CMD_SAVEENV */
Env_nvram.c (common):int saveenv(void)
Env_onenand.c (common):int saveenv(void)
Env_sf.c (common):int saveenv(void)
Env_sf.c (common):int saveenv(void)
Common.h (include):int saveenv     (void);
.............
===========================================================
尋找相關文件  /common/Env_nand.c
trace int savenv(void)
int saveenv(void)
{
int ret = 0;
env_t env_new;
ssize_t len;
char *res;
nand_erase_options_t nand_erase_options;

memset(&nand_erase_options, 0, sizeof(nand_erase_options));
nand_erase_options.length = CONFIG_ENV_RANGE;
nand_erase_options.offset = CONFIG_ENV_OFFSET;

if (CONFIG_ENV_RANGE < CONFIG_ENV_SIZE)    // < -- 不可小於
return 1;

res = (char *)&env_new.data;
len = hexport_r(&env_htab, '\0', &res, ENV_SIZE, 0, NULL);
if (len < 0) {
error("Cannot export environment: errno = %d\n", errno);
return 1;
}
env_new.crc = crc32(0, env_new.data, ENV_SIZE);

puts("Erasing Nand...\n");
if (nand_erase_opts(&nand_info[0], &nand_erase_options))
return 1;

puts("Writing to Nand... ");
if (writeenv(CONFIG_ENV_OFFSET, (u_char *)&env_new)) {
puts("FAILED!\n");
return 1;
}

puts("done\n");
return ret;

}
===========================================================
kernel 列印分區訊息
Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00040000 : "bootloader"
0x00040000-0x00060000 : "params"
0x00060000-0x00260000 : "kernel"
0x00260000-0x10000000 : "root"


CONFIG_ENV_SIZE   表示寫入資料(環境變數)的分區大小;
CONFIG_ENV_OFFSET 表示存儲的偏移位址;
CONFIG_ENV_RANGE:表示擦除的大小,nand寫之前需要擦除操作,nand擦出一定要是單塊的整數倍
修改程式  smdk2440.h
......
//#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
//#define CONFIG_ENV_IS_IN_FLASH
//#define CONFIG_ENV_SIZE 0x10000
/* allow to overwrite serial and ethaddr */
//#define CONFIG_ENV_OVERWRITE
#define CONFIG_ENV_IS_IN_NAND     // 需定義為了在Makefile中,引入、編譯Env_nand.c
#define CONFIG_ENV_OFFSET           0x00040000   // 256k
#define CONFIG_ENV_SIZE             0x20000
#define CONFIG_ENV_RANGE            CONFIG_ENV_SIZE
........
===========================================================
重新燒寫編譯,執行 save cmd
SMDK2410 # save
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x40000 -- 100% complete.
Writing to Nand... done
SMDK2410 # reset
resetting ...


U-Boot 2012.04.01 (Sep 18 2015 - 02:42:28)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled <--警告訊息不在,ok
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0

NAND read: device 0 offset 0xabc, size 0x200000
Attempt to read non page aligned data
 0 bytes read: ERROR
Wrong Image Format for bootm command
ERROR: can't get kernel image!
===========================================================
3.8.3 建立mtdparts指令,讓user在開發上更方便

在燒寫kernel過程中
U-Boot 2012.04.01 (Sep 18 2015 - 02:42:28)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0
SMDK2410 # tftp uImage 30000000
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 192.168.0.254; our IP address is 192.168.0.110
Filename '30000000'.
Load address: 0x0
Loading: *
TFTP error: 'File not found' (1)
Not retrying...
SMDK2410 # tftp 30000000 uImage
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 192.168.0.254; our IP address is 192.168.0.110
Filename 'uImage'.
Load address: 0x30000000
Loading: T #################################################################
         #############################################################
done
Bytes transferred = 1848720 (1c3590 hex)
SMDK2410 # nand erase 60000 200000

NAND erase: device 0 offset 0x60000, size 0x200000
Erasing at 0x240000 -- 100% complete.
OK
SMDK2410 # nand write 30000000 60000 200000

NAND write: device 0 offset 0x60000, size 0x200000

 2097152 bytes written: OK
----------------------------------------------------------------
nand erase 60000 200000
nand write 30000000 60000 200000
使如下命令替代
nand erase kernel
nand write 30000000 kernel
kernel : 表示 60000 200000 的偏移量和长度
ps. 此修改僅改變u-boot宏定義,多一層修飾,增加可讀性,並不影響kernel所決定的分區。
===========================================================
SMDK2410 # mtdparts
Unknown command 'mtdparts' - try 'help'
無指令需新增 "mtdparts" command
指令存放在文件:/common/Cmd_mtdparts.c,需將程式編譯進uboot,
查 vim /common/Makefile
===========================================================
.............
COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o
COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o
COBJS-$(CONFIG_CMD_MMC_SPI) += cmd_mmc_spi.o
COBJS-$(CONFIG_MP) += cmd_mp.o
COBJS-$(CONFIG_CMD_MTDPARTS) += cmd_mtdparts.o
COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o
COBJS-$(CONFIG_CMD_NET) += cmd_net.o
COBJS-$(CONFIG_CMD_ONENAND) += cmd_onenand.o
COBJS-$(CONFIG_CMD_OTP) += cmd_otp.o

.......
===========================================================
將CONFIG_CMD_MTDPARTS 加進 smdk2440.h中
#define CONFIG_CMD_MTDPARTS
参考文件:include/configs/TQM866M.h
===========================================================
TQM866M.h
..........
/*-----------------------------------------------------------------------
 * Dynamic MTD partition support
 */
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_DEVICE /* needed for mtdparts commands */
#define CONFIG_FLASH_CFI_MTD
#define MTDIDS_DEFAULT "nor0=TQM8xxM-0"

#define MTDPARTS_DEFAULT "mtdparts=TQM8xxM-0:512k(u-boot)," \
"128k(dtb)," \
"1920k(kernel)," \
"5632(rootfs)," \
"4m(data)"
......
===========================================================
在jz2440 配置文件 include/configs/smdk2440.h中增加
smdk2440.h
.........
// insert mtdparts cmd
#define MTDIDS_DEFAULT "nand0=jz2440-0"

#define MTDPARTS_DEFAULT "mtdparts=jz2440-0:256k(u-boot)," \
"128k(parms)," \
"2m(kernel)," \

"-(rootfs)"
..........
===========================================================
新增mtdparts_init() 在board.c中
board.c
.........
/*
 ************************************************************************
 *
 * This is the next part if the initialization sequence: we are now
 * running from RAM and have a "normal" C environment, i. e. global
 * data can be written, BSS has been cleared, the stack size in not
 * that critical any more, etc.
 *
 ************************************************************************

 */
.............
   mtdparts_init();

/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;) {
main_loop();

}
..............
===========================================================
重新編譯,出現error如下
common/libcommon.o: In function `get_mtd_info':
/home/scyu/share/linux_source/uboot/u-boot-2012.04.01/common/cmd_mtdparts.c:306: undefined reference to `get_mtd_device_nm'
make: *** [u-boot] Error 1
搜尋 get_mtd_device_nm 函數在哪裡定義,發現在 \drivers\mtd\Mtdcore.c 中定義
找  cat /drivers/mtd/Makefile
...........
COBJS-$(CONFIG_MTD_DEVICE) += mtdcore.o
COBJS-$(CONFIG_MTD_PARTITIONS) += mtdpart.o
COBJS-$(CONFIG_MTD_CONCAT) += mtdconcat.o
COBJS-$(CONFIG_HAS_DATAFLASH) += at45.o
COBJS-$(CONFIG_FLASH_CFI_DRIVER) += cfi_flash.o
COBJS-$(CONFIG_FLASH_CFI_MTD) += cfi_mtd.o
...........
新增#define CONFIG_MTD_DEVICE 在smdk2440.h中,將mtdcore.c編譯進uboot
===========================================================
重新編譯、燒寫

U-Boot 2012.04.01 (Sep 18 2015 - 20:37:30)



CPUID: 32440001

FCLK:      400 MHz

HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
mtdparts variable not set, see 'help mtdparts'  <--無分區訊息顯示
no partitions defined

defaults:
mtdids  : nand0=jz2440-0
mtdparts: mtdparts=jz2440-0:256k(u-boot),128k(parms),2m(kernel),-(rootfs)
Hit any key to stop autoboot:  0
SMDK2410 # mtdparts
mtdparts variable not set, see 'help mtdparts' <--無分區訊息顯示
no partitions defined

defaults:
mtdids  : nand0=jz2440-0
mtdparts: mtdparts=jz2440-0:256k(u-boot),128k(parms),2m(kernel),-(rootfs)
SMDK2410 # help mtdparts
mtdparts - define flash/nand partitions

Usage:
mtdparts
    - list partition table
mtdparts delall
    - delete all partitions
mtdparts del part-id
    - delete partition (e.g. part-id = nand0,1)
mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]
    - add partition
mtdparts default
    - reset partition table to defaults <-- 提示需要輸入指令採用default value

-----

this command uses three environment variables:

'partition' - keeps current partition identifier

partition  := <part-id>
<part-id>  := <dev-id>,part_num

'mtdids' - linux kernel mtd device id <-> u-boot device id mapping

mtdids=<idmap>[,<idmap>,...]

<idmap>    := <dev-id>=<mtd-id>
<dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
<dev-num>  := mtd device number, 0...
<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)

'mtdparts' - partition list

mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]

<mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
<mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
<part-def> := <size>[@<offset>][<name>][<ro-flag>]
<size>     := standard linux memsize OR '-' to denote all remaining space
<offset>   := partition start offset within the device
<name>     := '(' NAME ')'
<ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
SMDK2410 # mtdparts default <--手動輸入分區採用預設值
SMDK2410 # mtdparts <--分區訊息顯示

device nand0 <jz2440-0>, # parts = 4
 #: name                size            offset          mask_flags
 0: u-boot              0x00040000      0x00000000      0
 1: parms               0x00020000      0x00040000      0
 2: kernel              0x00200000      0x00060000      0
 3: rootfs              0x0fda0000      0x00260000      0

active partition: nand0,0 - (u-boot) 0x00040000 @ 0x00000000

defaults:
mtdids  : nand0=jz2440-0
mtdparts: mtdparts=jz2440-0:256k(u-boot),128k(parms),2m(kernel),-(rootfs)
===========================================================
mtdparts 修正
board.c
.............
        run_command("mtdparts default", 0);
        // mtdparts_init();

/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;) {
main_loop();
}
..............
===========================================================
重新編譯、燒寫、ok
U-Boot 2012.04.01 (Sep 18 2015 - 21:13:19)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0
SMDK2410 # mtdparts

device nand0 <jz2440-0>, # parts = 4
 #: name                size            offset          mask_flags
 0: u-boot              0x00040000      0x00000000      0
 1: parms               0x00020000      0x00040000      0
 2: kernel              0x00200000      0x00060000      0
 3: rootfs              0x0fda0000      0x00260000      0

active partition: nand0,0 - (u-boot) 0x00040000 @ 0x00000000

defaults:
mtdids  : nand0=jz2440-0
mtdparts: mtdparts=jz2440-0:256k(u-boot),128k(parms),2m(kernel),-(rootfs)
===========================================================
3.8.4 驗證:燒寫 kernel、文件系統到 nand flash上
將之前的nand flash 寫入地址 0xabc 修正為kernel
#define CONFIG_BOOTCOMMAND  "nand read 30000000 kernel 0x200000; bootm 0x30000000" 
或 set bootcmd 'nand read 30000000 kernel; bootm 30000000'
重新編譯、燒寫
uboot:
  1. tftp 30000000 u-boot.bin
  2. protect off all
  3. erase 0 3ffff
  4. cp.b 30000000 0 40000
uImage:
  1. tftp 30000000 uImage
  2. nand erase.part kernel
  3. nand write 30000000 kernel
啟動kernel進入root
U-Boot 2012.04.01 (Sep 18 2015 - 21:55:17)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0

NAND read: device 0 offset 0x60000, size 0x200000
 2097152 bytes read: OK
## Booting kernel from Legacy Image at 30000000 ...
   Image Name:   Linux-2.6.22.6
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1848656 Bytes = 1.8 MiB
   Load Address: 30008000
   Entry Point:  30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux...................................................................................................................... done, booting the kernel.
Linux version 2.6.22.6 (book@book-desktop) (gcc version 3.4.5) #1 Thu Jan 27 22:22:51 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists.  Total pages: 16256
Kernel command line: console=ttySAC0 root=/dev/mtdblock3
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61056KB available (3264K code, 458K data, 140K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2410 Power Management, (c) 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C2440: Clock Support, DVS off
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NetWinder Floating Point Emulator V0.97 (double precision)
Registering GDB sysrq handler
JFFS2 version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
yaffs Jan 27 2011 22:22:18 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
fb0: s3c2410fb frame buffer device
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO map 0x50000000 mem 0xf0400000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO map 0x50004000 mem 0xf0404000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO map 0x50008000 mem 0xf0408000 (irq = 76) is a S3C2440
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
line 400 <DM9KS> I/O: c486a000, VID: 90000a46
line 408 <DM9KS> I/O: c486a000, VID: 90000a46
<DM9KS> error version, chip_revision = 0x1a, chip_info = 0x3
id_val=0
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 1663 at 0x0cfe0000
Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00040000 : "bootloader"
0x00040000-0x00060000 : "params"
0x00060000-0x00260000 : "kernel"
0x00260000-0x10000000 : "root"
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
s3c2410 TouchScreen successfully loaded
input: s3c2410 TouchScreen as /class/input/input0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
mapped channel 0 to 0
s3c2410-sdi s3c2410-sdi: powered down.
s3c2410-sdi s3c2410-sdi: initialisation done.
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
drivers/hid/usbhid/hid-core.c: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.14 (Thu May 31 09:03:25 2007 UTC).
ASoC version 0.13.1
s3c2410iis_probe...
UDA1341 audio driver initialized
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 1
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
UDF-fs: No partition found (1)
yaffs: dev is 32505859 name is "mtdblock3"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.3, "mtdblock3"
yaffs: auto selecting yaffs2
block 1645 is bad
s3c2410-sdi s3c2410-sdi: running at 0kHz (requested: 0kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
VFS: Mounted root (yaffs filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 764, tty '': '/etc/init.d/rcS'
BusyBox v1.7.0 (2008-01-22 10:04:09 EST) multi-call binary

Usage: route [{add|del|delete}]

Edit the kernel's routing tables

Options:
        -n      Dont resolve names
        -e      Display other/more information
        -A inet{6}      Select address family


Please press Enter to activate this console. tsdev (compaq touchscreen emulation) is scheduled for removal.
See Documentation/feature-removal-schedule.txt for details.
Warning: TimeZone::data Can't create a valid data object for 'Europe/Oslo'
Warning: could not register server

starting pid 772, tty '/dev/s3c2410_serial0': '/bin/sh'
#

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

3.8.5 燒寫 JFFS2

tftp 30000000 fs_mini_mdev.jffs2
nand erase.part rootfs
nand write.jffs2 30000000 0x00260000 5b89a8
set bootargs console=ttySAC0 root=/dev/mtdblock3 rootfstype=jffs2
boot

----------------------------------------------
SMDK2410 # boot
NAND read: device 0 offset 0x60000, size 0x200000
 2097152 bytes read: OK
## Booting kernel from Legacy Image at 30000000 ...
   Image Name:   Linux-2.6.22.6
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1848656 Bytes = 1.8 MiB
   Load Address: 30008000
   Entry Point:  30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux...................................................................................................................... done, booting the kernel.
Linux version 2.6.22.6 (book@book-desktop) (gcc version 3.4.5) #1 Thu Jan 27 22:22:51 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2410
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists.  Total pages: 16256
Kernel command line: console=ttySAC0 root=/dev/mtdblock3 rootfstype=jffs2
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00500000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61056KB available (3264K code, 458K data, 140K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2410 Power Management, (c) 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C2440: Clock Support, DVS off
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NetWinder Floating Point Emulator V0.97 (double precision)
Registering GDB sysrq handler
JFFS2 version 2.2. (NAND) c 2001-2006 Red Hat, Inc.
yaffs Jan 27 2011 22:22:18 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 30x40
fb0: s3c2410fb frame buffer device
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO map 0x50000000 mem 0xf0400000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO map 0x50004000 mem 0xf0404000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO map 0x50008000 mem 0xf0408000 (irq = 76) is a S3C2440
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
line 400 <DM9KS> I/O: c486a000, VID: 90000a46
line 408 <DM9KS> I/O: c486a000, VID: 90000a46
<DM9KS> error version, chip_revision = 0x1a, chip_info = 0x3
id_val=0
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 1663 at 0x0cfe0000
Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00040000 : "bootloader"
0x00040000-0x00060000 : "params"
0x00060000-0x00260000 : "kernel"
0x00260000-0x10000000 : "root"
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
mice: PS/2 mouse device common for all mice
s3c2410 TouchScreen successfully loaded
input: s3c2410 TouchScreen as /class/input/input0
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
mapped channel 0 to 0
s3c2410-sdi s3c2410-sdi: powered down.
s3c2410-sdi s3c2410-sdi: initialisation done.
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
drivers/hid/usbhid/hid-core.c: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.14 (Thu May 31 09:03:25 2007 UTC).
ASoC version 0.13.1
s3c2410iis_probe...
UDA1341 audio driver initialized
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 1
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
s3c2410-sdi s3c2410-sdi: running at 0kHz (requested: 0kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
VFS: Mounted root (jffs2 filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 765, tty '': '/etc/init.d/rcS'

Please press Enter to activate this console.
===========================================================
3.8.6 燒寫 YAFFS

tftp 30000000 fs_mini_mdev.yaffs2
nand erase.part rootfs
nand write.yaffs 30000000 260000  889bc0

-----------------------------------
U-Boot 2012.04.01 (Sep 18 2015 - 21:55:17)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0
SMDK2410 #
SMDK2410 #
SMDK2410 #
SMDK2410 # tftp 30000000 fs_mini_mdev.yaffs2
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 192.168.0.254; our IP address is 192.168.0.110
Filename 'fs_mini_mdev.yaffs2'.
Load address: 0x30000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #########################
done
Bytes transferred = 8952768 (889bc0 hex)
SMDK2410 # nand erase.part rootfs

NAND erase.part: device 0 offset 0x260000, size 0xfda0000
Skipping bad block at  0x0cfe0000
Erasing at 0xffe0000 -- 100% complete.
OK
SMDK2410 # nand write.yaffs 30000000 260000  889bc0

NAND write: device 0 offset 0x260000, size 0x889bc0
Unknown nand command suffix '.yaffs'. < -- 燒寫失敗,需修改uboot源碼

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

找關鍵字 "Unknown nand command suffix" 可在cmd_nand.c文件裡找到
1. 將 ONFIG_CMD_NAND_YAFFS 定義進smdk2440.h
需比對二進制文件(需再研究)
2. 在 drivers/mtd/nand/nand_util.c中,
     Nand_util.c 中
ops.mode = MTD_OOB_AUTO, 修改成 ops.mode =MTD_OOB_RAW
                                      if (!rval), 修改成 if(rval)
if (!need_skip && !(flags & WITH_DROP_FFS))
修改成 if (!need_skip && !(flags & WITH_DROP_FFS) && !(flags & WITH_YAFFS_OOB)) {

------------------------------------------------
U-Boot 2012.04.01 (Sep 19 2015 - 01:20:12)

CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0
SMDK2410 # tftp 30000000 fs_mini_mdev.yaffs2
ERROR: resetting DM9000 -> not responding
dm9000 i/o: 0x20000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:0c:29:2f:4e:70
could not establish link
Using dm9000 device
TFTP from server 192.168.0.254; our IP address is 192.168.0.110
Filename 'fs_mini_mdev.yaffs2'.
Load address: 0x30000000
Loading: T #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #########################
done
Bytes transferred = 8952768 (889bc0 hex)
SMDK2410 # nand erase.part rootfs

NAND erase.part: device 0 offset 0x260000, size 0xfda0000
Skipping bad block at  0x0cfe0000
Erasing at 0xffe0000 -- 100% complete.
OK
SMDK2410 # nand write.yaffs 30000000 260000  889bc0

NAND write: device 0 offset 0x260000, size 0x889bc0

 8952768 bytes written: OK
重新啟動 kernel、yaffs2文件成功載入
...........
VFS: Mounted root (yaffs filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 764, tty '': '/etc/init.d/rcS'
s3c2410-sdi s3c2410-sdi: running at 0kHz (requested: 0kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).
s3c2410-sdi s3c2410-sdi: running at 98kHz (requested: 97kHz).

Please press Enter to activate this console.
starting pid 770, tty '/dev/s3c2410_serial0': '/bin/sh'

===========================================================
3.8.7 製作patch
make distclean

mv   u-boot-2012.04.01   u-boot-2012.04.01_scyu
diff   -urN u-boot-2012.04.01   u-boot-2012.04.01_scyu > u-boot-2012.04.01_scyu.patch

使用patch
cd u-boot-2012.04.01
patch -p1 < ../u-boot-2012.04.01_scyu.patch

No comments:

Post a Comment