debugfs-design.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ========
  2. Debug FS
  3. ========
  4. .. contents::
  5. Overview
  6. --------
  7. The *DebugFS* feature is primarily aimed at exposing firmware debug data to
  8. higher SW layers such as a non-secure component. Such component can be the
  9. TFTF test payload or a Linux kernel module.
  10. Virtual filesystem
  11. ------------------
  12. The core functionality lies in a virtual file system based on a 9p file server
  13. interface (`Notes on the Plan 9 Kernel Source`_ and
  14. `Linux 9p remote filesystem protocol`_).
  15. The implementation permits exposing virtual files, firmware drivers, and file blobs.
  16. Namespace
  17. ~~~~~~~~~
  18. Two namespaces are exposed:
  19. - # is used as root for drivers (e.g. #t0 is the first uart)
  20. - / is used as root for virtual "files" (e.g. /fip, or /dev/uart)
  21. 9p interface
  22. ~~~~~~~~~~~~
  23. The associated primitives are:
  24. - Unix-like:
  25. - open(): create a file descriptor that acts as a handle to the file passed as
  26. an argument.
  27. - close(): close the file descriptor created by open().
  28. - read(): read from a file to a buffer.
  29. - write(): write from a buffer to a file.
  30. - seek(): set the file position indicator of a file descriptor either to a
  31. relative or an absolute offset.
  32. - stat(): get information about a file (type, mode, size, ...).
  33. .. code:: c
  34. int open(const char *name, int flags);
  35. int close(int fd);
  36. int read(int fd, void *buf, int n);
  37. int write(int fd, void *buf, int n);
  38. int seek(int fd, long off, int whence);
  39. int stat(char *path, dir_t *dir);
  40. - Specific primitives :
  41. - mount(): create a link between a driver and spec.
  42. - create(): create a file in a specific location.
  43. - bind(): expose the content of a directory to another directory.
  44. .. code:: c
  45. int mount(char *srv, char *mnt, char *spec);
  46. int create(const char *name, int flags);
  47. int bind(char *path, char *where);
  48. This interface is embedded into the BL31 run-time payload when selected by build
  49. options. The interface multiplexes drivers or emulated "files":
  50. - Debug data can be partitioned into different virtual files e.g. expose PMF
  51. measurements through a file, and internal firmware state counters through
  52. another file.
  53. - This permits direct access to a firmware driver, mainly for test purposes
  54. (e.g. a hardware device that may not be accessible to non-privileged/
  55. non-secure layers, or for which no support exists in the NS side).
  56. SMC interface
  57. -------------
  58. The communication with the 9p layer in BL31 is made through an SMC conduit
  59. (`SMC Calling Convention`_), using a specific SiP Function Id. An NS
  60. shared buffer is used to pass path string parameters, or e.g. to exchange
  61. data on a read operation. Refer to :ref:`ARM SiP Services <arm sip services>`
  62. for a description of the SMC interface.
  63. Security considerations
  64. -----------------------
  65. - Due to the nature of the exposed data, the feature is considered experimental
  66. and importantly **shall only be used in debug builds**.
  67. - Several primitive imply string manipulations and usage of string formats.
  68. - Special care is taken with the shared buffer to avoid TOCTOU attacks.
  69. Limitations
  70. -----------
  71. - In order to setup the shared buffer, the component consuming the interface
  72. needs to allocate a physical page frame and transmit its address.
  73. - In order to map the shared buffer, BL31 requires enabling the dynamic xlat
  74. table option.
  75. - Data exchange is limited by the shared buffer length. A large read operation
  76. might be split into multiple read operations of smaller chunks.
  77. - On concurrent access, a spinlock is implemented in the BL31 service to protect
  78. the internal work buffer, and re-entrancy into the filesystem layers.
  79. - Notice, a physical device driver if exposed by the firmware may conflict with
  80. the higher level OS if the latter implements its own driver for the same
  81. physical device.
  82. Applications
  83. ------------
  84. The SMC interface is accessible from an NS environment, that is:
  85. - a test payload, bootloader or hypervisor running at NS-EL2
  86. - a Linux kernel driver running at NS-EL1
  87. - a Linux userspace application through the kernel driver
  88. --------------
  89. *Copyright (c) 2019-2020, Arm Limited and Contributors. All rights reserved.*
  90. .. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
  91. .. _Notes on the Plan 9 Kernel Source: http://lsub.org/who/nemo/9.pdf
  92. .. _Linux 9p remote filesystem protocol: https://www.kernel.org/doc/Documentation/filesystems/9p.txt
  93. .. _ARM SiP Services: arm-sip-service.rst