blob: 16c5f3285b31df63d51265b41b3d88326f4a87d7 [file] [log] [blame]
Adriana Kobylaka290eff2017-06-27 09:39:57 -05001#!/bin/sh
2
3# Get the mtd device number (mtdX)
4findmtd() {
5 m="$(grep -xl "$1" /sys/class/mtd/*/name)"
6 m="${m%/name}"
7 m="${m##*/}"
8 echo "${m}"
9}
10
11# Get the ubi device number (ubiX_Y)
12findubi() {
13 u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)"
14 u="${u%/name}"
15 u="${u##*/}"
16 echo "${u}"
17}
18
19ubi_rw() {
20 rwmtd="$(findmtd "${reqmtd}")"
21 rw="${rwmtd#mtd}"
22 ubidev="/dev/ubi${rw}"
23
24 # Create a ubi volume of size 4MB, that is the current size of the rwfs image
25 vol="$(findubi "${name}")"
26 if [ -z "${vol}" ]; then
27 ubimkvol "${ubidev}" -N "${name}" -s 4MiB
28 fi
29}
30
31case "$1" in
32 ubirw)
33 reqmtd="$2"
34 name="$3"
35 ubi_rw
36 ;;
37 *)
38 echo "Invalid argument"
39 exit 1
40 ;;
41esac
42rc=$?
43if [ ${rc} -ne 0 ]; then
44 echo "$0: error ${rc}"
45 exit ${rc}
46fi