~ubuntu-branches/ubuntu/hardy/flash-kernel/hardy

« back to all changes in this revision

Viewing changes to flash-kernel

  • Committer: Bazaar Package Importer
  • Author(s): Martin Michlmayr
  • Date: 2007-11-20 09:41:57 UTC
  • Revision ID: james.westby@ubuntu.com-20071120094157-mokjpmckxfu2im63
Tags: 1.6
* Check whether kernel and ramdisk fit into flash before writing
  them.
* Use the whole partition available for the ramdisk on NSLU2 (6 MB),
  not just the first 4 MB.  In order to be actually able to use
  ramdisks larger than 4 MB, a new version of APEX is needed though
  (see #451882).
* Remove Iomega NAS 100d support at the request of Rod Whitby since
  the firmware does CRC checks and this isn't handled yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        grep "\"$1\"" /proc/mtd | cut -d: -f 1 | sed 's/mtd/\/dev\/mtdblock/'
23
23
}
24
24
 
 
25
mtdsize() {
 
26
        size=$(grep "\"$1\"" /proc/mtd | cut -d " " -f 2)
 
27
        printf "%d" 0x$size
 
28
}
 
29
 
25
30
check_subarch() {
26
31
        if [ -n "$subarch" ] && [ "$subarch" != "$1" ]; then
27
32
                echo "Kernel $kfile does not match your subarchitecture" >&2
30
35
        fi
31
36
}
32
37
 
 
38
check_size() {
 
39
        if [ $2 -gt $3 ]; then
 
40
                error "The $1 doesn't fit in flash."
 
41
        fi
 
42
}
 
43
 
33
44
# See http://www.nslu2-linux.org/wiki/Info/BootFlash -- the NSLU2 uses a
34
45
# 16 byte MTD header, the first four bytes (big endian) give the length of
35
46
# the remainder of the image, and the remaining bytes are zero.  Generate
66
77
if [ ! -e $kfile ] || [ ! -e $ifile ]; then
67
78
        error "Can't find $kfile and $ifile"
68
79
fi
 
80
kfilesize=$(wc -c $kfile | awk '{print $1}')
 
81
ifilesize=$(wc -c $ifile | awk '{print $1}')
69
82
 
70
83
# Extract the subarchitecture from the kernel name
71
84
if [ -L "$kfile" ]; then
86
99
                        ;;
87
100
                esac
88
101
                check_mtd
89
 
                mtdfis=$(mtdblock "FIS directory")
90
 
                if [ -z "$mtdfis" ]; then
 
102
                fismtd=$(mtdblock "FIS directory")
 
103
                if [ -z "$fismtd" ]; then
91
104
                        error "Cannot find mtd FIS directory"
92
105
                fi
93
 
                mtdkernel=$(mtdblock Kernel)
94
 
                if [ -z "$mtdkernel" ]; then
 
106
                kmtd=$(mtdblock Kernel)
 
107
                if [ -z "$kmtd" ]; then
95
108
                        error "Cannot find mtd partition 'Kernel'"
96
109
                fi
97
 
                mtdramdisk=$(mtdblock Ramdisk)
98
 
                if [ -z "$mtdramdisk" ]; then
 
110
                kmtdsize=$(mtdsize "Kernel")
 
111
                check_size "kernel" $(($kfilesize + 16 + 16)) $kmtdsize
 
112
                imtd=$(mtdblock Ramdisk)
 
113
                if [ -z "$imtd" ]; then
99
114
                        error "Cannot find mtd partition 'Ramdisk'"
100
115
                fi
 
116
                imtdsize=$(mtdsize "Ramdisk")
 
117
                check_size "ramdisk" $(($ifilesize + 16)) $imtdsize
101
118
                # The following devio magic parses the FIS directory to
102
119
                # obtain the size, offset and name of each partition.  This
103
120
                # used used to obtain the offset of the Kernel partition.
