AM335x學(xué)習(xí)記錄.doc_第1頁
AM335x學(xué)習(xí)記錄.doc_第2頁
AM335x學(xué)習(xí)記錄.doc_第3頁
AM335x學(xué)習(xí)記錄.doc_第4頁
AM335x學(xué)習(xí)記錄.doc_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

AM335x 學(xué)習(xí)筆記1 硬件及其開發(fā)環(huán)境篇1.1 開發(fā)環(huán)境的搭建1.1.1 路由器方式的NFS啟動1) 通過路由器的方式來啟動NFS文件系統(tǒng)設(shè)置路由器局域網(wǎng)的網(wǎng)關(guān):,然后將開發(fā)板和PC都連接在路由器的LAN端口,并且采用DCHP的方式來實現(xiàn)tftp和nfs。2) uEnv.txtserverip=7rootpath=/opt/ti-sdk-am335x-evm/targetNFSbootfile=uImage-am335x-evm.binip_method=dhcptftp_nfs_boot=echo Booting from network.; dhcp $loadaddr $bootfile; run net_args; bootm $loadaddruenvcmd=run tftp_nfs_boot1.1.2 Root用戶登陸#sudo passwd root#*#*#sudo s H 切換到root用戶然后就可以重啟虛擬機(jī),以用戶root來登陸1.1.3 中文字庫問題#locale a 查看是否有zh_CN,zh_CN.gb18030,zh_CN.gb2312等#vim /var/lib/locales/supported.d/local#dpkg-reconfigure locales#locale-gen zh_CN.GB18030#locale-gen zh_CN.GB2312#locale-gen zh_CN.GBK1.1.4 環(huán)境變量設(shè)置路徑#vim /etc/envinoment常用的3個永久設(shè)置路徑l #vim /etc/envirnomentl #vim /etc/profilel #vim /.bashrc (/root/.bashrc)1.1.5 設(shè)置ubuntu的上網(wǎng)ip設(shè)置為 bridge連接方式,設(shè)定靜態(tài)IP地址.1.1.6 更改sh工具#rm /bin/sh# ln s /bin/bash /bin/sh#apt-get install fakeroot1.1.7 安裝必須的工具#apt-get install vim#apt-get install build-essential#apt-get install libtool#apt-get install bsion(干什么用的還不清楚)GNU autotools主要包括三個工具 autoconf,automake,libtool1.1.8 虛擬機(jī)開發(fā)工具的安裝$ sudo apt-get install build-essential libncurses-dev flex bison autoconf automake libmpfr-dev texinfo nfs-kernel-server tftpd-hpa libcloog-ppl1.2 AM335x BeagleBone 的NFS啟動Sd卡的識別:在/media/下面顯示內(nèi)容在/dev/sd* 下顯示分區(qū)卸載:#unmount /dev/sdb1 這個是在AM335X-LINUX-PSP-04.06.00.03里面找的1) 制作sd啟動盤 MLO+uboot.img+uImage+rootfs#!/bin/bashif -z $1 | -z $2 | -z $3 | -z $4 thenecho mksd-am335x Usage:echo mksd-am335x echo Example: mksd-am335x /dev/sdc MLO u-boot.img uImage nfs.tar.gzexitfiif ! -e $2 thenecho Incorrect MLO location!exitfiif ! -e $3 thenecho Incorrect u-boot.img location!exitfiif ! -e $4 thenecho Incorrect uImage location!exitfiif ! -e $5 thenecho Incorrect rootfs location!exitfiecho All data on $1 now will be destroyed! Continue? y/nread ansif ! $ans = y thenexitfiecho Partitioning $1.DRIVE=$1dd if=/dev/zero of=$DRIVE bs=1024 count=1024SIZE=fdisk -l $DRIVE | grep Disk | awk print $5 echo DISK SIZE - $SIZE bytesCYLINDERS=echo $SIZE/255/63/512 | bcecho CYLINDERS - $CYLINDERSecho ,9,0x0C,*echo ,- | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVEecho Making filesystems.mkfs.vfat -F 32 -n boot $11 & /dev/nullmkfs.ext3 -L rootfs $12 & /dev/nullecho Copying files.mount $11 /mntcp $2 /mnt/MLOcp $3 /mnt/u-boot.imgcp $4 /mnt/uImageumount $11mount $12 /mnttar zxvf $5 -C /mnt & /dev/nullchmod 755 /mntumount $12echo Done2) 建立uEnv.txt(我是將tf卡放入讀卡器,在虛擬機(jī)下面vim編寫的。應(yīng)該在xp上用讀卡器讀出來,用文本文件編寫uEnv.txt也可以的)bootargs=console=ttyo0,115200n8 root=/dev/nfs (ttyo0 小寫的o,不是數(shù)字0)nfsroot=7:/opt/ti-sdk-am335x-evm/targetNFS rw noinitrd ip=00:7::ipaddr=00serverip=7netmask=ethaddr=00:08:ee:05:4d:7eautoload=nobootdelay=3bootcmd=tftp 0x81000000 uImage-am335x;bootm如果只是這樣,在將制作好的tf卡插入beaglebone,還是會默認(rèn)從mmc啟動U-Boot# mmc rescan U-Boot# fatload mmc 0 0x81000000 uEnv.txt U-Boot# env import -t 0x81000000 $filesize U-Boot# boot有時候會出現(xiàn)“bootm 問題” :解決方法:boot 8100000000 (不要0x也可以,要也可以)這樣就可以從nfs掛載啟動注意:在啟動linux后,會停止,等一會后就可以進(jìn)入文件系統(tǒng)。 serverip=7rootpath=/opt/ti-sdk-am335x-evm/targetNFSbootfile=uImage-am335x-evm.binip_method=dhcpnet_args=setenv bootargs console=ttyO0,115200n8 root=/dev/nfs nfsroot=$serverip:$rootpath,$nfsopts rw noinitrd ip=$ip_methodtftp_nfs_boot=echo Booting from network.; dhcp $loadaddr $bootfile; run net_args; bootm $loadaddruenvcmd=run tftp_nfs_boot1.3 常見問題1) win7 64位安裝問題(不能正常的啟動gui)修改文件/etc/init/rc-sysinit.confenv DEFAULT_RUNLEVEL=52) VIM 在啟動vim時,當(dāng)前用戶根目錄下的.vimrc文件會被自動讀取,該文件可以包含一些設(shè)置甚至腳本,所以,一般情況下把.vimrc文件創(chuàng)建在當(dāng)前用戶的根目錄下比較方便,即創(chuàng)建的命令為:$vi /.vimrcSet number 保存退出3)Ubuntu 循環(huán)登陸問題原因:我自己在/etc/environment 里面不正確修改了PATH,導(dǎo)致這種情況的出現(xiàn),2次了。解決辦法:用ctrl+F1+Alt進(jìn)入終端(注意,不要ctrl+Alt+F1,因為虛擬機(jī)會捕捉到ctrl+alt,導(dǎo)致后面的ctrl+Alt+F1無效。進(jìn)入終端后連ls,都提示找不到路徑,說明PATH有問題,可以用echo $PATH查看。修改:export PATH = /bin:/sbin:/usr/bin:/usr/sbin,這樣就可以用ls,vi等命令了。就用vim編輯錯誤的PATH路徑,然后重啟就ok。2 AM335x外設(shè)2.1 AM335x LCD驅(qū)動控制LCD分為2個部分:1. 激光LCD控制器,同步的(Hclk,Vclk,R,G,B,等)2. LIDD控制器,異步的(CS,WE,OE,ALE,DATA)1)AM335x的LCDC控制器是OMAPL138的升級版本不同之處:l 中斷配置和狀態(tài)寄存器的不同l 升級到2048*2048的分辨率l 24位的數(shù)據(jù)寬度AM335x的LCDCLCDC有2個時鐘源L3外設(shè)時鐘和L4LS3 uboot相關(guān)3.1 bootloader分為3級boot stage,其中第1級為內(nèi)部ROM,第2,3級都是基于uboot的。第1級 :AM335x 內(nèi)部的ROM第2級 :標(biāo)記為 SPL,它是不可以交互的【non-interactive】,一個特別的uboot版本第3級 :標(biāo)記為simply U-Boot.ROM 可以從下面的設(shè)備中讀取 SPL imagenon-XIP(SD/MMC,NAND)image有一個header. 8個字節(jié)(入口點和image的長度)外設(shè)(uart)ROM 通過uart讀取image到內(nèi)部的0x402f0400,并且執(zhí)行。不需要image的headerUboot二級設(shè)計原理AM335x內(nèi)部RAM大小為128K,其中底部的18K用作ROM,1 KB at the start (0x402f0000 - 0x402f0400) is secure,不可以被訪問。剩下就109K,可以用來放uboot映像和用作stack。你不可能期望所有的uboot都小于110K(這還不包括stack,heap所用的空間);所以采用2級boot stage. 初級只是完成必要的設(shè)備初始化(如,Nand,MMC,I2C等),第2級就完成剩下的初始化部分(如,時鐘,以太網(wǎng),定時器等等)3.2 Uboot 配置和編譯$ make O=am335x CROSS_COMPILE=arm-arago-linux-gnueabi- ARCH=arm am335x_evmO=am335x 作為目錄重新配置之前要刪除$ rm -rf ./am335x生成2個文件:MLO和u-boot.bin串口的配置l Baud rate: 115,200l Data bits: 8l Parity: Nonel Stop bits: 1l Flow control: Nonel Transmit delay: 0 msec/char, 100 msec/line通過CCS燒寫uboot你可以燒寫SPL&uboot到nand設(shè)備上面,然后配置成nand啟動。使用PSP提供的nand flash writer不通過CCS燒寫ubootl Both the stages of U-Boot need to be flashed on the same media.l MLO is the binary for SPL and u-boot.img is the binary for U-Boot Uart flash模式配置成uart啟動模式通過uart加載uboot燒寫SPL bootloader燒寫uboot bootloader燒寫完成后,設(shè)置成合適的啟動模式 SD flash 模式.啟動模式Nand模式啟動:Micron Nand parts (page size 2KB, block size 128KB) are supported on AM335XEVM platforms.NAND 布局+-+-0x00000000- SPL start (SPL copy on 1st block)| | |-0x0001FFFF- SPL end | |-0x00020000- SPL.backup1 start (SPL copy on 2nd block)| | |-0x0003FFFF- SPL.backup1 end | |-0x00040000- SPL.backup2 start (SPL copy on 3rd block)| | |-0x0005FFFF- SPL.backup2 end | |-0x00060000- SPL.backup3 start (SPL copy on 4th block)| | |-0x0007FFFF- SPL.backup3 end| |-0x00080000- U-Boot start| | | |-0x002BFFFF- U-Boot end | |-0x00260000- ENV start| | | |-0x0027FFFF- ENV end| |-0x00280000- Linux Kernel start| | | | | |-0x0077FFFF- Linux Kernel end| |-0x00780000- File system start| | | | | | | | | | | | |+-+-0x10000000- NAND end (Free end)Writing to NandU-Boot# nand write 【需要和0x800 (2048) bytes對齊】【Note】:Offset &len fields should be in align with 0x800 (2048) bytes. On writing 3000 (0xbb8) bytes, len field can be aligned to 0x1000 ie 4096 bytes. Offset field should be aligned to page start address, multiple of 2048 bytes.If a bad block is encountered during the write operation, it is skipped and the write operation continues from next good block.For example, to write 0x40000 bytes from memory buffer at address 0x80000000 to NAND - starting at block 32 (offset 0x400000):U-Boot# nand write 0x80000000 0x400000 0x40000Reading from NandTo read len bytes of data from NAND block at a particular offset to the memory buffer in DDR located at addr:U-Boot# nand read If a bad block is encountered during the read operation, it is skipped and the read operation continues from next good block.For example, to read 0x40000 bytes from NAND - starting at block 32 (offset 0x400000) to memory buffer at address 0x80000000:U-Boot# nand read 0x80000000 0x400000 0x40000Marking a bad blockSome of the blocks in the NAND may get corrupted over a period of time. In such cases you should explicitly mark such blocks as bad so that the image that you are writing to NAND does not end up getting corrupted.To forcefully mark a block as bad:U-Boot# nand markbad For example, to mark block 32 (assuming erase block size of 128Kbytes) as bad block - offset = blocknum * 128 * 1024:U-Boot# nand markbad 0x400000Viewing bad blocksTo view the list of bad blocks:U-Boot# nand badNote The user marked bad blocks can be viewed by using this command only after a reset.Erasing NandTo erase NAND blocks in a particular the address range or using block numbers:U-Boot# nand erase Note start offset addr & len fields should should align to 0x20000 (64*2048) bytes, i.e. block size 128KB.This commands skips bad blocks (both factory and user marked) encountered within the specified range.For example, to erase blocks 32 through 34:U-Boot# nand erase 0x00400000 0x40000NAND ECC algorithm selectionNAND flash memory, although cheap, suffers from problems like bit flipping which lead to data corruption. However by making use of some error correction coding (ECC) techniques it is possible to work around this problem.For the data stored in NAND flash, U-Boot supports following NAND ECC schemes1. S/W ECC (Hamming code)2. H/W ECC (Hamming code, BCH4, BCH8)Current releases do not support BCH4.BCH Flash OOB LayoutFor any ECC scheme we need to add some extra data while writing so as to detect and correct (if possible) the errors introduced by the NAND part. In case of BCH scheme some bytes are needed to store the ECC related info.The section of NAND memory where addition info like ECC data is stored is referred to as Out Of Band or OOB section.The first 2 bytes are used for Bad block marker 0xFFFF = Good blockThe next N bytes is used for BCH bytesN = B * 1. B = 8 bytes per 512 byte sector in BCH42. B = 14 bytes per 512 byte sector in BCH83. B = 26 bytes per 512 byte sector in BCH16So for a 2k page-size NAND flash with 64-byte OOB size, we will use BCH8. This will consume 2 + (14*4) = 58 bytes out of 64 bytes available.The NAND flash part used in EVM does not have enough spare area to support BCH16.ECC Schemes and their context of usageECC typeUsageS/W ECCNot usedH/W ECC - Hamming CodeShould use this scheme only for flashing the U-Boot ENV variables.H/W ECC BCH8Should use this scheme while flashing any image/binary other than the U-Boot ENV variables.To select ECC algorithm for NAND:U-Boot# nandecc sw | hw Usage:sw - Set software ECC for NAND hw - Set hardware ECC for NAND - 0 for Hamming code 1 for bch4 2 for bch8 3 for bch16 Currently we support only Software, Hamming Code and BCH8. We do not support BCH4 and BCH16ECC schemes usage tableECC schemes usage tableComponentDefault ECC scheme used by the componentECC scheme to be used to flash the componentECC schemes supported by the componentSPLBCH8BCH8BCH8U-bootHammingBCH8Hamming/BCH8LinuxBCH8BCH8BCH8File SystemNABCH8NAEnvironment variablesNAHammingNAFlashing Linux Kernel from U-BootTFTP the kernel uImage to DDR.U-Boot# mw.b 0x82000000 0xff 0x500000 U-Boot# tftp 0x82000000 Now flash the kernel image to NAND at the appropriate offset (refer toNAND layoutsection for the offsets)U-Boot# nandecc hw 2U-Boot# nand erase 0x00280000 0x00500000U-Boot# nand write 0x82000000 0x00280000 0x500000Note Image_size should be aligned to page size of 2048 (0x800) bytesUBIFS file system flashingIn AM335X, UBIFS file system is used in NAND flash as it is next generation flash file system.1. creating of UBIFS file system image is described overhere2. Follow the steps mentioned below to Flash UBIFS imageNote: In case of AM335x, file system partition is starting from 0x780000. So from U-Boot, flashing offset for file system from U-Boot is 0x780000 and from Linux MTD partition number 7 should used for flashing file file system.UBIFS file system flashing from U-BootGet the UBIFS image to U-Boot from tftp or MMC/SD or UART. Lets consider an example of MMC card.Since we copy the data to NAND, Empty/Erase the required RAM. Then, get the UBIFS image to U-BootLoad the memory with 0xFF u-boot# mw.b 0x82000000 0xFF filesystem image sizeis upward aligned to NAND page size.Load the UBIFS file system image, in the example below from MMC as u-boot# mmc rescan u-boot# fatload mmc 0 0x82000000 ubi.imgErase the NAND. Switch to BCH8 ECC and the flash the image assuming NAND partition to be erased starts from 0x780000 and is of size 0xF880000. File system size to be flashed is 0xFC0000 which is upward aligned to NAND block size. u-boot# nand erase 0x00780000 0xF880000 u-boot# nandecc hw 2 u-boot# nand write 0x82000000 0x780000 0xFC0000UBIFS file system flashing from Linux Flash the UBI file system image (ubi.img) to MTD partition Xubiformat /dev/mtd -f ubi.img -s 512 -O 2048Assuming7th mtd partition, we can use the following command to flash the ubifs image to partition 7.#ubiformat /dev/mtd7 -f ubi.img -s 512 -O 20484 linux相關(guān)4.1 linux小技巧#cat /proc/meminof 查看memory map#free 查看剩余的內(nèi)存#cat /proc/iomem 可以查看IO(或者說外設(shè)的)物理地址范圍Linux啟動的最后的一步就是調(diào)用用戶空間的init進(jìn)程Ubuntu 開發(fā)環(huán)境搭建4.2 linux下的gpio編程Beaglebone GPIO 學(xué)習(xí)通過GPIO點亮LED需要三個步驟:1.選定具體GPIO口;2.設(shè)置GPIO口的工作模式;3.編寫控制程序。2.設(shè)置GPIO口的工作模式BeagleBone的引腳工作模式設(shè)置比較方便,在/sys/kernel/debug/omap_mux文件下有每個引腳的模式設(shè)定文件。在終端輸入:# ls /sys/kernel/debug/omap_mux就可以查看到。擴(kuò)展插排P8的Pin3對應(yīng)GPIO1_6,由下表可知對應(yīng)設(shè)置文件為gpmc_ad6。同理,GPIO1_7對應(yīng)的文件為gpmc_ad7,TIMER4對應(yīng)的文件為gprnc_advn_ale。3. 編寫控制程序GPIO的配置文件在/sys/class/gpio目錄下,控制程序可以分為四個步驟:配置GPIO:在/sys/class/gpio目錄下可以看到文件export,調(diào)用該文件以實現(xiàn)配置。該文件對所有GPIO編號,從0開始。GPIOn_x的編號為32*n+x,例如此處用的GPIO1_6的編號為32*1+6=38。在終端輸入:# echo 38 /sys/class/gpio/export,在此回到目錄/sys/class/gpio下,可以看到產(chǎn)生了一個新的目錄./gpio38,里面包含了該IO口的輸入輸出設(shè)置等配置文件。注意:export文件只有root寫權(quán)限,執(zhí)行上述命令或者以后用C編寫的可執(zhí)行文件要以ROOT身份執(zhí)行。設(shè)置GPIO的方向(輸入輸出)輸入:# echo out /sys/class/gpio/gpio38/direction,即設(shè)置該GPIO為輸出。設(shè)置GPIO的輸出電平:在終端輸入:#echo 1 /sys/class/gpio/gpio38/value,即設(shè)置GPIO輸出高電平輸入echo 0 /sys/class/gpio/gpio38/value設(shè)置GPIO輸出低電平。關(guān)閉GPIO輸入:#echo 38 /sys/class/gpio/unexport,即刪除GPIO配置文件,可以看到目錄gpio38已經(jīng)被刪除。下面是C語言編寫的GPIO控制例程,實現(xiàn)LED的每隔一秒閃爍一次。#include #include #include #include int main(void)FILE *p=NULL;int i=0;p = fopen(/sys/class/gpio/export,w);fprintf(p,%d,38);fclose(p);p = fopen(/sys/class/gpio/gpio38/direction,w);fprintf(p,out);fclose(p);for(i=0;i100;i+)p = fopen(/sys/class/gpio/gpio38/value,w);fprintf(p,%d,1);sleep(1);fclose(p);p = fopen(/sys/class/gpio/gpio38/value,w);fprintf(p,%d,0);sleep(1);fclose(p);p = fopen(/sys/class/gpio/unexport,w);fprintf(p,%d,38);fclose(p);return 0;Linux下面操作IO#define TIA8_GPIO1_PA (0x4804C000)#define TIA8_GPIO_CLEARDATAOUT (0x190)#define TIA8_GPIO_SETDATAOUT (0x194)#define TIA8_GPIO_CTRL (0x130)#define TIA8_GPIO_OE (0x134)#define LED1( 1 21)#define LED2( 1 22)#define LED3( 1 23)#define LED4( 1 24)void _iomem *base = ioremap【_nocache】(TIA8_GPIO1_PA,0x2048);_raw_writel(LED1,(base+TIA8_GPIO_SETDATAOUT);_raw_writel(LED2,(TIA8_GPIO_SETDATAOUT+base);_raw_writel(LED3,(TIA8_GPIO_CLEARDATAOUT+base);_raw_writel(LED4,(TIA8_GPIO_CLEARDATAOUT+base);運行成功的例子:#include #include #include #include #include #include #include #include #include MODULE_LICENSE(GPL);static DECLARE_COMPLETION(work);static int status;static int gpio_num = 53;/32*n+gpio GPIO1_21 = 32*1+21 = 53;static int _init gpio_init(void)printk(KERN_INFO gpio init.n);status = gpio_request(gpio_num,beaglebone-led);if(status 0) printk(ERROR cant request gpio%d.n,gpio_num);return status;gpio_direction_output(gpio_num,1);gpio_set_value(gpio_num,1);return 0;static void _exit gpio_exit(void)printk(KERN_INFO gpio exit.n);gpio_set_value(gpio_num,0);gpio_free(gpio_num);module_init(gpio_init);module_exit(gpio_exit);4.3 AM335x-MUX配置(1)重要的數(shù)據(jù)結(jié)構(gòu)/*struct mux_partition-包含分區(qū)相關(guān)信息*name:當(dāng)前分區(qū)名*flags:本分區(qū)的特定標(biāo)志*phys:物理地址*size:分區(qū)大小*base:ioremap 映射過的虛擬地址*muxmodes:本分區(qū)mux節(jié)點鏈表頭*node:分區(qū)鏈表頭*/struct omap_mux_partitionconstchar*name;u32flags;u32phys;u32size;void _iomem*base;struct list_headmuxmodes;struct list_headnode; 這個數(shù)據(jù)結(jié)構(gòu)中包含了芯片中幾乎所有定義好的mux的數(shù)據(jù),它在mux數(shù)據(jù)初始化函數(shù)omap_mux_init中初始化,并添加到全局mux_partitions鏈表中(通過node成員)。而其中的muxmodes是所有mux信息節(jié)點的鏈表頭,用來鏈接以下數(shù)據(jù)結(jié)構(gòu):/*struct omap_mux_entry-mux信息節(jié)點*mux:omap_mux結(jié)構(gòu)體*node:鏈表節(jié)點*/struct omap_mux_entrystruct omap_muxmux;struct list_headnode;而在以上數(shù)據(jù)結(jié)構(gòu)中,struct omap_mux是記錄單個mu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論