52171314

52171314

0个粉丝

51

问答

0

专栏

29

资料

52171314  发布于  2013-11-16 18:04:22
采纳率 0%
51个问答
4549

在线升级uboot,内核和文件系统

原帖地址:http://blog.csdn.net/fulinus/article/details/9033147 在线升级uboot,内核和文件系统

fulinux

下面我在fl2440开发板上运行正常的情况下实现更新或升级uboot,内核和文件系统的任务。

如下是一个在线升级的脚本:

!/bin/sh

This shell scripts used to update the u-boot linux kernel, root file system image when Linux running

erase_cmd=flash_eraseall

write_cmd=nandwrite

cu_version=cat /proc/version

PROG_NAME=basename $0

IMAGE_TYPE=

ROOTFS_TYPE=

usage()

{

echo " Usage: $PROG_NAME -[f/k/u/h] [filename]"

echo "Example: $PROG_NAME linuxrom-s3c2440.bin"

echo " $PROG_NAME u-boot-s3c2440.bin"

echo " $PROG_NAME rootfs.jffs2"

echo " $PROG_NAME -u uboot.bin"

echo " $PROG_NAME -k lin.bin"

echo " $PROG_NAME -f fs.yaffs2"

echo " $PROG_NAME -h"

exit;

}

burn_image()

{

partition=$1

file_name=$2

if ( ! $erase_cmd /dev/$partition) ; then

    echo "Erase /dev/$partition failure."

    exit

fi

if ( ! $write_cmd -p /dev/$partition $file_name) ; then

    echo "Write $file_name to /dev/$partition failure."

    exit

fi

}

check_and_umount()

{

MTD=$1

MTDBLOCK=mtdblock${MTD:3}

MOUNT_BLOCK=`cat /proc/mounts | grep $MTDBLOCK|awk -F " " '{print $1}'`

if [ -n "$MOUNT_BLOCK" ] ; then

    umount /dev/$MTDBLOCK

else

    echo "No need umount $MTDBLOCK"

fi

}

check_image_type()

{

IMAGE_NAME=$1

if echo $IMAGE_NAME | grep -E "boot|uboot|u-boot|bootloader" > /dev/null ; then

    IMAGE_TYPE=BOOTLOADER

elif echo $IMAGE_NAME | grep -E "linux|kernel" > /dev/null ; then

    IMAGE_TYPE=KERNEL

elif  echo $IMAGE_NAME | grep -E "rootfs|jffs2|yaffs2|ubifs|cramfs|ramdisk" > /dev/null ; then

    IMAGE_TYPE=ROOTFS

else

    IMAGE_TYPE=UNKNOW

fi

}

up_bootloader()

{

IMAGE_FILE=$1

echo "Upgrade bootloader image '$IMAGE_FILE'"

#To-Do: Find the mtd here, only do upgrade if we can find it, or throw error and exit out

#echo $mtd | grep -E "u-boot|uboot" | awk -F ":" '{print $1}'

partition=`cat /proc/mtd | grep -E "uboot|u-boot|U-boot|bootloader" | awk -F ":" '{print $1}'`

if [ -z $partition ] ; then

    echo "Can not find the u-boot partition for update!"

    exit

fi

#To-Do: Start to burn the image to corresponding partition here

burn_image $partition $IMAGE_FILE

}

up_kernel()

{

IMAGE_FILE=$1

echo "Upgrade linux kernel image '$IMAGE_FILE'"

#To-Do: Find the mtd here, only do upgrade if we can find it, or throw error and exit out

#echo $mtd | grep -E "linux|kernel" | awk -F ":" '{print $1}'

partition=`cat /proc/mtd | grep -E "linux|kernel" | awk -F ":" '{print $1}'`

if [ -z $partition ] ; then

    echo "Can not find the kernel partition for update!"

    exit

fi

#To-Do: Start to burn the image to corresponding partition here

burn_image $partition $IMAGE_FILE

}

up_rootfs()

