Adriana Kobylak | a290eff | 2017-06-27 09:39:57 -0500 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Get the mtd device number (mtdX) |
| 4 | findmtd() { |
| 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) |
| 12 | findubi() { |
| 13 | u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)" |
| 14 | u="${u%/name}" |
| 15 | u="${u##*/}" |
| 16 | echo "${u}" |
| 17 | } |
| 18 | |
| 19 | ubi_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 | |
| 31 | case "$1" in |
| 32 | ubirw) |
| 33 | reqmtd="$2" |
| 34 | name="$3" |
| 35 | ubi_rw |
| 36 | ;; |
| 37 | *) |
| 38 | echo "Invalid argument" |
| 39 | exit 1 |
| 40 | ;; |
| 41 | esac |
| 42 | rc=$? |
| 43 | if [ ${rc} -ne 0 ]; then |
| 44 | echo "$0: error ${rc}" |
| 45 | exit ${rc} |
| 46 | fi |