嵌入式Linux固件升級

嵌入式Linux固件升級

開發需求

• 基於TCP/IP完成驅動模塊和應用程序的更新、升級

特殊聲明

該文檔中驅動程序和應用程序統稱爲“固件”。

 

•   機:VMWare--Fedora 9

• 開發板:yc2440--64MB NandflashKernel:2.6.24.4

• 編譯器:arm-linux-gcc-4.0.0

 

設計原理圖

 

 

說明:

•  開發板啓動FileServer應用程序,作爲TCP/IPServer端,提供接收升級文件的服務。

• 當需要進行固件升級時,PC啓動FileClient應用程序,作爲TCP/IPClient端,提供發送升級文件的服務。

• Shell腳本文件StartShell判斷是否有固件需要升級,如果有更新現有固件後,啓動更新後的固件,如果沒有,啓動現有固件。

 

文件名稱

所在目錄

功能

FileClient

Linux PC下任意目錄

PCTCP/IP客戶端,

向開發板發送升級固件。

FileServer

Linux開發板

/tmp/update/

開發板TCP/IP服務端,

接收客戶端發送的升級固件。

StartShell

Linux開發板

/etc/init.d/

替換相應固件,

啓動相應固件。

 

實現步驟

1.      配置啓動文件(開發板:192.168.1.168

在開發板中,編輯開機啓動腳本/etc/init.d/rcS

#cp ~/StartShell /etc/init.d/

#vi /etc/init.d/rcS

 

在該文件的最後面,填寫下面信息:

./StartShell

 

重新啓動開發板。

 

2.      發送更新文件文件(Linux PC192.168.1.200

#./fileclient ./AppMain 192.168.1.168

#./fileclient ./helloworld.ko 192.168.1.168

 

上述更新文件,被髮送至開發板的/tmp/update/FileServer所在的目錄)目錄中。

 

重新啓動開發板,文件升級完成。

 

注:如果要動態加載驅動模塊,首先必須在開發板上創建/lib/modules/2.6.24.4目錄。

附件:

•  TCP/IP源碼文件

http://download.csdn.net/source/2996852

 

注:TCP/IP 服務儘量使用大端口號,如:50000,否則服務器端會有Bind失敗的情況出現。

服務器端如果有防火牆,需要開放該端口號,否則客戶端會有connect失敗的情況出現。

 

• StartShell腳本

 

#! /bin/sh

 

#判斷是否有新的驅動文件,如果有進行替換

if [ -f /tmp/update/helloworld.ko ]

then

        echo "it is a new ko file"

 

        rm /lib/modules/helloworld.ko -f

        cp /tmp/update/helloworld.ko /lib/modules/

        rm /tmp/update/helloworld.ko -f

 

else

        echo "it is not a new ko file"

fi

 

insmod helloworld

#判斷是否有新的應用程序文件,如果有進行替換

if [ -f /tmp/update/AppMain ]

then

        echo "it is a new app file"

 

        rm /root/application/AppMain -f

        cp /tmp/update/AppMain /root/application/

        chmod 777 /tmp/update/AppMain

        rm /tmp/update/AppMain -f

              

else

        echo "it is not a new app file"

fi

 

#啓動應用程序

cd /root/application/

./AppMain &

 

#啓動TCP/IP服務程序

cd /tmp/update/

./FileServer &

 

 

 

Embedded Linux firmware upgrade
Development requirement
• Based on TCP/IP to complete the driver modules and application updates, upgrades
Special Statement
Drivers program and application program in this document are collectively called the "firmware".

• Main machine: VMWare-Fedora 9
• Development Board: yc2440-64MB Nandflash; Kernel: 2.6.24.4
• Compiler: arm-linux-gcc-4.0.0

Design schematic
 

Description:
• Start FileServer application on development board, as the TCP/IP server, providing service to receive the upgrade file.
• When you need a firmware upgrade, PC starts FileClient application, as the TCP/IP client, providing service to send the upgrade file.
• Shell script file StartShell determine whether there is the firmware need to upgrade, if it is existed, launch the updated firmware, if not, start the existing firmware.

File

directory

function

FileClient

any directory in linux PC

PC TCP/IP client,
Send upgrade firmware to  development board.

FileServer

/tmp/update/ in

linux development board

Development board TCP/IP server,

receive the upgrade firmware from client.

StartShell

/etc/init.d/ in

linux development board

Replace firmware,

Start frimware.


Implementation steps
1. Configuration startup files (development board: 192.168.1.168)
In the development board, edit the boot script file /etc/init.d/rcS, input the following information:
# cp ~ /StartShell /etc/init.d/
# vi /etc/init.d/rcS

Finally, in the end of the document, input the following information:

 

./StartShell

Restart the development board.

2. Send the update file file (Linux PC: 192.168.1.200)
#./Fileclient ./AppMain 192.168.1.168
#./Fileclient ./Helloworld.ko 192.168.1.168

The update file is sent to the development board of the /tmp/update/(FileServer  directory) directory.

Restart the development board, file upgrade is OK.

Note: If you want to dynamically load the driver module, first the directory /lib/modules/2.6.24.4 must be created in development board.


Attachment:
• TCP/IP source code file
http://download.csdn.net/source/2996852

Note: TCP/IP service port to make use of large numbers, such as: 50000, otherwise there will be bind server failure situation.
If the server has a firewall, you need to open up the port number, otherwise the client will connect failure situation.

• StartShell script

#! /bin/sh

# Determine whether there is a new driver file, if there is to be replaced
if [ -f /tmp/update/helloworld.ko ]
then
        echo "it is a new ko file"

        rm /lib/modules/helloworld.ko -f
        cp /tmp/update/helloworld.ko /lib/modules/
        rm /tmp/update/helloworld.ko -f
else
        echo "it is not a new ko file"
fi

insmod helloworld
# Determine whether there is a new application file, if there is to be replaced
if [ -f /tmp/update/AppMain ]
then
        echo "it is a new app file"

        rm /root/application/AppMain -f
        cp /tmp/update/AppMain /root/application/ 
        
chmod 777 /tmp/update/AppMain
        rm /tmp/update/AppMain -f
else
        echo "it is not a new app file"
fi

# Start the application program
cd /root/application/
./AppMain &

# Start TCP/IP service program
cd /tmp/update/
./FileServer &

 

發佈了25 篇原創文章 · 獲贊 26 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章