source: trunk/target/linux/ar71xx/base-files/sbin/wget2nand @ 21444

Last change on this file since 21444 was 21444, checked in by juhosg, 7 years ago

ar71xx: Make wget2nand fail if copying the kernel fails and use the correct file extension for the rootfs image

wget2nand didnt check the exit status after copying the kernel, if the
copying failed for some reason ( for example not enougs space on the
kernel partition) it simply continued extracting the rootfs.
I also changed the filename, which wget2nand trys to download (
.tar.gz instead of .tgz ).

Signed-off-by: Marko Foerster <mrkfoerster@…>

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/sh
2# wget2nand
3# This script can be used to download a TGZ file from your build system which
4# contains the files to be installed on the NAND flash on your RB1xx card.
5# The one parameter is the URL of the TGZ file to be downloaded.
6# Licence GPL V2
7# Author david.goodenough@linkchoose.co.uk
8# Based on cf2nand from RB532 support
9. /etc/functions.sh
10
11wget2nand_dir=/tmp/wget2nand
12mnt_kernel=$wget2nand_dir/mnt_kernel
13mnt_rootfs=$wget2nand_dir/mnt_rootfs
14src_rootfs=$wget2nand_dir/rootfs.tgz
15src_kernel=$wget2nand_dir/kernel
16
17[ -d "$wget2nand_dir" ] && {
18        echo "$wget2nand_dir already exists"
19        exit 1
20}
21
22# need to find the wget server from the command line
23url=$1
24[ -z "$url" ] && {
25        echo "No URL specified for image TGZ"
26        echo "Usage : $0 URL"
27        exit 1
28}
29
30url_kernel=$url/openwrt-ar71xx-vmlinux.elf
31url_rootfs=$url/openwrt-ar71xx-rootfs.tar.gz
32
33mtd_kernel="$(find_mtd_part 'kernel')"
34mtd_rootfs="$(find_mtd_part 'rootfs')"
35[ -z "$mtd_kernel" -o -z "$mtd_rootfs" ] && {
36        echo "Cannot find NAND Flash partitions"
37        exit 1
38}
39
40mkdir "$wget2nand_dir"
41wget $url_kernel -O "$src_kernel" || {
42        echo "Unable to download $url_kernel"
43        exit 1
44}
45
46wget $url_rootfs -O "$src_rootfs" || {
47        echo "Unable to download $url_rootfs"
48        exit 1
49}
50
51echo "Erasing filesystem..."
52mtd erase kernel 2>/dev/null >/dev/null
53mtd erase rootfs 2>/dev/null >/dev/null
54
55echo "Mounting $mtd_rootfs as new root and $mtd_kernel as kernel partition"
56
57mkdir "$mnt_kernel"
58mkdir "$mnt_rootfs"
59mount -t yaffs2 "$mtd_kernel" "$mnt_kernel"
60mount -t yaffs2 "$mtd_rootfs" "$mnt_rootfs"
61
62echo "Copying kernel..."
63cp $src_kernel $mnt_kernel/kernel || {
64       echo "Error occured while copying the kernel"
65       exit 1
66}
67chmod +x $mnt_kernel/kernel
68
69echo "Preparing filesystem..."
70( cd "$mnt_rootfs"; tar xvz -f "$src_rootfs" )
71
72# make sure everything is written before we unmount the partitions
73echo "chmod ugo+x /" > $mnt_rootfs/etc/uci-defaults/set_root_permission
74sync
75ls $mnt_kernel >/dev/null
76ls $mnt_rootfs >/dev/null
77
78echo "Cleaning up..."
79# unmount the partitions and remove the directories into which they were mounted
80umount $mnt_kernel
81umount $mnt_rootfs
82rm -rf $wget2nand_dir
83
84# all done
85echo "Image written, you can now reboot.  Remember to change the boot source to Boot from Nand"
Note: See TracBrowser for help on using the repository browser.