1.mtdåmtdblockçåºå«
2.åä¸ä¸ªåµå
¥å¼Linuxç³»ç»ç©¶ç«è¦ååªäºå·¥ä½
mtdåmtdblockçåºå«
mtd-utilså·¥å ·å¯¹mtdåmtdblockååºè®¾å¤çåºå«å¤ç
1 / $ flash_eraseall /dev/mtdblock/2
2 flash_eraseall: /dev/mtdblock/2: unable to get MTD device info
3 / $ flash_eraseall /dev/mtdblock/2
4 flash_eraseall: /dev/mtdblock/2: unable to get MTD device info
5 / $ flash_eraseall /dev/mtd/2
6 Erasing Kibyte @ 8e -- % complete.
7 / $ ls
1 / $ flashcp rootfs_version /dev/mtdblock2
2 This javaweb在线买药系统源码doesn't seem to be a valid MTD flash device!
3 / $ flashcp rootfs_version /dev/mtdblock/2
4 This doesn't seem to be a valid MTD flash device!
5 / $ flashcp rootfs_version /dev/mtd2
6 / $ ls
mtdåmtdblockååºè®¾å¤mountæ¶çåºå«
1 / $ mount -t jffs2 /dev/mtd/2 qqzm/
2 mount: Mounting /dev/mtd/2 on qqzm/ failed: Invalid argument
3 / $ mount -t jffs2 /dev/mtd2 qqzm/
4 mount: Mounting /dev/mtd2 on qqzm/ failed: Invalid argument
5 / $ mount -t jffs2 /dev/mtdblock/2 qqzm/
6 / $ ls
mtdblockæè½½æåï¼åæ¦é¤åå¸è½½å¤±è´¥
/ $ flash_eraseall /dev/mtd/2 <span></span> Erasing Kibyte @ 8e -- % complete.
/qqzm $ mount
/dev/root on / type jffs2 (rw,noatime)
proc on /proc type proc (rw,nodiratime)
sysfs on /sys type sysfs (rw)
devfs on /dev type devfs (rw)
devpts on /dev/pts type devpts (rw)
/dev/mmcblk0p1 on /mnt/sd type vfat (rw,nodiratime,fmask=,dmask=,codepage=cp,iocharset=iso-1)
/dev/mtdblock/2 on /qqzm type jffs2 (rw,noatime)
none on /qqzm/www/cgi-bin/tmp type ramfs (rw)
/qqzm $ cd ..
/ $ umount /qqzm
umount: Couldn't umount /qqzm: Inappropriate ioctl for device
/ $ umount /dev/mtdblock/2
umount: Couldn't umount /dev/mtdblock/2: Inappropriate ioctl for device
/ $
MTDææ¯çåºæ¬åç
MTD(memory technology deviceå åææ¯è®¾å¤)æ¯ç¨äºè®¿é®memory设å¤ï¼ROMãflashï¼çLinuxçåç³»ç»ãMTDç主è¦ç®çæ¯ä¸ºäºä½¿æ°çmemory设å¤ç驱å¨æ´å ç®åï¼ä¸ºæ¤å®å¨ç¡¬ä»¶åä¸å±ä¹é´æä¾äºä¸ä¸ªæ½è±¡çæ¥å£ï¼å¹¶è¿è¡äºä¸ä¸ªå±æ¬¡ååï¼å±æ¬¡ä»ä¸å°ä¸å¤§è´ä¸ºï¼è®¾å¤æ件ãMTD设å¤å±ãMTDåå§è®¾å¤å±ã硬件驱å¨å±ãMTDçæææºä»£ç å¨/drivers/mtdåç®å½ä¸ã
ç³»ç»ä¸çMTD设å¤æ件
~ $ ls /dev/mtd* -l
crw-rw---- 1 root root , 0 Jan 1 : /dev/mtd0
crw-rw---- 1 root root , 1 Jan 1 : /dev/mtd0ro
crw-rw---- 1 root root , 2 Jan 1 : /dev/mtd1
crw-rw---- 1 root root , 3 Jan 1 : /dev/mtd1ro
crw-rw---- 1 root root , 4 Jan 1 : /dev/mtd2
crw-rw---- 1 root root , 5 Jan 1 : /dev/mtd2ro
crw-rw---- 1 root root , 6 Jan 1 : /dev/mtd3
crw-rw---- 1 root root , 7 Jan 1 : /dev/mtd3ro
brw-rw---- 1 root root , 0 Jan 1 : /dev/mtdblock0
brw-rw---- 1 root root , 1 Jan 1 : /dev/mtdblock1
brw-rw---- 1 root root , 2 Jan 1 : /dev/mtdblock2
brw-rw---- 1 root root , 3 Jan 1 : /dev/mtdblock3
/dev/mtd:
crw-rw-rw- 1 root root , 0 Jan 1 : 0
cr--r--r-- 1 root root , 1 Jan 1 : 0ro
crw-rw-rw- 1 root root , 2 Jan 1 : 1
cr--r--r-- 1 root root , 3 Jan 1 : 1ro
crw-rw-rw- 1 root root , 4 Jan 1 : 2
cr--r--r-- 1 root root , 5 Jan 1 : 2ro
crw-rw-rw- 1 root root , 6 Jan 1 : 3
cr--r--r-- 1 root root , 7 Jan 1 : 3ro
/dev/mtdblock:
brw------- 1 root root , 0 Jan 1 : 0
brw------- 1 root root , 1 Jan 1 : 1
brw------- 1 root root , 2 Jan 1 : 2
brw------- 1 root root , 3 Jan 1 : 3
~ $
å¯ä»¥çå°æmtdNå对åºç/dev/mtd/NãmtdblockNå对åºç/dev/mtdblock/N两类MTD设å¤ï¼åå«æ¯å符设å¤ï¼ä¸»è®¾å¤å·åå设å¤ï¼ä¸»è®¾å¤å·ãå ¶ä¸/dev/mtd0å/dev/mtd/0æ¯å®å ¨çä»·çï¼/dev/mtdblock0å/dev/mtdblock/0æ¯å®å ¨çä»·çï¼è/dev/mtd0å/dev/mtdblock0åæ¯åä¸ä¸ªMTDååºç两ç§ä¸ååºç¨æè¿°ï¼æä½ä¸æ¯æåºå«çã
/dev/mtdN设å¤
/dev/mtdN æ¯MTDæ¶æä¸å®ç°çmtdååºæ对åºçå符设å¤(å°mtd设å¤åæå¤ä¸ªåºï¼æ¯ä¸ªåºå°±ä¸ºä¸ä¸ªå符设å¤)ï¼å ¶éé¢æ·»å äºä¸äºioctlï¼æ¯æå¾å¤å½ä»¤ï¼å¦MEMGETINFOï¼MEMERASEçã
mtd-utilsä¸çflash_eraseallçå·¥å ·ï¼å°±æ¯ä»¥è¿äºioctl为åºç¡èå®ç°çå·¥å ·ï¼å®ç°ä¸äºå ³äºFlashçæä½ãæ¯å¦ï¼mtd å·¥å ·ä¸ flash_eraseallä¸ï¼
1 if (ioctl(fd, MEMGETINFO, &meminfo) != 0)
2 {
3 fprintf(stderr, "%s: %s: unable to get MTD device info\n",exe_name, mtd_device);
4 return 1;
5 }
MEMGETINFOæ¯Linux MTDä¸çdrivers/mtd/mtdchar.cä¸çioctlå½ä»¤ï¼ä½¿ç¨mtdå符设å¤éè¦å è½½mtdcharå æ ¸æ¨¡åã该代ç 解éäºä¸é¢ç第ä¸ä¸ªç°è±¡ã
/dev/mtdblockN设å¤
/dev/mtdblockNï¼æ¯Flash驱å¨ä¸ç¨add_mtd_partitions()æ·»å MTD设å¤ååºï¼èçæç对åºçå设å¤ãMTDå设å¤é©±å¨ç¨åºå¯ä»¥è®©flashå¨ä»¶ä¼ªè£ æå设å¤ï¼å®é ä¸å®éè¿ææ´åçerase blockæ¾å°raméé¢è¿è¡è®¿é®ï¼ç¶ååæ´æ°å°flashï¼ç¨æ·å¯ä»¥å¨è¿ä¸ªå设å¤ä¸å建é常çæ件系ç»ã
è对äºMTDå设å¤ï¼MTD设å¤å±æ¯ä¸æä¾ioctlçå®ç°æ¹æ³çï¼ä¹å°±ä¸ä¼æ对åºçMEMGETINFOå½ä»¤ä¹ç±»ï¼å æ¤ä¸è½ä½¿ç¨nandwrite,flash_eraseall,flash_eraseçå·¥å ·å»å¯¹/dev/mtdblockNå»è¿è¡æä½ï¼å¦åå°±ä¼åºç°ä¸é¢çç°è±¡ä¸ï¼åæ¶ä¹è§£éäºç°è±¡3ââç¨mtd2æ¦é¤ååºåï¼å¨ç¨mtdblock2è¿è¡umountå°±ä¼é ææ··ä¹±ã
mtdå设å¤ç大å°å¯ä»¥éè¿procæ件系ç»è¿è¡æ¥çï¼
~ $ cat /proc/partitions
major minor #blocks name
0 mtdblock0
1 mtdblock1
2 mtdblock2
3 mtdblock3
0 mmcblk0
1 mmcblk0p1
~ $
åé¢ç两个æ¯SDå设å¤çååºå¤§å°ãæ¯ä¸ªblockç大å°æ¯1KBã
MTD设å¤ååºåæ»ç»
éè¿procæ件系ç»æ¥çmtd设å¤çååºæ åµï¼
1 ~ $ cat /proc/mtd
2 dev: size erasesize name
3 mtd0: "boot"
4 mtd1: "kernel"
5 mtd2: "roofs"
6 mtd3: "app"
7 ~ $
å¯ä»¥åç°ï¼å®é ä¸mtdNåmtdblockNæè¿°çæ¯åä¸ä¸ªMTDååºï¼å¯¹åºåä¸ä¸ªç¡¬ä»¶ååºï¼ä¸¤è ç大å°æ¯ä¸æ ·çï¼åªä¸è¿æ¯MTD设å¤å±æä¾ç»ä¸å±çè§å¾ä¸ä¸æ ·ï¼ç»ä¸å±æä¾äºå符åå设å¤ä¸¤ç§æä½è§å¾ââ为äºä¸å±ä½¿ç¨ç便å©åéè¦ï¼æ¯å¦mountå½ä»¤çéæ±ï¼ä½ åªè½æè½½å设å¤(ææ件系ç»)ï¼èä¸è½å¯¹å符设å¤è¿è¡æè½½ï¼å¦åä¼åºç°ä¸é¢çç°è±¡2:æ æåæ°ã
è¿é对äºmtdåmtdblock设å¤ç使ç¨åºæ¯è¿è¡ç®åæ»ç»ï¼
mtd-utilså·¥å ·åªè½åºç¨ä¸/dev/mtdNçMTDå符设å¤
mountãumountå½ä»¤åªå¯¹/dev/mtdblockNçMTDå设å¤ææ
/dev/mtdNå/dev/mtdblockNæ¯åä¸ä¸ªMTD设å¤çåä¸ä¸ªååºï¼Nä¸æ ·ï¼
åä¸ä¸ªåµå ¥å¼Linuxç³»ç»ç©¶ç«è¦ååªäºå·¥ä½
ãã1ãLinux åºç¡
ããå®è£ Linuxæä½ç³»ç» Linuxæä»¶ç³»ç» Linux常ç¨å½ä»¤ Linuxå¯å¨è¿ç¨è¯¦è§£ çæLinuxæå¡è½å¤ç¬ç«å®è£ Linuxæä½ç³»ç»
è½å¤çç»ä½¿ç¨Linuxç³»ç»çåºæ¬å½ä»¤ 认è¯Linuxç³»ç»ç常ç¨æå¡å®è£ Linuxæä½ç³»ç» Linuxåºæ¬å½ä»¤å®è·µ 设置Linuxç¯å¢åé å®å¶Linuxçæå¡
Shell ç¼ç¨åºç¡ä½¿ç¨viç¼è¾æ件 使ç¨Emacsç¼è¾æ件 使ç¨å ¶ä»ç¼è¾å¨
ãã2ãShell ç¼ç¨åºç¡
ããShellç®ä» 认è¯åå°ç¨åºBashç¼ç¨çæLinuxç³»ç»ä¸çç¼è¾ç¯å¢ çæLinuxä¸çåç§Shell çç»è¿è¡shellç¼ç¨çæviåºæ¬æä½
çæEmacsçåºæ¬æä½ æ¯è¾ä¸åshellçåºå« ç¼åä¸ä¸ªæµè¯æå¡å¨æ¯å¦è¿éçshellèæ¬ç¨åº ç¼åä¸ä¸ªæ¥çè¿ç¨æ¯å¦åå¨çshellèæ¬ç¨åº
ç¼åä¸ä¸ªå¸¦æ循ç¯è¯å¥çshellèæ¬ç¨åº
ãã3ãLinux ä¸çC ç¼ç¨åºç¡
ããlinux Cè¯è¨ç¯å¢æ¦è¿° Gcc使ç¨æ¹æ³ Gdbè°è¯ææ¯ Autoconf Automake Makefile 代ç ä¼å
çæLinuxç³»ç»ä¸çå¼åç¯å¢ çæGccç¼è¯å¨ çæMakefileè§åç¼åHello,Worldç¨åº ä½¿ç¨ makeå½ä»¤ç¼è¯ç¨åº ç¼å带æä¸ä¸ªå¾ªç¯çç¨åº
è°è¯ä¸ä¸ªæé®é¢çç¨åº
ãã4ãåµå ¥å¼ç³»ç»å¼ååºç¡
ããåµå ¥å¼ç³»ç»æ¦è¿°äº¤åç¼è¯ é ç½®TFTPæå¡ é ç½®NFSæå¡ ä¸è½½Bootloaderåå æ ¸
åµå ¥å¼Linuxåºç¨è½¯ä»¶å¼åæµç¨çæåµå ¥å¼ç³»ç»æ¦å¿µä»¥åå¼åæµç¨ 建ç«åµå ¥å¼ç³»ç»å¼åç¯å¢å¶ä½cross_gccå·¥å ·é¾ ç¼è¯å¹¶ä¸è½½U-boot
ç¼è¯å¹¶ä¸è½½Linuxå æ ¸ ç¼è¯å¹¶ä¸è½½Linuxåºç¨ç¨åº
ãã5ãåµå ¥å¼ç³»ç»ç§»æ¤
ããLinuxå æ ¸ä»£ç å¹³å°ç¸å ³ä»£ç åæ ARMå¹³å°ä»ç» å¹³å°ç§»æ¤çå ³é®ææ¯ ç§»æ¤Linuxå æ ¸å° ARMå¹³å° äºè§£ç§»æ¤çæ¦å¿µ
è½å¤ç§»æ¤Linuxå æ ¸ç§»æ¤Linux2.6å æ ¸å° ARM9å¼åæ¿
ãã6ãåµå ¥å¼ Linux ä¸ä¸²å£éä¿¡
ãã串è¡I/Oçåºæ¬æ¦å¿µ åµå ¥å¼Linuxåºç¨è½¯ä»¶å¼åæµç¨ Linuxç³»ç»çæ件åè®¾å¤ ä¸æ件ç¸å ³çç³»ç»è°ç¨ é ç½®è¶ çº§ç»ç«¯åMiniCOM
è½å¤çæè¿è¡ä¸²å£éä¿¡ çææ件I/O ç¼å串å£éä¿¡ç¨åº ç¼åå¤ä¸²å£éä¿¡ç¨åº
ãã7ãåµå ¥å¼ç³»ç»ä¸å¤è¿ç¨ç¨åºè®¾è®¡
ããLinuxç³»ç»è¿ç¨æ¦è¿° åµå ¥å¼ç³»ç»çè¿ç¨ç¹ç¹ è¿ç¨æä½ å®æ¤è¿ç¨ ç¸å ³çç³»ç»è°ç¨äºè§£Linuxç³»ç»ä¸è¿ç¨çæ¦å¿µ è½å¤ç¼åå¤è¿ç¨ç¨åºç¼åå¤è¿ç¨ç¨åº
ç¼åä¸ä¸ªå®æ¤è¿ç¨ç¨åº sleepç³»ç»è°ç¨ä»»å¡ç®¡çãåæ¥ä¸éä¿¡ Linuxä»»å¡æ¦è¿°ä»»å¡è°åº¦ 管é ä¿¡å· å ±äº«å å ä»»å¡ç®¡ç API äºè§£Linuxç³»ç»ä»»å¡ç®¡çæºå¶
çæè¿ç¨é´éä¿¡çå ç§æ¹å¼ çæåµå ¥å¼Linuxä¸çä»»å¡é´åæ¥ä¸éä¿¡ç¼åä¸ä¸ªç®åç管éç¨åºå®ç°æä»¶ä¼ è¾ ç¼åä¸ä¸ªä½¿ç¨å ±äº«å åçç¨åº
ãã8ãåµå ¥å¼ç³»ç»ä¸å¤çº¿ç¨ç¨åºè®¾è®¡
ãã线ç¨çåºç¡ç¥è¯ å¤çº¿ç¨ç¼ç¨æ¹æ³ 线ç¨åºç¨ä¸çåæ¥é®é¢äºè§£çº¿ç¨çæ¦å¿µ è½å¤ç¼åç®åçå¤çº¿ç¨ç¨åºç¼åä¸ä¸ªå¤çº¿ç¨ç¨åº
ãã9ãåµå ¥å¼ Linux ç½ç»ç¼ç¨
ããç½ç»åºç¡ç¥è¯ åµå ¥å¼Linuxä¸TCP/IPç½ç»ç»æ socket ç¼ç¨ å¸¸ç¨ APIå½æ° åæPingå½ä»¤çå®ç° åºæ¬UDPå¥æ¥å£ç¼ç¨ 许å¯è¯ç®¡ç
PPPåè®® GPRS äºè§£åµå ¥å¼Linuxç½ç»ä½ç³»ç»æ è½å¤è¿è¡åµå ¥å¼Linuxç¯å¢ä¸çsocket ç¼ç¨ çæUDPåè®®ãPPPåè®® çæGPRS
使ç¨socket ç¼å代çæå¡å¨ 使ç¨socket ç¼åè·¯ç±å¨ ç¼å许å¯è¯æå¡å¨ æåºTCPåUDPçä¼ç¼ºç¹ ç¼åä¸ä¸ªwebæå¡å¨ ç¼åä¸ä¸ªè¿è¡å¨
ARMå¹³å°çç½ç»ææ¾å¨
ãããGUI ç¨åºå¼å
ããGUIåºç¡ åµå ¥å¼ç³»ç»GUIç±»å ç¼è¯QT è¿è¡QTå¼åçæåµå ¥å¼ç³»ç»å¸¸ç¨çGUI è½å¤è¿è¡QTç¼ç¨ä½¿ç¨QTç¼åâHelloï¼Worldâç¨åº
è°è¯ä¸ä¸ªå å ¥ä¿¡å·/槽çå®ä¾ éè¿éè½½QWidget ç±»æ¹æ³å¤çäºä»¶
ãããLinux å符设å¤é©±å¨ç¨åº
ãã设å¤é©±å¨ç¨åºåºç¡ç¥è¯ Linuxç³»ç»ç模å å符设å¤é©±å¨åæ fs_operationç»æ å 载驱å¨ç¨åºäºè§£è®¾å¤é©±å¨ç¨åºçæ¦å¿µ
äºè§£Linuxå符设å¤é©±å¨ç¨åºç»æ è½å¤ç¼åå符设å¤é©±å¨ç¨åºç¼åSkullé©±å¨ ç¼åé®çé©±å¨ ç¼åI/Oé©±å¨ åæä¸ä¸ªçé¨ç驱å¨ç¨åº
对æ¯Linux2.6å æ ¸ä¸2.4å æ ¸ä¸å符设å¤é©±å¨çä¸åLinux å设å¤é©±å¨ç¨åºå设å¤é©±å¨ç¨åºå·¥ä½åç å ¸åçå设å¤é©±å¨ç¨åºåæ
å设å¤ç读å请æ±éåäºè§£Linuxå设å¤é©±å¨ç¨åºç»æ è½å¤ç¼åç®åçå设å¤é©±å¨ç¨åºæ¯è¾å符设å¤ä¸å设å¤çå¼å ç¼åMMCå¡é©±å¨ç¨åº åæä¸ä¸ªæ件系ç»
对æ¯Linux2.6å æ ¸ä¸2.4å æ ¸ä¸å设å¤é©±å¨çä¸å
ãããæ件系ç»
ããèææä»¶ç³»ç» æ件系ç»çå»ºç« ramfså åæä»¶ç³»ç» procæä»¶ç³»ç» devfs æä»¶ç³»ç» MTDææ¯ç®ä» MTDå设å¤åå§å
MTDå设å¤ç读åæä½äºè§£Linuxç³»ç»çæä»¶ç³»ç» äºè§£åµå ¥å¼Linuxçæä»¶ç³»ç» äºè§£MTDææ¯ è½å¤ç¼åç®åçæ件系ç»ä¸º ARM9å¼åæ¿æ·»å MTDæ¯æ
移æ¤JFFS2æä»¶ç³»ç» éè¿procæ件系ç»ä¿®æ¹æä½ç³»ç»åæ° åæromfs æ件系ç»æºä»£ç å建ä¸ä¸ªcramfs æ件系ç»
ããæ 论éæ©åªä¸æ¹åï¼åºæ¬çlinuxçç¥è¯æ¯éè¦å ·å¤çï¼å ¶ä»è¿éè¦ææ¡çç¥è¯æARM(æ常ç¨çä¸æ¬¾åµå ¥å¼å¤çå¨)åCè¯è¨ç¼ç¨ï¼æ¯ä¸æ¹é¢ç¥è¯çææ¡çç»ç¨åº¦é½æç»å³å®äºä¸ªäººè¿è¡åµå ¥å¼linuxå¼åç综åè½åã
æ´å¤è¯¦æ æ¥æºï¼ãåæ¸ è¿è§åµå ¥å¼å¦é¢ã