嵌入式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.youkuaiyun.com/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.youkuaiyun.com/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 &

 

### 嵌入式 Linux 通过 USB 实现固件更新的方法 在嵌入式 Linux 环境下,可以通过 USB 接口实现系统或固件升级。以下是具体方法和技术细节: #### 方法一:利用 Linux USB 设备驱动程序接口 Linux 提供了一套完整的 USB 驱动框架,可以用来编写自定义的设备驱动程序以支持固件升级功能。开发者需要注册一个 USB 设备驱动并处理数据传输逻辑[^1]。 - **步骤说明** 开发者可以在主机端(PC)设计一个应用程序作为客户端,该应用负责发送固件文件到目标板。而在目标板侧,则需开发对应的 USB 大容量存储类或其他类型的驱动程序来接收这些数据。 - **代码示例** 下面是一个简单的 USB 数据读取函数模板: ```c static int usb_firmware_read(struct urb *urb) { struct device *dev = &urb->dev; char buffer[BUF_SIZE]; memset(buffer, 0, BUF_SIZE); if (usb_bulk_msg(dev, usb_rcvbulkpipe(dev, EP_IN), buffer, BUF_SIZE, NULL, TIMEOUT)) { dev_err(dev, "Failed to read data from USB\n"); return -EIO; } process_firmware_data(buffer); // 自定义的数据处理函数 return 0; } ``` #### 方法二:基于块设备的固件更新机制 对于某些场景,可以直接将 USB 存储设备挂载为块设备,并将其视为临时存储介质完成固件替换操作。这种方式通常适用于那些拥有较大内部闪存空间或者 SD 卡插槽的产品线[^2]。 - 当前活动分区被标记为主分区A时,在另一份镜像已经下载完毕的情况下切换至备用分区B启动即可达成无缝切换效果;反之亦然。 - 如果采用双分区方案,则还需要额外考虑引导加载器如何识别当前有效的工作区以及何时触发回滚策略等问题。 #### 方法三:网络化远程部署方式结合本地USB验证流程 除了纯粹依赖物理连接之外,还可以借助于互联网技术先从服务器拉取最新版本号及相关元信息后再决定是否继续下一步动作即实际写盘过程。此时可引入第三方工具链简化复杂度比如mtd-utils包里边就包含了诸如flash_eraseall这样的命令可以帮助快速擦除指定区域然后再填充新内容进去[^3]。 另外值得注意的是无论采取哪种途径都务必做好充分测试工作确保不会因为人为失误而导致不可逆损害发生! ```bash #!/bin/bash # Example script for upgrading via USB mass storage class. MOUNT_POINT="/mnt/usb" FIRMWARE_FILE="new-firmware.bin" if ! mount | grep $MOUNT_POINT; then mkdir -p $MOUNT_POINT && \ mount /dev/sda1 $MOUNT_POINT || { echo 'Mount failed!'; exit 1;} fi cp "$MOUNT_POINT/$FIRMWARE_FILE" "/path/to/system/firmware/" && sync umount $MOUNT_POINT reboot now ``` ---
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值