2009年9月7日 星期一

vivi Memory 常數




/* Flash */
#define FLASH_BASE                       ROM_BASE0    /* 0x3000 0000 */
#define FLASH_SIZE                       SZ_32M
#define FLASH_UNCACHED_BASE       0x10000000    /* to mapping flash memory */
#define FLASH_BUSWIDTH               4
/* ROM */
#define VIVI_ROM_BASE                  0x00000000
#define VIVI_PRIV_ROM_BASE           0x01FC0000














/* Porocessor memory map */
#define ROM_BASE0          0x00000000      /* base address of rom bank 0 */
#define ROM_BASE1          0x08000000      /* base address of rom bank 1 */
#define DRAM_BASE0        0x30000000      /* base address of dram bank 0 */
#define DRAM_BASE1        0x38000000        /* base address of dram bank 1 */




#define DRAM_BASE          DRAM_BASE0   /* 0x3000 0000*/
#define DRAM_SIZE          SZ_64M      

#define MTD_PART_SIZE                       SZ_16K   /* 16k=0x40000 */
#define MTD_PART_OFFSET                   0x00000000
#define PARAMETER_TLB_SIZE               SZ_16K   /* 16k=0x4000 */
#define PARAMETER_TLB_OFFSET           0x00004000
#define LINUX_CMD_SIZE                      SZ_16K  
#define LINUX_CMD_OFFSET                  0x00008000
#define VIVI_PRIV_SIZE                        (MTD_PART_SIZE + PARAMETER_TLB_SIZE + LINUX_CMD_SIZE) 




/* 16k+16k+16k=48k=*/


/* RAM */
#define VIVI_RAM_SIZE                   SZ_1M 
#define VIVI_RAM_BASE                  (DRAM_BASE + DRAM_SIZE - VIVI_RAM_SIZE) 




/* 0x3000 0000 + 64M - 1M = 0x33ff ffff - 1M = 0x33ef ffff*/




#define HEAP_SIZE                         SZ_1M
#define HEAP_BASE                        (VIVI_RAM_BASE - HEAP_SIZE)




/* 0x33ef ffff - 1M = 0x33df ffff*/




#define MMU_TABLE_SIZE                SZ_16K
#define MMU_TABLE_BASE               (HEAP_BASE - MMU_TABLE_SIZE)




/* 0x33df ffff - 16k = 0x33df bfff*/




#define VIVI_PRIV_RAM_BASE           (MMU_TABLE_BASE - VIVI_PRIV_SIZE)




/* 0x33df bfff - 48k= 0x33de ffff*/




#define STACK_SIZE                       SZ_32K
#define STACK_BASE                      (VIVI_PRIV_RAM_BASE - STACK_SIZE)




/* 0x33de ffff - 32k = 0x33de 7fff*/




#define RAM_SIZE                          (STACK_BASE - DRAM_BASE)




/* 0x33de 7fff - 0x3000 000 = 0x3de 7fff = 64M - 1M - 1M - 16K-48K-16K - 32k= 61M + 912K*/




#define RAM_BASE                          DRAM_BASE 




/* 0x3000 0000 */


2009年9月6日 星期日

移植 linux-2.6.26 內核





主機:
ubuntu 8.04 (linux-2.6.24-19)
gcc-4.2

目標板:
s3c2440

交叉編譯器:
請參考
ubuntu 開發環境設置 For embedded system
 
要移植的內核版本:
linux-2.6.26

文件系統:
cramfs
---------------------------------------------------------------------------------------------------
準備知識:

Linux支持多種平台架構。在原始碼的arch目錄下,已經將各種支援的平台架構的原始碼分門別類。為了配置方便,在各種平台架構的目錄下,一般都配有一個名為configs的目錄。其中,放著許多已經初步配置好的defconfig文件。通過這些defconfig文件,加快了我們編譯內核的速度。
比如我所用的是一個arm架構的s3c2440板,那我就可以從arch/arm/configs/中找到s3c2410_defconfig,這是目前最相似2440的一個設定文件了。使用:
$ make s3c2410_defconfig

$ cp arch/arm/configs/s3c2410_defconfig ./.config

執行上面命令後,將會在原始碼目錄下產生.config配置文件。執行

$ make menuconfig
$ make xconfig


可以進一步配置內核。最後執行

$ make zImage


生成我們所需的燒錄文件

內核編譯基本命令:

make mrproper --- 清理全部文件,包括.config和一些備份文件, 或
make clean --- 清理生成文件,但會保留.config和一些模塊文件。

make defconfig --- 產生包含全部預設選項的.config文件。這裡用make s3c2410_defconfig替代
make oldconfig --- 在舊的.config基礎上生成新的.config。如果只想在原來內核配置的基礎上修改一些小地方,會省去不少麻煩

make config --- 基於文本的最為傳統的配置界面,不推薦使用
make menuconfig --- 基於文本選單的配置界面,字符終端下推薦使用
make xconfig --- 基於圖形窗口模式的配置界面,Xwindow下推薦使用
  
   目的都是生成一個.config文件,這三個命令中,make xconfig的界面最為友好,如果你可以使用Xwindow,你就用這個好了,這個比較方便,也好設置。如果你不能使用Xwindow,那麼就使用 make menuconfig好了。界面雖然比上面一個差點,總比make config的要好多了。

