Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup console from Device Tree #1388

Closed
wants to merge 23 commits into from
Closed

Conversation

jforissier
Copy link
Contributor

@jforissier jforissier commented Mar 3, 2017

This is a rework of my older proof-of-concept code to use DT in OP-TEE to configure devices etc., similar to what the Linux kernel is doing. The series can be divided in two parts:

  • Patches 1 ("serial.h: add missing #include <stdbool.h>) through 12 (" core: add common implementation for console_putc() and console_flush()") rework the UART drivers in order to use the previously introduced struct serial_chip and struct serial_ops. The console initialization code is updated accordingly. Update: moved to Serial drivers rework #1393.
  • Patches 13 (" core: introduce struct dt_driver") to 19 ("core: arm: generic boot: dt: switch console to /secure-chosen/stdout-path") add a framework for DT-compatible drivers and use it to setup the console from information retrieved from the DT.

Tested on QEMU with manual modifications to the emulator itself to alter the DT:

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index a193b5a..8817431 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -627,6 +627,9 @@ static void create_uart(const VirtBoardInfo *vbi, qemu_irq *pic, int uart,
         /* Mark as not usable by the normal world */
         qemu_fdt_setprop_string(vbi->fdt, nodename, "status", "disabled");
         qemu_fdt_setprop_string(vbi->fdt, nodename, "secure-status", "okay");
+       /* Select as default console for secure world */
+       qemu_fdt_add_subnode(vbi->fdt, "/secure-chosen");
+       qemu_fdt_setprop_string(vbi->fdt, "/secure-chosen", "stdout-path", nodename);
     }

With this, the console remains on the secure UART (/pl011@9040000). When the property's value is forced to "/pl011@9000000" instead, the console is switched to the Non-Secure UART. Finally, if the /secure-chose node is left empty, the console is disabled.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Prepare for reworking the UART drivers to adopt the usual model where
a device is represented by a structure holding private data (base
address for instance) and a generic part (struct serial_chip).

The console output functions may be used by early init code before the
MMU has been turned on. Therefore, the serial drivers need a way to
access the UART using either a physical or a virtual address. But,
only the platform code knows how to translate the physical address to
a virtual one (it knows the memory type to use in the phys_to_virt()
call). So, this commit gives the platform code the opportunity to
update the driver's private data for the console, by calling
console_init() twice: once before the MMU is turned on, and once
after. A call to console_flush() just before MMU enablement
ensures that no pending data are lost.

The conversion of the UART drivers will be done in later commits.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Since most platforms now use the same console_putc() and
console_flush(), move them to core/kernel/console.c. Make them __weak
so that platforms may still provide their own.
The common code expects the platforms to initialize whatever serial
device from console_init() and set the serial_console pointer.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
When CFG_DT=y, a linker section is created (.rodata.dtdrv) to hold all
the DT-compatible drivers. The table can later be queried at runtime.
Some manipulation functions are exported in <kernel/dt.h>.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Use the functions provided by libfdt instead of our own.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Maps a device into memory from its FDT node.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Add struct serial_driver which will be useful to UART drivers that
want to create devices from a DT node.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
…path

If CFG_DT=y, check the Device Tree's /secure-chosen node and look for
the stdout-path property. Adjust the console output accordingly.
The DT bindings for this property have been proposed on the LKML [1].

[1] https://www.spinics.net/lists/arm-kernel/msg566034.html

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU)
…n/stdout-path

Allow NULL DT.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Avoid extern in .c file

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Fix typo

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Fix typo

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
@MrVan
Copy link
Contributor

MrVan commented Mar 10, 2017

@jforissier Just wonder is there helper functions that driver can be probed by using dts? There are too many CFG_xx in my code. I would like to use dts to differentiate, optee shmem/tee ram for different platforms. Also dtb is only used in init_fdt(fdt);, I would like to let platform code/ driver code could also access device tree. Do you have plan to add the support?

@etienne-lms
Copy link
Contributor

I agree that DT could be quite useful to many platforms, to reduce some static configuration directive. Be careful that some settings may not be easily portable into the DT. TEE RAM is an example since the OP-TEE core shall be built for the exact physical location we expect it to be loaded/executed.

I also agree the DT parsing support should exit the generic_boot.c and be made available for drivers and platforms. Also, after talking about DT those last days, I believe there will likely be different needs and strategy regarding for each of the different platform. Hence, CFG_DT should only enable integration of the DT parsing/overwritting support, leaving to each platform to decide how they read/write the DTB. I have no idea of how to implement that, but we should think about it.

@jforissier, in the mean time, i feel your change can continue to be reviewed (and merged once agreed) since it still proposed interesting use of the DTB in OP-TEE. Bringing more flexibility into DT use can more later on.

@jforissier
Copy link
Contributor Author

Superseded by #1433.

@jforissier jforissier closed this Mar 21, 2017
@jforissier jforissier deleted the dt2 branch November 13, 2018 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants