歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> S3C6410 完全由SD卡啟動Linux流程

S3C6410 完全由SD卡啟動Linux流程

日期:2017/3/1 10:56:58   编辑:Linux編程
1. s3c6410 SD啟動原理
s3c6410 支持Nand Flash本地啟動Linux,包括內核,根文件系統,bootloader均寫入在Nand Flash.這樣可以獨立運行.
很多情況下,Nand Flash的某種原因無法寫入內核和Rootfs.而使用tftp下載內核,用NFS啟動根文件系統比較慢.s3c6410 支持 SD卡啟動,經過改造u-boot可以從SD卡引導內核,這樣而Linux 又可以從SD卡的裝載ext3根文件系統.這樣可以制作一個完整的SD卡啟動卡.

這樣bootloader(u-boot)可以寫入SD卡,引導扇區. bootloader的第一階段把自己裝入在內存高端地址看後,可以用兩種方法從SD卡裝入內核到內存. 一種是用fatload命令從fat分區裝入內核文件到內存。 fatload mmc 1 address filename (上述命令表示從第一個mmc設備裝入文件filename到內存的address當中),這個需要完整的實現fat的驅動,因此很多u-boot沒有帶. 另外一種常見的做法是使用u-boot的movi 命令. 用movi 命令直接讀寫SD卡sector.但是這樣有可以與文件系統有沖突,因此要小心分區. 後面就是用這個方法來實現啟動的.可以把movi讀入命令寫入bootcmd 實現自動啟動
3.內核裝入後,可以支持用ext3的格式作根文件系統,這樣可以把SD卡一個分區格式化成ext3即 可以啟動 ,這樣要修改bootargs
這個可以參考<<ARM-Linux使用SD卡根文件系統>> http://www.linuxidc.com/Linux/2011-11/47797.htm
2.Linux SD分區操作.
支持這種需要2G以下,非SDHC卡,假設是一個2G SD卡,分300M給FAT,剩下全部給 EXT3格式,作根文件系統。 bootloader寫在SD卡的引導區,不占用分區空間 Linux 對SD卡的的操作,如果第一個插入的SD卡是 /dev/sda,第二個SD卡是/dev/sdb ...依次類推. 如果第一個SD卡的第一個分區是 /dev/sda1 ,第二個分區 /dev/sda2 .如果上一個卡(sda)未安全撥下,而第二次插入也會變成sdb. 所以插入卡時要小心檢測SD卡對應的設備結點.

2.1 Linux 分區工具 fdisk.
fdisk 與dos下的工具同名,在操作SD分區,最好把分區文件目錄umount掉,否則會修改分區失敗,也注意要把SD卡的寫保護鎖打開. 命令格式 fdisk <設備結點> 這是指設備結點/dev/sda之類,不要對/dev/sda1 之類操作.
  1. # fdisk /dev/sda
  2. The number of cylinders for this disk is set to 35560.
  3. There is nothing wrong with that, but this is larger than 1024,
  4. and could in certain setups cause problems with:
  5. 1) software that runs at boot time (e.g., old versions of LILO)
  6. 2) booting and partitioning software from other OSs
  7. (e.g., DOS FDISK, OS/2 FDISK)
  8. Command (m for help): m #<------------顯示fdisk菜單
  9. Command action
  10. a toggle a bootable flag
  11. b edit bsd disklabel
  12. c toggle the dos compatibility flag
  13. d delete a partition
  14. l list known partition types
  15. m print this menu
  16. n add a new partition
  17. o create a new empty DOS partition table
  18. p print the partition table
  19. q quit without saving changes
  20. s create a new empty Sun disklabel
  21. t change a partition's system id
  22. u change display/entry units
  23. v verify the partition table
  24. w write table to disk and exit
  25. x extra functionality (experts only)
  26. Command (m for help): p #<--------------------打印分區表
  27. Disk /dev/sda: 2002 MB, 2002780160 bytes
  28. 11 heads, 10 sectors/track, 35560 cylinders
  29. Units = cylinders of 110 * 512 = 56320 bytes
  30. Device Boot Start End Blocks Id System
  31. /dev/sda1 2 35561 1955775+ b W95 FAT32 #原有的FAT32分區