{

IMAGE_NAME=$1

ROOTFS_TYPE=${IMAGE_NAME##*.}

VALID_ROOTFS_TYPE=0

echo $ROOTFS_TYPE

for i in jffs2 yaffs2 ubifs ramdisk cramfs ; do

    if [ "$i" = "$ROOTFS_TYPE" ] ; then

        VALID_ROOTFS_TYPE=1

        break;

    fi

done

if [ 0 == $VALID_ROOTFS_TYPE ] ; then

    echo "============================================================================================"

    echo "ERROR: Unknow rootfs image '$IMAGE_NAME', suffix/type: .$ROOTFS_TYPE"

    echo "The suffix of rootfs image file name should be: .ramdisk .yaffs2 .jffs2 .ubifs .cramfs"

    echo "============================================================================================"

    usage

fi

echo "Upgrade $ROOTFS_TYPE rootfs image '$IMAGE_FILE'"

#To-Do: Find the mtd here, only do upgrade if we can find it, or throw error and exit out

MTD=`cat /proc/mtd | grep -E "$ROOTFS_TYPE" | awk -F ":" '{print $1}'`

#To-Do: Check this partition already mounted or not, if mounted then umount it first here

check_and_umount $MTD

#To-Do: Start to burn the image to corresponding partition here                                                                                                                    

burn_image $MTD $IMAGE_FILE

}

while getopts "afku" opt

do

case $opt in

  a)

       IMAGE_TYPE=APPS

       shift 1

       break;

       ;;

  k)

       IMAGE_TYPE=KERNEL

       shift 1

       break;

       ;;

  f)

       IMAGE_TYPE=ROOTFS

       shift 1

       break;

       ;;

  u)

       IMAGE_TYPE=BOOTLOADER

       shift 1

       break;

       ;;

  h)

       usage

       ;;

  ?)

       usage

       ;;

esac

done

IMAGE_FILE=$1

if [ ! -n "$IMAGE_FILE" ] ; then

usage

fi

if [ ! -n "$IMAGE_TYPE" ] ; then

check_image_type  $IMAGE_FILE

fi

if [ $IMAGE_TYPE == BOOTLOADER ] ; then

up_bootloader $IMAGE_FILE

elif [ $IMAGE_TYPE == KERNEL ] ; then

up_kernel $IMAGE_FILE

elif [ $IMAGE_TYPE == ROOTFS ] ; then

echo "$IMAGE_FILE ***************"

up_rootfs $IMAGE_FILE

else

echo "============================================================================================"

echo "ERROR: Unknow image type: '$IMAGE_NAME'"

echo "============================================================================================"

usage

fi

文件系统如下:

[lingyun@localhost fulinux]$ ls

kernel rootfs systools u-boot

[lingyun@localhost fulinux]$ cd rootfs/

[lingyun@localhost rootfs]$ ls

ramdisk-s3c2440.gz rootfs rootfs_tree.tar.bz2 tools

[lingyun@localhost rootfs]$ cd rootfs

[lingyun@localhost rootfs]$ pwd

/home/lingyun/fulinux/rootfs/rootfs

[lingyun@localhost rootfs]$

因为上面的shell脚本需要用到两个应用程序flash_eraseall和nandwrite所以需要在上面的文件系统里有这两个程序。如果没有添加方式如下:

[lingyun@localhost fulinux]$ ls

kernel rootfs systools u-boot

[lingyun@localhost fulinux]$ cd systools/

[lingyun@localhost systools]$ ls

busybox

[lingyun@localhost systools]$ cd busybox/

[lingyun@localhost busybox]$ ls

build.sh busybox-1.20.2 busybox-1.20.2.tar.bz2 patch

[lingyun@localhost busybox]$ cd busybox-1.20.2

[lingyun@localhost busybox-1.20.2]$

[lingyun@localhost busybox]$ ls

build.sh busybox-1.20.2 busybox-1.20.2.tar.bz2 patch

[lingyun@localhost busybox]$ cd busybox-1.20.2

[lingyun@localhost busybox-1.20.2]$ vt100

[lingyun@localhost busybox-1.20.2]$ make menuconfig

主目录:

Busybox Settings --->

。。。

Installation Options ("make install" behavior) --->

What kind of applet links to install (as soft-links) --->

指定文件系统的目录位置:

(/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs) BusyBox installation prefix

。。。

