1

I'm trying to emulate a nand flash with qemu and use that to mount an existent ubifs image on the virtual machine.

I added a nand device and a drive of the type mtd, resulting on the following command:

$ qemu-system-arm -nographic -M virt -m 64 -device nand,chip_id=0x59  -drive if=mtd,format=raw,file=data.ubi -kernel openwrt-armvirt-32-zImage-initramfs 
Warning: Orphaned drive without device: id=mtd0,file=data.ubi,if=mtd,bus=0,unit=0
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.19.56 (buildbot@builds) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r10348-577174cf60)) #0 SMP Tue Jun 25 14:46:01 2019
[    0.000000] CPU: ARMv7 Processor [412fc0f1] revision 1 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: linux,dummy-virt
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv0.2 detected in firmware.
...

I can't access to the data.ubi probably because of the following warning:

"Warning: Orphaned drive without device"

How can I add the ubi image to the nand device correctly?

PRVS
  • 1,612
  • 4
  • 38
  • 75
  • What are you trying to do/debug? You can loop back mount ubi on an x86 host and share with the qemu system if you just need the files. – artless noise Jul 03 '19 at 13:10

1 Answers1

1

You have to link the -drive and -device via an id parameter:

qemu-system-arm \
  `: [...]` \
  -device nand,chip_id=0x59,id=myubiflash \
  -drive if=mtd,format=raw,file=data.ubi,id=myubiflash \
  `: [...]`

If you really read the message carefully, you'll notice that the drive id defaults to mtd0:

Warning: Orphaned drive without device: id=mtd0,file=data.ubi,if=mtd,bus=0,unit=0

And of course qemu can't magically guess that you meant to define the -device nand for the drive.

The error message is exactly on the spot here.


Edit

I'll admit, no perfect understanding of the layers of syntax in QEMU commandline on my side either. Also, the QEMU doc isn't the easiest to read; however it has this passage:

A block driver node created with -blockdev can be used for a guest device by specifying its node name for the drive property in a -device argument that defines a block device.

-blockdev is synonym to -drive in this context.

If I can interpret it right, the meaning of this is that instead of

  • -device […],id=foo, -drive […],id=foo

you're supposed to use

  • -device […],drive=foo, -drive […],id=foo

Can't test this ATM, but either of those should make it work for you.

ulidtko
  • 14,740
  • 10
  • 56
  • 88
  • Nice! It solves the problem. However, now it gives me another error regarding the machine type support `qemu-system-arm: -drive if=mtd,format=raw,file=100000.uubi,id=myubiflash: machine type does not support if=mtd,bus=0,unit=0` any idea about this? – PRVS Jul 02 '19 at 13:49
  • @PRVS try running `qemu-system-arm -machine help` and selecting which Arm board you emulate. `-machine virt` might be a good choice here – ulidtko Jul 02 '19 at 18:37
  • Thanks. My problem is that the arm's that are possible to emulate does not have support to NAND, so, it has been dificulty for me to find a solution. – PRVS Jul 03 '19 at 12:34