- 收藏
- 点赞
- 分享
- 举报
在线升级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里的文件系统了。
结束。
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
-
2017-07-10 22:22:52
-
2018-03-07 14:22:11
-
2015-11-13 17:53:06
-
2014-10-23 10:20:14
-
2017-07-29 18:25:24
-
2016-06-16 16:31:36
-
2016-06-21 18:01:31
-
2019-09-20 18:12:07
-
2015-07-22 11:04:25
-
2019-12-19 14:38:37
-
2023-02-22 11:42:34
-
2018-03-29 16:29:09
-
12014-11-24 21:43:21
-
2016-03-14 10:42:43
-
2015-07-22 09:38:59
-
2020-09-26 15:17:20
-
32020-07-08 19:27:15
-
2018-06-15 16:53:42
-
2018-11-21 10:56:02
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
-
10求HI3519DV500_SDK_V2.0.1.1
-
5有偿求HI3516DV500 + OV5647驱动
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明