回到主目录:

Miscellaneous Utilities --->

选择如下的两个程序:

。。。

[*] nandwrite

。。。

[*] flash_eraseall

。。。

保存退出。

[lingyun@localhost busybox-1.20.2]$ sudo make install

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/[ -> busybox

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/[[ -> busybox

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/addgroup -> busybox

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/adduser -> busybox

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/arping -> busybox

/home/lingyun/fulinux/systools/busybox/../../rootfs/rootfs//bin/ash -> busybox

。。。。

[lingyun@localhost busybox-1.20.2]$ cd ~/fulinux/rootfs/rootfs

将脚本文件拷贝到tftp/目录下:

[fulinux@centos6 tftp]$ ls

upgrade

下面将根目录以jffs2文件系统形式移植到开发板中去,如下:

Copyright (C) 2013 fulinux [email]fulinux@sina.com[/email]

root login: root

: ls

apps data etc init linuxrc proc sbin tmp var

bin dev info lib mnt root sys usr

:

将tftp目录下的upgrade文件下载到开发板中:

: tftp -gr upgrade 192.168.1.3

upgrade 100% |***| 5116 0:00:00 ETA

: ls

apps data etc init linuxrc proc sbin tmp usr

bin dev info lib mnt root sys upgrade var

: ll upgrade

-rw-r--r-- 1 root root 5116 Feb 17 02:57 upgrade

: chmod +x upgrade

: ll upgrade

-rwxr-xr-x 1 root root 5116 Feb 17 02:57 upgrade

:

将要升级或更新的uboot下载到开发板上,然后执行脚本升级uboot,如下:

: tftp -gr u-boot-s3c2440.bin 192.168.1.3

u-boot-s3c2440.bin 100% |***| 277k 0:00:00 ETA

: ./upgrade

Usage: upgrade -[f/k/u/h] [filename]

Example: upgrade linuxrom-s3c2440.bin

       upgrade  u-boot-s3c2440.bin

       upgrade  rootfs.jffs2

       upgrade -u uboot.bin

       upgrade -k lin.bin

       upgrade -f fs.yaffs2

       upgrade -h

: ./upgrade -u u-boot-s3c2440.bin

Upgrade bootloader image 'u-boot-s3c2440.bin'

Erasing 128 Kibyte @ 100000 - 100% complete.

Writing at 0x00000000

Writing at 0x00020000

Writing at 0x00040000

: reboot

重启后如下:

。。。

root login: root

: ls

apps info proc u-boot-s3c2440.bin

bin init root upgrade

data lib sbin usr

dev linuxrc sys var

etc mnt tmp

:

将要升级或更新的内核下载到开发板上,然后执行脚本升级内核,如下:

: tftp -gr linuxrom-s3c2440.bin 192.168.1.3

linuxrom-s3c2440.bin 100% |***| 2552k 0:00:00 ETA

: sh upgrade

Usage: upgrade -[f/k/u/h] [filename]

Example: upgrade linuxrom-s3c2440.bin

       upgrade  u-boot-s3c2440.bin

       upgrade  rootfs.jffs2

       upgrade -u uboot.bin

       upgrade -k lin.bin

       upgrade -f fs.yaffs2

       upgrade -h

: sh upgrade -k linuxrom-s3c2440.bin

Upgrade linux kernel image 'linuxrom-s3c2440.bin'

Erasing 128 Kibyte @ f00000 - 100% complete.

Writing at 0x00000000

Writing at 0x00020000

Writing at 0x00040000

Writing at 0x00060000

Writing at 0x00080000

Writing at 0x000a0000

Writing at 0x000c0000

Writing at 0x000e0000

Writing at 0x00100000

Writing at 0x00120000

Writing at 0x00140000

Writing at 0x00160000

Writing at 0x00180000

Writing at 0x001a0000

Writing at 0x001c0000

Writing at 0x001e0000

Writing at 0x00200000

Writing at 0x00220000

Writing at 0x00240000

Writing at 0x00260000

: reboot

重启后如下:

Copyright (C) 2013 fulinux[email]fulinux@sina.com[/email]

root login: root

: ls

apps lib sys

bin linuxrc tmp

data linuxrom-s3c2440.bin u-boot-s3c2440.bin

dev mnt upgrade

etc proc usr

info root var

init sbin

:

将要升级或更新的文件系统下载到开发板上,然后执行脚本升级文件系统,下面以jffs2文件系统为例:

话说,如果是initramfs文件系统的话就可以比较好的更新或是升级一个文件系统,但是我们这里是用的jffs2,不能再jffs2分区里把他擦了在跟新一个jffs2到这个分区中去,所以我们用另一种方式来达到这种更新文件系统效果。我们的根文件系统是出于mtdblock4分区中的,我们的mtdblock5分区原本是准备放yaffs2的,但是现在这个分区没有任何文件系统,我们就将jffs2文件系统更新到这个分区中去,然后通过修改uboot中的bootargs参数就可以从mtdblock5分区启动根文件系统了,具体操作如下:

~ >: tftp -gr rootfs.jffs2 192.168.1.3

rootfs.jffs2 100% |***| 20480k 0:00:00 ETA

~ >: tftp -gr upgrade 192.168.1.3

upgrade 100% |***| 5138 0:00:00 ETA

~ >: chmod +x upgrade

~ >: cat /proc/mtd

dev: size erasesize name

mtd0: 00100000 00020000 "mtdblock0 u-boot 1MB"

mtd1: 00f00000 00020000 "mtdblock1 kernel 15MB"

mtd2: 01400000 00020000 "mtdblock2 ramdisk 20MB"

mtd3: 01400000 00020000 "mtdblock3 cramfs 20MB"

mtd4: 01400000 00020000 "mtdblock4 jffs2 20MB"

mtd5: 02800000 00020000 "mtdblock5 yaffs2 40MB"

mtd6: 02800000 00020000 "mtdblock6 ubifs 40MB"

mtd7: 02800000 00020000 "mtdblock7 apps 40MB"

mtd8: 03c00000 00020000 "mtdblock8 data 40MB"

~ >: flash_eraseall /dev/mtd5

Erasing 128 Kibyte @ 2800000 - 100% complete.

~ >: nandwrite -p /dev/mtd5 rootfs.jffs2

Writing at 0x00000000

Writing at 0x00020000

Writing at 0x00040000

Writing at 0x00060000

Writing at 0x00080000

Writing at 0x000a0000

Writing at 0x000c0000

Writing at 0x000e0000

Writing at 0x00100000

Writing at 0x00120000

Writing at 0x00140000

Writing at 0x00160000

Writing at 0x00180000

Writing at 0x001a0000

Writing at 0x001c0000

Writing at 0x001e0000

Writing at 0x00200000

Writing at 0x00220000

Writing at 0x00240000

Writing at 0x00260000

Writing at 0x00280000

Writing at 0x002a0000

Writing at 0x002c0000

Writing at 0x002e0000

Writing at 0x00300000

Writing at 0x00320000

Writing at 0x00340000

Writing at 0x00360000

Writing at 0x00380000

Writing at 0x003a0000

Writing at 0x003c0000

Writing at 0x003e0000

Writing at 0x00400000

Writing at 0x00420000

Writing at 0x00440000

Writing at 0x00460000

Writing at 0x00480000

Writing at 0x004a0000

Writing at 0x004c0000

Writing at 0x004e0000

Writing at 0x00500000

Writing at 0x00520000

Writing at 0x00540000

Writing at 0x00560000

Writing at 0x00580000

Writing at 0x005a0000

Writing at 0x005c0000

Writing at 0x005e0000

Writing at 0x00600000

Writing at 0x00620000

Writing at 0x00640000

Writing at 0x00660000

Writing at 0x00680000

Writing at 0x006a0000

Writing at 0x006c0000

Writing at 0x006e0000

Writing at 0x00700000

Writing at 0x00720000

Writing at 0x00740000

Writing at 0x00760000

Writing at 0x00780000

Writing at 0x007a0000

Writing at 0x007c0000

Writing at 0x007e0000

Writing at 0x00800000

Writing at 0x00820000

Writing at 0x00840000

Writing at 0x00860000

Writing at 0x00880000

Writing at 0x008a0000

Writing at 0x008c0000

Writing at 0x008e0000

Writing at 0x00900000

Writing at 0x00920000

Writing at 0x00940000

Writing at 0x00960000

Writing at 0x00980000

Writing at 0x009a0000

Writing at 0x009c0000

Writing at 0x009e0000

Writing at 0x00a00000

Writing at 0x00a20000

Writing at 0x00a40000

Writing at 0x00a60000

Writing at 0x00a80000

Writing at 0x00aa0000

Writing at 0x00ac0000

Writing at 0x00ae0000

Writing at 0x00b00000

Writing at 0x00b20000

Writing at 0x00b40000

Writing at 0x00b60000

Writing at 0x00b80000

Writing at 0x00ba0000

Writing at 0x00bc0000

Writing at 0x00be0000

Writing at 0x00c00000

Writing at 0x00c20000

Writing at 0x00c40000

Writing at 0x00c60000

Writing at 0x00c80000

Writing at 0x00ca0000

Writing at 0x00cc0000

Writing at 0x00ce0000

Writing at 0x00d00000

Writing at 0x00d20000

Writing at 0x00d40000

Writing at 0x00d60000

Writing at 0x00d80000

Writing at 0x00da0000

Writing at 0x00dc0000

Writing at 0x00de0000

Writing at 0x00e00000

Writing at 0x00e20000

Writing at 0x00e40000

Writing at 0x00e60000

Writing at 0x00e80000

Writing at 0x00ea0000

Writing at 0x00ec0000

Writing at 0x00ee0000

Writing at 0x00f00000

Writing at 0x00f20000

Writing at 0x00f40000

Writing at 0x00f60000

Writing at 0x00f80000

Writing at 0x00fa0000

Writing at 0x00fc0000

Writing at 0x00fe0000

Writing at 0x01000000

Writing at 0x01020000

Writing at 0x01040000

Writing at 0x01060000

Writing at 0x01080000

Writing at 0x010a0000

Writing at 0x010c0000

Writing at 0x010e0000

Writing at 0x01100000

Writing at 0x01120000

Writing at 0x01140000

Writing at 0x01160000

Writing at 0x01180000

Writing at 0x011a0000

Writing at 0x011c0000

Writing at 0x011e0000

Writing at 0x01200000

Writing at 0x01220000

Writing at 0x01240000

Writing at 0x01260000

Writing at 0x01280000

Writing at 0x012a0000

Writing at 0x012c0000

Writing at 0x012e0000

Writing at 0x01300000

Writing at 0x01320000

Writing at 0x01340000

Writing at 0x01360000

Writing at 0x01380000

Writing at 0x013a0000

Writing at 0x013c0000

Writing at 0x013e0000

Writing at 0x01400000

~ >: reboot

重启后设置bootargs参数,如下:

[ s3c2440@guowenxue ]# set bootargs 'noinitrd root=/dev/mtdblock5 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200'

[ s3c2440@guowenxue ]# boot

就可启动mtdblock5里的文件系统了。

结束。

我来回答
回答3个
时间排序
认可量排序

hxivxfrk

0个粉丝

4

问答

0

专栏

0

资料

hxivxfrk 2013-11-16 18:36:15
认可0
在遇到你之前,我对人世间是否有真正的圣人是怀疑的;而现在,我终于相信了!我曾经忘情于两汉的歌赋,我曾经惊讶于李杜的诗才,我曾经流连于宋元的词曲。但现在,我才知道我有多么浅薄!楼主,你的高尚情操太让人感动了。在现在这样一个物欲横流的金钱社会里,竟然还能见到楼主这样的性情中人,无疑是我这辈子最大的幸运。让我深深感受到了人性的伟大。楼主的帖子,就好比黑暗中刺裂夜空的闪电,又好比撕开乌云的阳光.

hrx2018

0个粉丝

8

问答

0

专栏

0

资料

hrx2018 2013-11-21 22:07:05
认可0
这帖子好长啊啊啊

wuoxivao

0个粉丝

4

问答

0

专栏

0

资料

wuoxivao 2013-11-17 19:47:53
认可0
好长啊:Q:Q:Q:Q:Q
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区