Features/PC System Flash: Difference between revisions

From QEMU
(Created page with 'This is a proposal for a simple flash emulation on QEMU/KVM. =Command line interface= To enable saving of the flash contents, a -flash a command line parameter would be added. …')
 
No edit summary
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
This is a proposal for a simple flash emulation on QEMU/KVM.
PC System Flash emulation was added for QEMU in pc-1.1.
 
=Flash Hardware=
Uses CFI flash support in hw/pflash_cfi01.c.


=Command line interface=
=Command line interface=
To enable saving of the flash contents, a -flash
Usage of -bios and -pflash parameters as of pc-1.1:
a command line parameter would be added.  This parameter
normally will override the -bios file usage.
 
<Pre>
-flash path    path to filename for saving flash contents
</Pre>
 
If the flash path does not exist, then the -bios file will be read to
initialize the flash contents.  If the flash path does exist, then it
will be used instead of the -bios file contents.
 
=VM hardware interface=
 
==Normal reads==
The flash content can be read in 1, 2, 4 or 8 byte sizes like the
current read-only bios rom.  The read accesses are not required to be aligned.


==Programming interface==
{| class='wikitable' border=1
Aside from normal flash read operations, the flash can be communicated
! KVM enabled !! -pflash used !! -bios used !! Result
with via special sequences of memory read and write operations.
|-
|rowspan=3 | <Center>No</Center>
| <Center>Yes</Center> || <Center>-</Center>
| -pflash parameter will be loaded as flash image just below 4GB.


This interface supports 32-bit aligned 32-bit data operations as
'bios.bin' and -bios parameter will be ''ignored''.
well as 64-bit aligned 64-bit operations.
|-
| <Center>No</Center> || <Center>No</Center>
| 'bios.bin' will be used to create a read-only pflash drive.


In the following examples, the address 0xfffffffc is used for 32-bit
A flash device is available, but it is read-only.
examples, and 0xfffffff8 is used for 64-bit examples. However,
|-
any properly aligned address can be used from 0x100000000-sizeof(bios.bin)
| <Center>No</Center> || <Center>Yes</Center>
up through 0xfffffff8 (for 64-bit operations) or 0xfffffffc (for 32-bit
| -bios parameter will be used to create a read-only pflash drive.
operations).


Only 1 flash communication operation can occur at one time. If any
A flash device is available, but it is read-only.
flash write occurs in another area of the flash, the the previous
|-
operation will be cancelled.
|rowspan=3 | <Center>Yes</Center>
|| <Center>Yes</Center> || <Center>-</Center>
| An error message condition:


===Entering flash communication mode===
PC system firmware (pflash) not available
32-bit mode:
|-
<Pre>
|| <Center>No</Center> || <Center>No</Center>
write32(addr=0xfffffffc, data=0x5a5a5a5a)
| 'bios.bin' will be loaded as rom image.
read32(addr=0xfffffffc) => returns 0xa5a5a5a5
</Pre>
64-bit mode:
<Pre>
write64(addr=0xfffffff8, data=0x5a5a5a5a5a5a5a5a)
read64(addr=0xfffffff8) => returns 0xa5a5a5a5a5a5a5a5
</Pre>


===Program flash===
No system flash is available.
* The flash must be in flash communication mode
|-
32-bit mode:
| <Center>No</Center> || <Center>Yes</Center>
<Pre>
| -bios parameter filename will be loaded as rom image.
write32(addr=0xfffffffc, data=0x0)
read32(addr=0xfffffffc) => returns current flash contents
write32(addr=0xfffffffc, data=new flash contents)
read32(addr=0xfffffffc) => returns new flash contents
read32(addr=0xfffffffc) => returns new flash contents ^ 0xffffffff
</Pre>
64-bit mode:
<Pre>
write64(addr=0xfffffff8, data=0x0)
read64(addr=0xfffffff8) => returns current flash contents
write64(addr=0xfffffff8, data=new flash contents)
read64(addr=0xfffffff8) => returns new flash contents
read64(addr=0xfffffff8) => returns new flash contents ^ 0xffffffffffffffff
</Pre>
* Following a successful program operation, the flash will immediately return to normal read mode.


===Flash size read===
No system flash is available.
* The flash must be in flash communication mode
|}
32-bit mode:
<Pre>
write32(addr=0xfffffffc, data=0x1)
read32(addr=0xfffffffc) => returns the size of the flash device
read32(addr=0xfffffffc) => returns the flash size ^ 0xffffffff
</Pre>
64-bit mode:
<Pre>
write64(addr=0xfffffff8, data=0x1)
read64(addr=0xfffffff8) => returns the size of the flash device
read64(addr=0xfffffff8) => returns the flash size ^ 0xffffffffffffffff
</Pre>
* Following a flash size read operation, the flash will immediately return to normal read mode.


===Interruptions===
==pflash drives==
* If the sequences above are not followed exactly, then the flash device should cancel the operation and immediately enter read mode.
The flash image can be any drive image format supported by QEMU.
* If a non-aligned write operation or a 1 or 2 byte write occurs to the  flash while a flash operation is in progress, then the current operation is immediately cancelled.
* If a properly aligned write operation occurs to an different address or of a different size while another operation is in progress, then the current operation is immediately cancelled.  If the write was the proper value to begin entering flash communication mode, then it will be accepted, and the sequence can proceed as a new operation.


==Examples==
There are two ways to add the pflash drive when launching qemu-system-i386 or qemu-system-x86_64:
* 32-bit flash write example at address 0xffff0000.  Data: old=0x76543210, new=0xfedcba98
# Use the -pflash parameter
<Pre>
# Use the -drive parameter with if=pflash
write32(addr=0xffff0000, data=0x5a5a5a5a)
read32(addr=0xffff0000) => returns 0xa5a5a5a5
write32(addr=0xffff0000, data=0x0)
read32(addr=0xffff0000) => returns 0x76543210
write32(addr=0xffff0000, data=0xfedcba98)
read32(addr=0xffff0000) => returns 0xfedcba98
read32(addr=0xffff0000) => returns 0x01234567
</Pre>


* 64-bit read flash size example at address 0xffff0000.  Flash size=0x100000
[[Category:Completed feature pages]]
<Pre>
write64(addr=0xffff0000, data=0x5a5a5a5a)
read64(addr=0xffff0000) => returns 0xa5a5a5a5
write64(addr=0xffff0000, data=0x1)
read64(addr=0xffff0000) => returns 0x00100000
read64(addr=0xffff0000) => returns 0xffefffff
</Pre>

Latest revision as of 15:39, 11 October 2016

PC System Flash emulation was added for QEMU in pc-1.1.

Flash Hardware

Uses CFI flash support in hw/pflash_cfi01.c.

Command line interface

Usage of -bios and -pflash parameters as of pc-1.1:

KVM enabled -pflash used -bios used Result
No
Yes
-
-pflash parameter will be loaded as flash image just below 4GB.

'bios.bin' and -bios parameter will be ignored.

No
No
'bios.bin' will be used to create a read-only pflash drive.

A flash device is available, but it is read-only.

No
Yes
-bios parameter will be used to create a read-only pflash drive.

A flash device is available, but it is read-only.

Yes
Yes
-
An error message condition:

PC system firmware (pflash) not available

No
No
'bios.bin' will be loaded as rom image.

No system flash is available.

No
Yes
-bios parameter filename will be loaded as rom image.

No system flash is available.

pflash drives

The flash image can be any drive image format supported by QEMU.

There are two ways to add the pflash drive when launching qemu-system-i386 or qemu-system-x86_64:

  1. Use the -pflash parameter
  2. Use the -drive parameter with if=pflash