接下操作,是刪除原有分區,並且新建兩個分區,一個用FAT,一個是EXT32根文件系統
  1. Command (m for help): d #<-------------刪除一個分區
  2. Selected partition 1
  3. Command (m for help): n #<-------------新建一個分區
  4. Command action
  5. e extended
  6. p primary partition (1-4)
  7. p #<--------------選擇創建 primary 首要分區
  8. Partition number (1-4): 1 #<---------第一個首要分區
  9. First cylinder (1-35560, default 1): #<---------起始位置,直接回車用缺省值
  10. Using default value 1
  11. Last cylinder or +size or +sizeM or +sizeK (1-35560, default 35560): 300M
  12. #<---- 第一個分區使用 300M空間
  13. Command (m for help): p
  14. Disk /dev/sda: 2002 MB, 2002780160 bytes
  15. 11 heads, 10 sectors/track, 35560 cylinders
  16. Units = cylinders of 110 * 512 = 56320 bytes
  17. Device Boot Start End Blocks Id System
  18. /dev/sda1 1 300 16495 83 Linux
  19. Command (m for help): n #<----建第二個分區
  20. Command action
  21. e extended
  22. p primary partition (1-4)
  23. p #<--------------選擇創建 primary 首要分區
  24. Partition number (1-4): 2 #<---------第二個首要分區
  25. First cylinder (301-35560, default 301):
  26. Using default value 301
  27. Last cylinder or +size or +sizeM or +sizeK (301-35560, default 35560):
  28. Using default value 35560 #直接回車表示缺省值,即把剩下所有空間都歸入這個分區
  29. Command (m for help): p
  30. Disk /dev/sda: 2002 MB, 2002780160 bytes
  31. 11 heads, 10 sectors/track, 35560 cylinders
  32. Units = cylinders of 110 * 512 = 56320 bytes
  33. Device Boot Start End Blocks Id System
  34. /dev/sda1 1 300 16495 83 Linux
  35. /dev/sda2 301 35560 1939300 83 Linux
  36. Command (m for help): w #<-------將分區表寫入SD卡,至此才真正生效
  37. The partition table has been altered!
  38. Calling ioctl() to re-read partition table.
  39. Syncing disks.

2.2 格式化兩個分區 第一個格式化成 FAT mkfs.vfat /dev/sda1 第二個格式化 格式ext3 格式 mkfs.ext3 /dev/sda2
  1. # mkfs.vfat /dev/sda1 #<----------格式化命令
  2. mkfs.vfat 2.11 (12 Mar 2005)
  3. [root@tch u-boot-1.1.6_hxy6410]# mkfs.ext3 /dev/sda2 #<------格式化命令
  4. mke2fs 1.39 (29-May-2006)
  5. Filesystem label=
  6. OS type: Linux
  7. Block size=4096 (log=2)
  8. Fragment size=4096 (log=2)
  9. 242880 inodes, 484825 blocks
  10. 24241 blocks (5.00%) reserved for the super user
  11. First data block=0
  12. Maximum filesystem blocks=499122176
  13. 15 block groups
  14. 32768 blocks per group, 32768 fragments per group
  15. 16192 inodes per group
  16. Superblock backups stored on blocks:
  17. 32768, 98304, 163840, 229376, 294912
  18. Writing inode tables: done
  19. Creating journal (8192 blocks): done
  20. Writing superblocks and filesystem accounting information:
  21. done
  22. This filesystem will be automatically checked every 33 mounts or
  23. 180 days, whichever comes first. Use tune2fs -c or -i to override.

2.3 測試文件系統是否可以用 mount -t ext3 /dev/sda2 /mnt
2.4 把根文件系統拷入SD卡,r表示遞歸,a表示把權限,符號鏈接等信息也拷貝 cp -ra /home/hxy/rootfs/* /mnt
Copyright © Linux教程網 All Rights Reserved