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