Root/nanonote-files/base-files/usr/bin/mtd.nn

1#!/bin/sh
2 
3__VERSION__=2012-10-15
4
5if [ "$1" == "flash" ] && [ "$#" == "3" ]; then
6    case "$2" in
7    "bootloader")
8        echo "not implenment"
9    #flash_eraseall /dev/mtd0
10    exit 0
11    ;;
12    "kernel")
13    echo "flashing kernel ..."
14    flash_eraseall /dev/mtd1
15    nandwrite -p /dev/mtd1 "$3"
16    exit 0
17    ;;
18    "rootfs")
19    echo "flashing rootfs ..."
20    ubiformat /dev/mtd2 -f "$3"
21    exit 0
22    ;;
23    "data")
24    echo "flashing data partition ..."
25    ubiformat /dev/mtd3 -f "$3"
26    exit 0
27    ;;
28    esac
29fi
30
31if [ "$1" == "mount" ] && [ "$#" == "3" ]; then
32    if [ "$2" == "rootfs" ] || [ "$2" == "data" ]; then
33    MOUNT_POINT="$3"
34    if [ "$2" == "rootfs" ]; then
35        PARTITION="2"
36    elif [ "$2" == "data" ]; then
37        PARTITION="3"
38    fi
39
40    mkdir -p $MOUNT_POINT
41    if [ "$?" != "0" ]; then
42        echo "mkdir -p $MOUNT_POINT Fail"
43        exit 1
44    fi
45
46    ubiattach /dev/ubi_ctrl -m ${PARTITION} > /dev/null 2>&1
47    DEV_UBI=`dmesg | grep "UBI: attached mtd${PARTITION} to" | tail -n 1 | cut -d ":" -f 2 | cut -d " " -f 5`
48    mount -t ubifs ${DEV_UBI}_0 $MOUNT_POINT
49        exit 0
50    fi
51fi
52
53if [ "$1" == "format_data_default" ]; then
54    ubiformat /dev/mtd3 -y
55    ubiattach /dev/ubi_ctrl -m 3
56    ubimkvol /dev/ubi1 -s 1480MiB -N data
57# test in xiangfu's nanonote. 1486 is the MAX size we can make
58# so we using 1480 for now
59    exit 0
60fi
61
62if [ "$1" == "fw_setenv_default" ]; then
63    fw_setenv bootargs mem=32M console=tty0 console=ttyS0,57600n8 ubi.mtd=2 rootfstype=ubifs root=ubi0:rootfs rw rootwait consoleblank=30 quiet
64    fw_setenv bootcmd nand read 0x80600000 0x400000 0x280000\;bootm
65    fw_setenv bootargsfromsd mem=32M console=tty0 console=ttyS0,57600n8 rootfstype=ext2 root=/dev/mmcblk0p1 rw rootwait
66    fw_setenv bootcmdfromsd mmc init\; ext2load mmc 0 0x80600000 /boot/uImage\; bootm
67    fw_setenv bootdelay 0
68    fw_setenv baudrate 57600
69    fw_setenv loads_echo 1
70    fw_setenv stdin serial
71    fw_setenv stderr serial
72    fw_setenv stdout serial
73    fw_setenv bootcmdf1 mmc init\; ext2load mmc 0:1 0x80600000 /boot/uImage\; bootm
74    fw_setenv bootargsf1 mem=32M console=tty0 console=ttyS0,57600n8 rootfstype=ext2 root=/dev/mmcblk0p1 rw rootwait
75    fw_setenv bootcmdf2 mmc init\; ext2load mmc 0:2 0x80600000 /boot/uImage\; bootm
76    fw_setenv bootargsf2 mem=32M console=tty0 console=ttyS0,57600n8 rootfstype=ext2 root=/dev/mmcblk0p2 rw rootwait
77    fw_setenv bootcmdf3 mmc init\; ext2load mmc 0:3 0x80600000 /boot/uImage\; bootm
78    fw_setenv bootargsf3 mem=32M console=tty0 console=ttyS0,57600n8 rootfstype=ext2 root=/dev/mmcblk0p3 rw rootwait
79    fw_setenv bootcmdf4 mtdparts default\;ubi part rootfs\;ubifsmount rootfs\;ubifsload 0x80600000 /boot/uImage\; bootm
80    fw_setenv bootargsf4 mem=32M console=tty0 console=ttyS0,57600n8 ubi.mtd=2 rootfstype=ubifs root=ubi0:rootfs rw rootwait
81    fw_setenv silent 1
82    echo "fw_setenv finished, check u-boot env by fw_printenv"
83    exit 0
84fi
85
86echo "\
87Usage: $0 [ command ] [ <para1> <para2> <para3> ]
88     flash bootloader|kernel|rootfs|data image_file
89             flash nand partition using <image_file>
90
91     mount rootfs|data mount_point
92             mount nand partition
93
94     format_data_default
95             lookinside for more detari
96             NOTICE:
97                     this command will format data
98                     partition, create a default
99                     1400MB volume, named 'data',
100                     ALL data will lost after run.
101
102     fw_setenv_default
103             reset bootloader default variable
104             lookinside for more detail
105             NOTICE:
106                     this command write hardcode
107                     variables to nand, so it must
108                     run once before you want change
109                     change it.
110
111script file for Qi Hardware Ben NanoNote
112written by: Xiangfu Liu (xiangfu@sharism.cc)
113written with Emacs in Ben NanoNote
114                             version: ${__VERSION__}
115Report bugs to developer@lists.qi-hardware.com"
116exit 0
117

Archive Download this file



interactive