Packager @Kevin Mihelich <kevin@archlinuxarm.org>
flash_uboot in .INSTALL for package uboot-odroid-n2 chooses the device to flash the uboot to with the following code:
$this->bbcode_second_pass_code('', '
flash_uboot() {
major=$(mountpoint -d / | cut -f 1 -d ':')
minor=$(mountpoint -d / | cut -f 2 -d ':')
device=$(cat /proc/partitions | awk {'if ($1 == "'${major}'" && $2 == "'${minor}'") print $4 '})
device="/dev/${device%%p*}"
...
')
I suggest that the mountpoint should check /boot first to see if it is a mountpoint for a partition. If that fails to find a partition then fall back to /.
I boot my n2 from an sd card which only has /boot contents in its first partition / and the boot.ini therein sets root=PARTUUID= to a partition on a USB attached SSD. fstab mounts the boot partition onto /boot. So with mountpoint -d / the device is set to /dev/sda1 rather than /dev/mmcblk1 which is what needs to be flashed. Since /boot and / can be on separate drives, I think it makes sense to check /boot first.
Alternatively, one could look at /proc/mounts. For example:
$this->bbcode_second_pass_code('', '
$ cat /proc/mounts | grep ' /boot '
/dev/mmcblk1p1 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
$ cat /proc/mounts | grep ' / '
/dev/sdb1 / ext4 rw,relatime,stripe=8191,data=ordered 0 0
')
So the code could be
$this->bbcode_second_pass_code('', '
device=$(cat /proc/mounts | grep ' /boot ' | awk '{ print $1 }')
[ -z "${device}" ] && device=$(cat /proc/mounts | grep ' / ' | awk '{ print $1 }')
device="${device%p*}"
')