歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 基於MT7688模塊的開發筆記11——編寫我的第一個程序並在MT7688中運行

基於MT7688模塊的開發筆記11——編寫我的第一個程序並在MT7688中運行

日期:2017/3/3 12:56:59   编辑:Linux技術

之前一直在學MT7688,發現要想真正利用這個開發板並在上面做出一些東西確實不容易。我花了很長的時間去學習Linux中的知識,包括怎樣在Ubuntu中搭建samba、tftp、vim、makefile、shell,以及燒寫程序等方法,常見錯誤的排除。我不得不說,自己缺的東西太多了。後來終於利用這些東西實現了開發板、Ubuntu、MT7688三者之間的文件訪問,但是卻還遲遲不知道怎樣編寫自己的程序並在開發板上運行。經過1天多的學習終於可以寫一個簡單的程序了。我是初學者也是菜鳥一枚,希望我的文章可以幫助初學者,請大神勿噴自行繞過。同時,我是想在MT7688上面做應用開發,也希望朋友們就基於MT7688開發板的用戶應用程序設計不吝賜教,吾不勝感激!!!

我用的是原廠的SDK:MediaTek_ApSoC_SDK_4300_20140916.tar

我在/MT7688/RT288x_SDK/source/user中建立了music文件夾,並將我的用戶程序寫到這個文件夾下。我的第一個程序很簡單,編寫music.c文件,運行這個文件時 ,輸出:Welcome to use wireless music service!

一、進入MT7688/RT288x_SDK/source/user/目錄,創建一個文件夾music

root@openwrt:~# cd ~/MT7688/RT288x_SDK/source/user/

root@openwrt:~/MT7688/RT288x_SDK/source/user# pwd

/root/MT7688/RT288x_SDK/source/user

root@openwrt:~/MT7688/RT288x_SDK/source/user# mkdir music

root@openwrt:~/MT7688/RT288x_SDK/source/user# cd music

root@openwrt:~/MT7688/RT288x_SDK/source/user/test# pwd

/root/MT7688/RT288x_SDK/source/user/music

二、編寫用戶程序

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# pwd

/root/MT7688/RT288x_SDK/source/user/music

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# touch music.c

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# vim music.c

程序內容如下:

#include<stdio.h>

int main()

{

printf("Welcome to use wireless music service!\n");

return 0;

}

三、/root/MT7688/RT288x_SDK/source/user/music中添加Makefile文件

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# ls

music.c

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# touch Makefile

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# ls

Makefile music.c

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# vim Makefile

編寫如下內容:

EXE = music

OBJS = music.o

#stdlibc++ known issue:

#If your program needs libstdc++, please turn off code optimization

CFLAGS += -O0

all: $(OBJS)

$(CXX) -o $(EXE) $(OBJS) $(LDFLAGS)

.cpp.o:

$(CXX) $(CFLAGS) -c $<

romfs:

$(ROMFSINST) /bin/$(EXE)

clean:

@rm -rf $(EXE) *.o

四、編輯RT288x_SDK/source/config/config.in文件

root@openwrt:~/MT7688/RT288x_SDK/source/user/music# vim ../../config/config.in

添加如下內容:

comment 'XXX Add-on Applications'

bool 'music_server' CONFIG_USER_MUSIC

五、編輯RT288x_SDK/source/user/中的Makefile文件

root@openwrt:~/MT7688/RT288x_SDK/source/user# pwd

/root/MT7688/RT288x_SDK/source/user

root@openwrt:~/MT7688/RT288x_SDK/source/user# vim Makefile

添加如下內容:

dir_$(CONFIG_USER_MUSIC) += music

六、/root/MT7688/RT288x_SDK/source中運行make menuconfig

root@openwrt:~/MT7688/RT288x_SDK/source/user# pwd

/root/MT7688/RT288x_SDK/source/user

root@openwrt:~/MT7688/RT288x_SDK/source/user# cd ..

root@openwrt:~/MT7688/RT288x_SDK/source# pwd