make --- 預設編譯。
make bzImage --- 編譯生成壓縮的核心二進制檔案,也會用make zImage替代

---------------------------------------------------------------------------------------------------
參考資料:
Linux2.6.22.2內核移植方法
移植內核2.6.24.4到S3C2440
《  對於Kernel panic - ……出錯的一點總結!

---------------------------------------------------------------------------------------------------
移植linux-2.6.26內核(假設已下載linux-2.6.26.tar.bz2)

1. 解壓源代碼

$ tar jxvf linux-2.6.26.tar.bz2

$ cd linux-2.6.26


2. 更改Makefile

#ARCH        ?= $(SUBARCH)

#CROSS_COMPILE    ?=
ARCH        ?= arm
CROSS_COMPILE    ?= /usr/local/arm/4.0.3/arm-linux-gnu/bin/arm-linux-gnu-


3. 產生預設配置

$ make s3c2410_defconfig


4. 增加devfs文件系統支持
linux2.6.26已經去掉devfs,為了內核支援devfs以及在啟動時並在/sbin/init運行之前能自動掛載/dev為devfs文件系統,修改fs的Kconfig文件。
linux-2.6.26/fs/Kconfig

修改的內容:
找到menu "Pseudo filesystems"
增加底下的程式:
  
config DEVFS_FS

    bool "/dev file system support (OBSOLETE)"
    depends on EXPERIMENTAL
    help
      This is support for devfs, a virtual file system (like /proc) which
      provides the file system interface to device drivers, normally found
      in /dev. Devfs does not depend on major and minor number
      allocations. Device drivers register entries in /dev which then
      appear automatically, which means that the system administrator does
      not have to create character and block special device files in the
      /dev directory using the mknod command (or MAKEDEV script) anymore.

      This is work in progress. If you want to use this, you *must* read
      the material in , especially
      the file README there.

      Note that devfs no longer manages /dev/pts! If you are using UNIX98
      ptys, you will also need to mount the /dev/pts filesystem (devpts).

      Note that devfs has been obsoleted by udev,
      <http://www.kernel.org/pub/linux/utils/kernel/hotplug/>.
      It has been stripped down to a bare minimum and is only provided for
      legacy installations that use its naming scheme which is
      unfortunately different from the names normal Linux installations
      use.

      If unsure, say N.

config DEVFS_MOUNT
    bool "Automatically mount at boot"
    depends on DEVFS_FS
    help
      This option appears if you have CONFIG_DEVFS_FS enabled. Setting
      this to 'Y' will make the kernel automatically mount devfs onto /dev
      when the system is booted, before the init thread is started.
      You can override this with the "devfs=nomount" boot option.

      If unsure, say N.

config DEVFS_DEBUG
    bool "Debug devfs"
    depends on DEVFS_FS
    help
      If you say Y here, then the /dev file system code will generate
      debugging messages. See the file
      for more details.

      If unsure, say N.


5. 修改時鐘頻率( 可解決印出訊息有亂碼問題 )
文件:arch/arm/mach-s3c2440/mach-smdk2440.c

    /*s3c24xx_init_clocks(16934400);*/

    s3c24xx_init_clocks(12000000);

6. 修改MTD分區
文件: arch/arm/plat-s3c24xx/common-smdk.c

/* fix mtd partition to be same with bootloader */

/* a flash all in 64M bit size have been devided into 4 partition: */
/*   1. boot : offset is 0 and size is 192k */
/*   2. kernel : offset is 0x30000 and size is 1856k */
/*   3. rootfs : offset is 0x200000 and size is 30M */
/*   4. ext-fs1 : offset is 0x2000000 and size is 32M */
static struct mtd_partition smdk_default_nand_part[] = {
    [0] = {
        .name    = "boot", /* default is "Boot Agent", by qspy */
        .size    = SZ_64K*3,  /* default is SZ_16K, qspy fix it to 192K*/
        .offset    = 0,
    },
    [1] = {
        .name    = "kernel", /* default is "S3C2410 flash partition 1", by qspy */
        .offset = SZ_64K*3,/* default is 0, by qspy */
        .size    = SZ_64K*29,/* default is SZ_2M, qspy fix it to 1856K*/
    },
    [2] = {
        .name    = "rootfs",/* default is "S3C2410 flash partition 2", by qspy */
        .offset = SZ_2M,/* default is SZ_4M, by qspy */
        .size    = SZ_1M*30,/* default is SZ_4M, qspy fix it to 30M*/
    },
    [3] = {
        .name    = "ext-fs1",/* default is "S3C2410 flash partition 2", by qspy */
        .offset    = SZ_32M,/* default is SZ_8M, by qspy */
        .size    = SZ_32M,/* default is SZ_2M, qspy fix it to 30M*/
    },
   };

  
