blob: a4515032776cd80d4975fe43a1f9bb6b8c02bbb7 [file] [log] [blame]
#!/bin/sh
# Get the mtd device number (mtdX)
findmtd() {
m="$(grep -xl "$1" /sys/class/mtd/*/name)"
m="${m%/name}"
m="${m##*/}"
echo "${m}"
}
# Get the ubi device number (ubiX_Y)
findubi() {
u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)"
u="${u%/name}"
u="${u##*/}"
echo "${u}"
}
ubi_rw() {
rwmtd="$(findmtd "${reqmtd}")"
rw="${rwmtd#mtd}"
ubidev="/dev/ubi${rw}"
# Create a ubi volume of size 4MB, that is the current size of the rwfs image
vol="$(findubi "${name}")"
if [ -z "${vol}" ]; then
ubimkvol "${ubidev}" -N "${name}" -s 4MiB
fi
}
ubi_ro() {
romtd="$(findmtd "${reqmtd}")"
ro="${romtd#mtd}"
ubidev="/dev/ubi${ro}"
# Create a static ubi volume
# TODO Get the actual image size openbmc/openbmc#1840
vol="$(findubi "${name}")"
if [ -z "${vol}" ]; then
ubimkvol "${ubidev}" -N "${name}" -s "${imgsize}" --type=static
vol="$(findubi "${name}")"
fi
}
# Squashfs images need a ubi block
ubi_block() {
vol="$(findubi "${name}")"
ubidevid="${vol#ubi}"
block="/dev/ubiblock${ubidevid}"
if [ ! -e "$block" ]; then
ubiblock --create "/dev/ubi${ubidevid}"
fi
}
ubi_updatevol() {
vol="$(findubi "${name}")"
ubidevid="${vol#ubi}"
img="/tmp/images/${version}/${imgfile}"
ubiupdatevol "/dev/ubi${ubidevid}" "${img}"
}
case "$1" in
ubirw)
reqmtd="$2"
name="$3"
ubi_rw
;;
ubiro)
reqmtd="$2"
name="$3"
version="$4"
imgfile="image-rofs"
imgsize="16MiB"
ubi_ro
ubi_block
ubi_updatevol
;;
ubikernel)
reqmtd="$2"
name="$3"
version="$4"
imgfile="image-kernel"
imgsize="4MiB"
ubi_ro
ubi_updatevol
;;
*)
echo "Invalid argument"
exit 1
;;
esac
rc=$?
if [ ${rc} -ne 0 ]; then
echo "$0: error ${rc}"
exit ${rc}
fi