Skip to content

sd: Add RPMB emulation to eMMC model

Jan Kiszka qemu-devel 6 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest6 patches 16 repliesIn review
  2. v56 patches 23 repliesSuperseded
  3. v46 patches 14 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v36 patches4 repliesSuperseded
v28 patches36 repliesSuperseded
v18 patches18 repliesSuperseded

Changes in v5 from the cover letter

- fix regression of patch 1 with unplugged SD cards
- address review comments on documentation

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6hw/sd/sdcard: Fix size check for backing block imagehw/sd/sd.c+48 -212 replies
2/6hw/sd/sdcard: Allow user-instantiated eMMChw/sd/sd.c+0 -20 replies
3/6hw/sd/sdcard: Add basic support for RPMB partitionhw/sd/sd.c hw/sd/sdmmc-internal.h hw/sd/trace-events+233 -81 reply
4/6hw/sd/sdcard: Handle RPMB MAC fieldhw/sd/sd.c+83 -01 reply
5/6scripts: Add helper script to generate eMMC block device imagesscripts/mkemmc.sh+219 -00 replies
5/6scripts: Add helper script to generate eMMC block device imagesscripts/mkemmc.sh+219 -06 replies
6/6docs: Add eMMC device model descriptiondocs/system/device-emulation.rst docs/system/devices/emmc.rst+54 -02 replies

Reviews trailers per patch

6 of 7 patches have a Reviewed-by or Acked-by.

PatchAlex BennéePhilippe Mathieu-DaudéCédric Le GoaterWarner LoshIlias Apalodimas
SeriesT-b T-b
1/6R-b R-b R-b
2/6
3/6R-b
4/6R-b
5/6R-b T-b
5/6R-b T-b
6/6R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v6 thread

Cover letter [PATCH v6 0/6] sd: Add RPMB emulation to eMMC model

Changes in v6 [1]:
- incorporated review suggestions, specifically
- style and structuring suggestion for sd.c changes
- usage of lduw_be_p, ldl_be_p, stw_be_p, stl_be_p
- usage of QEMU_IS_ALIGNED
- optimized rpmb_calc_hmac
- introduction of further RPMB_*_LEN constants
- truncate argument ordering in mkemmc.sh
- comment for unclear code in mkemmc.sh
- improvide description of patch 2
- rebased over master + [2]

Changes in v5:
- fix regression of patch 1 with unplugged SD cards
- address review comments on documentation

Changes in v4:
- add truncation warning to mkemmc.sh
- fix typos in doc and mkemmc.sh

Changes in v3:
- rebased, dropping merged patches
- rework image alignment rules to match hardware
- improve/fix mkemmc script
- add emmc documentation

Changes in v2:
- handle write counter expiry
- assert() availability of QCRYPTO_HASH_ALGO_SHA256
- add missing SPDX-License-Identifier

This closes an old gap in system integration testing for the very complex ARM firmware stacks by adding fairly advanced Replay Protected Memory Block (RPMB) emulation to the eMMC device model. Key programming and message authentication are working, so is the write counter. Known users are happy with the result. What is missing, but not only for RPMB- related registers, is state persistence across QEMU restarts. This is OK at this stage for most test scenarios, though, and could still be added later on.

What can already be done with it is demonstrated in the WIP branch of isar-cip-core at [3]: TF-A + OP-TEE + StandaloneMM TA + fTPM TA, used by U-Boot and Linux for UEFI variable storage and TPM scenarios. If you want to try: build qemu-arm64 target for trixie with 6.12-cip *head* kernel, enable secure boot and disk encryption, then run

$ QEMU_PATH=/path/to/qemu-build/ ./start-qemu.sh

Deploy snakeoil keys into PK, KEK and db after first boot to enable secure booting:

root@demo:~# cert-to-efi-sig-list PkKek-1-snakeoil.pem PK.esl
root@demo:~# sign-efi-sig-list -k PkKek-1-snakeoil.key -c PkKek-1-snakeoil.pem PK PK.esl PK.auth
root@demo:~# efi-updatevar -f PK.auth db
root@demo:~# efi-updatevar -f PK.auth KEK
root@demo:~# efi-updatevar -f PK.auth PK

Note that emulation is a bit slow in general, and specifically the partition encryption on first boot is taking 20 min. - we should probably reduce its size or understand if there is still something to optimize.

Jan

[1] https://github.com/siemens/qemu/commits/queues/emmc/
[2] https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
[3] https://gitlab.com/cip-project/cip-core/isar-cip-core/-/commits/next

CC Alexander Bulekov <[email protected]>
CC Alistair Francis <[email protected]>
CC Cédric Le Goater <[email protected]>
CC Joel Stanley <[email protected]>
CC Warner Losh <[email protected]>

Jan Kiszka (6):
hw/sd/sdcard: Fix size check for backing block image hw/sd/sdcard: Allow user-instantiated eMMC hw/sd/sdcard: Add basic support for RPMB partition hw/sd/sdcard: Handle RPMB MAC field
scripts: Add helper script to generate eMMC block device images
docs: Add eMMC device model description

 docs/system/device-emulation.rst |   1 +
 docs/system/devices/emmc.rst     |  53 +++++
 hw/sd/sd.c                       | 369 ++++++++++++++++++++++++++++---
 hw/sd/sdmmc-internal.h           |  22 ++
 hw/sd/trace-events               |   2 +
 scripts/mkemmc.sh                | 219 ++++++++++++++++++
 6 files changed, 636 insertions(+), 30 deletions(-)
 create mode 100644 docs/system/devices/emmc.rst
 create mode 100755 scripts/mkemmc.sh
Signature · 1 line
2.51.0