7. 關閉ECC檢查
文件:drivers/mtd/nand/s3c2410.c
函數:s3c2410_nand_init_chip
        /*chip->ecc.mode        = NAND_ECC_SOFT; */

        chip->ecc.mode    = NAND_ECC_NONE;

8. 設定內核

$ make xconfig

其中有幾項一定要修改的,分別是:

a. 啟動
|---Boot options

|    |---Default kernel command string: [root=/dev/mtdblock2 rootfstype=cramfs init=/linuxrc console=ttySAC1,115200 devfs=mount mem=64]

分析:
/dev/mtdblock2 : 表示MTD分區的第2個分區存儲根文件系統
rootfstype=cramfs : 分區是cramfs類型,這項不加應該關係不大
init=/linuxrc : 啟動的首個腳本就是根目錄下的linuxrc
console=ttySAC1,115200 : 使用串口1作為串口輸出,波特率設置為115200; 現在已經放棄了以前使用ttyS0的寫法
devfs=mount : 在/sbin/init運行之前能自動掛載/dev為devfs文件系統
mem=64 : 記憶體大小為64M

b. 增加devfs文件系統支持

|---File systems

|    |---Pseudo filesystems
|    |      |---/dev file system support
|    |      |      |---Automatically mount at boot
|    |      |      |---Debug devfs

 
這幾項都是必選的

c. CPU及系統類型

|---System Type

|    |---S3C2410 Machines
|    |      |---SMDK2410/A9M2410

支持2440時,這一項也是必選的,否則會編譯不過

-----------------------------------------------------
遇到的問題:

1. 啟動時亂碼
信息:

Nand flash status = c0

Set boot params = root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount display=shp480
Load Kernel...
8??腳c?泉''D?G#溰 `納 { 悃\'榌

解決:時鐘問題,更改時鐘頻率為12M即可

2. 文件系統cramfs掛載失敗

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
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (double precision)
msgmni has been set to 120
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
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
usbcore: registered new interface driver ub
dm9000 Ethernet Driver, V1.30
Linux video capture interface: v2.00
NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c $Revision: 1.41 $
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=4 40ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
s3c2410_nand_update_chip: chip c3d7d4bc: 9
Scanning device for bad blocks
Bad eraseblock 357 at 0x00594000
Bad eraseblock 3335 at 0x0341c000
Bad eraseblock 3995 at 0x03e6c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "boot"
0x00030000-0x00200000 : "kernel"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "ext-fs1"
usbmon: debugfs is not available
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
i2c /dev entries driver
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
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Registered led device: led4
Registered led device: led5
Registered led device: led6
Registered led device: led7
TCP cubic registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
end_request: I/O error, dev mtdblock2, sector 2
EXT2-fs: unable to read superblock
end_request: I/O error, dev mtdblock2, sector 0
Buffer I/O error on device mtdblock2, logical block 0
end_request: I/O error, dev mtdblock2, sector 0
Buffer I/O error on device mtdblock2, logical block 0
end_request: I/O error, dev mtdblock2, sector 8
Buffer I/O error on device mtdblock2, logical block 1
end_request: I/O error, dev mtdblock2, sector 8
Buffer I/O error on device mtdblock2, logical block 1
end_request: I/O error, dev mtdblock2, sector 16
Buffer I/O error on device mtdblock2, logical block 2
end_request: I/O error, dev mtdblock2, sector 16
Buffer I/O error on device mtdblock2, logical block 2
end_request: I/O error, dev mtdblock2, sector 24
Buffer I/O error on device mtdblock2, logical block 3
end_request: I/O error, dev mtdblock2, sector 24
Buffer I/O error on device mtdblock2, logical block 3
end_request: I/O error, dev mtdblock2, sector 0
FAT: unable to read boot sector
VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)
Please append a correct "root=" boot option; here are the available partitions:
1f00        192 mtdblock0 (driver?)
1f01       1856 mtdblock1 (driver?)
1f02      30720 mtdblock2 (driver?)
1f03      32768 mtdblock3 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)

問題可能:
a。MTD分區與bootloader不匹配
b。沒有 devfs文件系統支持
c。ECC校驗沒有關閉

3. /linuxrc初始化失敗
Linux video capture interface: v2.00

NFTL driver: nftlcore.c $Revision: 1.98 $, nftlmount.c $Revision: 1.41 $
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=4 40ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
s3c2410_nand_update_chip: chip c3d704bc: 9
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Bad eraseblock 357 at 0x00594000
Bad eraseblock 3335 at 0x0341c000
Bad eraseblock 3995 at 0x03e6c000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "boot"
0x00030000-0x00200000 : "kernel"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "ext-fs1"
usbmon: debugfs is not available
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
i2c /dev entries driver
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
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
Registered led device: led4
Registered led device: led5
Registered led device: led6
Registered led device: led7
TCP cubic registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 124K
cramfs: bad compressed blocksize 989432407
cramfs: bad compressed blocksize 4274059297
Failed to execute /linuxrc.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.

問題可能:
a。 "Default kernel command string"設置有誤,比如啟動分區指定不對
b。 可能是文件系統有問題