1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# vim: filetype=sh
ARM_BINFMT_DEF=/proc/sys/fs/binfmt_misc/qemu-arm
ERR_CPU_EMULATION="E: Cannot continue because host OS does not provide ARM cpu emulation."
has_fix_binary_flag()
{
cat $1 | grep "flags" | grep 'F' >/dev/null
}
prepare_rootfs_for_emulation()
{
if [ ! -f $ARM_BINFMT_DEF ]
then
echo "$ERR_CPU_EMULATION" >&2
return 1
fi
if has_fix_binary_flag "$ARM_BINFMT_DEF"
then
# ok the binary of the emulator was loaded once for all when the
# binfmt_misc entry was registered, so emulation will be available
# in target too
# see https://www.kernel.org/doc/Documentation/admin-guide/binfmt-misc.rst
# the section about flag "F".
return
fi
set -- $(cat $ARM_BINFMT_DEF | grep interpreter)
interpreter_path="$(readlink -f $2)"
if [ ! -f "./$interpreter_path" ]
then
# emulator binary is missing in target
# verify we have it on the host
if [ ! -f "$interpreter_path" ]
then
echo "$ERR_CPU_EMULATION" >&2
return 1
fi
# ok, copy the one from the host
cp "$interpreter_path" "./$interpreter_path"
# keep track of this
echo "$interpreter_path" > .emulation.added
fi
}
cleanup_rootfs_for_emulation()
{
if [ -f .emulation.added ]
then
rm "./$(cat .emulation.added)"
rm .emulation.added
fi
}
|