/root/MT7688/RT288x_SDK/source

root@openwrt:~/MT7688/RT288x_SDK/source# make menuconfig

在執行的過程中會出現一個選項:這就是剛剛添加的程序,選擇y

* Force build (Normally built when required)

*

music_server (CONFIG_USER_MUSIC) [N/y/?] (NEW) y

七、編譯新的鏡像文件

root@openwrt:~/MT7688/RT288x_SDK/source# make dep

root@openwrt:~/MT7688/RT288x_SDK/source# make

八、編譯完成後

Image Name: Linux Kernel Image

Created: Wed May 11 00:53:33 2016

Image Type: MIPS Linux Kernel Image (lzma compressed)

Data Size: 4009600 Bytes = 3915.62 kB = 3.82 MB

Load Address: 0x80000000

Entry Point: 0x8000C150

Kernel Size: 0x00000000

make[2]: Leaving directory `/root/MT7688/RT288x_SDK/source/vendors/Ralink/MT7628'

make[1]: Leaving directory `/root/MT7688/RT288x_SDK/source/vendors'

if [ -d /tftpboot ]; then \

cp /root/MT7688/RT288x_SDK/source/images/root_uImage /tftpboot; \

fi

九、測試music文件是否正確

root@openwrt:~/MT7688/RT288x_SDK/source# pwd

/root/MT7688/RT288x_SDK/source

root@openwrt:~/MT7688/RT288x_SDK/source# cd romfs/bin/

root@openwrt:~/MT7688/RT288x_SDK/source/romfs/bin# file music

music: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, stripped

root@openwrt:~/MT7688/RT288x_SDK/source/romfs/bin#

十、把鏡像燒寫到MT7688,方法跟燒寫Uboot類似,但是操作的時候選擇方式2

##### The CPU freq = 575 MHZ ####

estimate memory size =64 Mbytes

RESET MT7628 PHY!!!!!!

Please choose the operation:

1: Load system code to SDRAM via TFTP.

2: Load system code then write to Flash via TFTP.

3: Boot system code via Flash (default).

4: Entr boot command line interface.

7: Load Boot Loader code then write to Flash via Serial.

9: Load Boot Loader code then write to Flash via TFTP.

You choosed 2

0

2: System Load Linux Kernel then write to Flash via TFTP.

Warning!! Erase Linux in Flash then burn new one. Are you sure?(Y/N)

Please Input new ones /or Ctrl-C to discard

Input device IP (10.10.10.123) ==:192.168.1.1

Input server IP (10.10.10.3) ==:192.168.1.32

Input Linux Kernel filename () ==:root_uImage

netboot_common, argc= 3

NetTxPacket = 0x83FE4E00

KSEG1ADDR(NetTxPacket) = 0xA3FE4E00

NetLoop,call eth_halt !

NetLoop,call eth_init !

Trying Eth0 (10/100-M)

Waitting for RX_DMA_BUSY status Start... done

ETH_STATE_ACTIVE!!

TFTP from server 192.168.1.32; our IP address is 192.168.1.1

Filename 'root_uImage'.

TIMEOUT_COUNT=10,Load address: 0x80100000

Loading: checksum bad

Got ARP REQUEST, return our IP

checksum bad

checksum bad

checksum bad

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

checksum bad

checksum bad

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

checksum bad

checksum bad

Got ARP REQUEST, return our IP

checksum bad

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REQUEST, return our IP

Got ARP REPLY, set server/gtwy eth addr (b8:88:e3:7a:66:3a)

Got it

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################################################

####

done

Bytes transferred = 4009664 (3d2ec0 hex)

NetBootFileXferSize= 003d2ec0

.............................................................

.............................................................

.

.

Done!

十一、在開發板中就可以使用自己編寫的程序了

# help

Built-in commands:

-------------------

. : break cd chdir continue eval exec exit export false hash

help local pwd read readonly return set shift source times trap

true type ulimit umask unset wait

# music

Welcome to using wireless music service!

#

Copyright © Linux教程網 All Rights Reserved