104
 
                offset=$(echo "$(devio "<<$mtdfis" '
 
121
                offset=$(echo "$(devio "<<$fismtd" '
105
122
                        <= $ 0x20000 -
106
123
                        L= 0x1000
107
124
                        $( 1
129
146
                # kernel into two and write them to flash with two Sercomm
130
147
                # headers.
131
148
                boundary=1441792 # 0x00160000
132
 
                ksize=$(wc -c $kfile | awk '{print $1}')
133
149
                ksize1=$(expr $boundary - $offset - 16)
134
150
                tmp=$(tempfile)
135
151
                printf "Flashing kernel: " >&2
136
152
                (
137
 
                        sercomm_header $(expr $ksize + 16)
 
153
                        sercomm_header $(expr $kfilesize + 16)
138
154
                        dd if=$kfile of=$tmp bs=$ksize1 count=1 2>/dev/null
139
155
                        nslu2_swap $tmp
140
156
                        sercomm_header 131072
141
157
                        dd if=$kfile of=$tmp ibs=$ksize1 skip=1 2>/dev/null
142
158
                        nslu2_swap $tmp
143
159
                        rm -f $tmp
144
 
                ) > "$mtdkernel" || error "failed."
 
160
                ) > "$kmtd" || error "failed."
145
161
                echo "done." >&2
146
162
                printf "Flashing initramfs: " >&2
147
 
                size=$(grep "\"Ramdisk\"" /proc/mtd | cut -d " " -f 2)
148
 
                size=$(printf "%d" 0x$size)
149
 
                isize=$(wc -c $ifile | awk '{print $1}')
150
 
                pad=$(expr $size - $isize - 16)
151
 
                if [ "$pad" -gt 0 ]; then
152
 
                        dd if=$ifile of=$tmp ibs=4M conv=sync 2>/dev/null
153
 
                fi
 
163
                dd if=$ifile of=$tmp ibs=$(($imtdsize - 16)) conv=sync 2>/dev/null
154
164
                (
155
 
                        sercomm_header $isize
 
165
                        sercomm_header $ifilesize
156
166
                        nslu2_swap $tmp
157
167
                        rm -f $tmp
158
 
                ) > $mtdramdisk || error "failed."
159
 
                echo "done." >&2
160
 
        ;;
161
 
        "Iomega NAS 100d")
162
 
                check_subarch "ixp4xx"
163
 
                check_mtd
164
 
                mtdramdisk=$(mtdblock filesystem)
165
 
                if [ -z "$mtdramdisk" ]; then
166
 
                        error "Cannot find mtd partition 'filesystem'"
167
 
                fi
168
 
                mtdkernel=$(mtdblock kernel)
169
 
                if [ -z "$mtdkernel" ]; then
170
 
                        error "Cannot find mtd partition 'kernel'"
171
 
                fi
172
 
                printf "Flashing kernel: " >&2
173
 
                cat $kfile > "$mtdkernel" || error "failed."
174
 
                echo "done." >&2
175
 
                printf "Flashing initramfs: " >&2
176
 
                size=$(grep "\"filesystem\"" /proc/mtd | cut -d " " -f 2)
177
 
                size=$(printf "%d" 0x$size)
178
 
                isize=$(wc -c $ifile | awk '{print $1}')
179
 
                pad=$(expr $size - $isize)
180
 
                (
181
 
                        cat $ifile
182
 
                        dd if=/dev/zero bs=$pad count=1 2>/dev/null
183
 
                ) > $mtdramdisk || error "failed."
 
168
                ) > $imtd || error "failed."
184
169
                echo "done." >&2
185
170
        ;;
186
171
        "Thecus N2100")
187
172
                check_subarch "iop32x"
188
173
                check_mtd
189
 
                mtdramdisk=$(mtdblock ramdisk)
190
 
                if [ -z "$mtdramdisk" ]; then
 
174
                imtd=$(mtdblock ramdisk)
 
175
                if [ -z "$imtd" ]; then
191
176
                        error "Cannot find mtd partition 'ramdisk'"
192
177
                fi
193
 
                mtdkernel=$(mtdblock kernel)
194
 
                if [ -z "$mtdkernel" ]; then
 
178
                imtdsize=$(mtdsize "ramdisk")
 
179
                check_size "ramdisk" $ifilesize $imtdsize
 
180
                kmtd=$(mtdblock kernel)
 
181
                if [ -z "$kmtd" ]; then
195
182
                        error "Cannot find mtd partition 'kernel'"
196
183
                fi
 
184
                kmtdsize=$(mtdsize "kernel")
 
185
                check_size "kernel" $(($kfilesize + 8)) $kmtdsize
197
186
                printf "Flashing kernel... " >&2
198
187
                (
199
188
                        devio 'wl 0xe3a01c04,4' 'wl 0xe381104d,4'
200
189
                        cat $kfile
201
 
                ) > $mtdkernel || error "failed."
 
190
                ) > $kmtd || error "failed."
202
191
                echo "done." >&2
203
192
                printf "Flashing initramfs... " >&2
204
 
                size=$(grep "\"ramdisk\"" /proc/mtd | cut -d " " -f 2)
205
 
                size=$(printf "%d" 0x$size)
206
 
                isize=$(wc -c $ifile | awk '{print $1}')
207
 
                pad=$(expr $size - $isize)
 
193
                pad=$(expr $imtdsize - $ifilesize)
208
194
                (
209
195
                        cat $ifile
210
196
                        dd if=/dev/zero bs=$pad count=1 2>/dev/null
211
 
                ) > $mtdramdisk || error "failed."
 
197
                ) > $imtd || error "failed."
212
198
                echo "done." >&2
213
199
        ;;
214
200
        *)