Hello Marco,

On 11/10/25 9:35 PM, Marco Felsch wrote:
> Add helpers to disable the /secure-chosen/stdout-path property from a
> FDT to keep the secure-OS silent. This is useful to keep the console on
> for development purpose and off for the release case. For the later
> case, the board code also needs to ensure that no /chosen/stdout-path
> exsits, else the secure-OS may fallback to this node.
> 
> The API is very specific to make clear that only the
> /secure-chosen/stdout-path is patched on demand.
> 
> Signed-off-by: Marco Felsch <[email protected]>
> ---
>  include/pbl.h |  4 ++++
>  pbl/console.c | 18 ++++++++++++++++++
>  pbl/fdt.c     | 26 ++++++++++++++++++++++++++
>  3 files changed, 48 insertions(+)
> 
> diff --git a/include/pbl.h b/include/pbl.h
> index 
> 0961b6b91e585a59a3e8facb1af261857cb6f57e..7e64a9d200ade522ebeb6394c730b608abc6d2bf
>  100644
> --- a/include/pbl.h
> +++ b/include/pbl.h
> @@ -17,6 +17,9 @@ extern unsigned long free_mem_end_ptr;
>  void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int 
> len);
>  int pbl_dtbz_uncompress(void *dest, void *compressed_start, unsigned long 
> len);
>  
> +void pbl_set_disable_secure_chosen_stdout(void);
> +int pbl_disable_secure_chosen_stdout(void);
> +
>  void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long 
> *memsize);
>  int fdt_fixup_mem(void *fdt, unsigned long membase[], unsigned long 
> memsize[], size_t num);
>  
> @@ -34,6 +37,7 @@ int fdt_copy_node(const void *src_fdt, void *dest_fdt, 
> const char *path,
>  int pbl_barebox_verify(const void *compressed_start, unsigned int len,
>                      const void *hash, unsigned int hash_len);
>  int pbl_load_fdt(const void *fdt, void *dest, int destsize);
> +int fdt_remove_secure_chosen_stdout(void *fdt);
>  
>  #endif
>  
> diff --git a/pbl/console.c b/pbl/console.c
> index 
> 66652320149db5cdb9d365c5b05a9ac0903935d2..b3f2ac60b5e23b487c0d098d5c2ac5c3f2c8acdc
>  100644
> --- a/pbl/console.c
> +++ b/pbl/console.c
> @@ -4,6 +4,7 @@
>  #include <debug_ll.h>
>  #include <asm/sections.h>
>  #include <linux/err.h>
> +#include <pbl.h>
>  
>  /*
>   * Put these in the data section so that they survive the clearing of the
> @@ -12,6 +13,23 @@
>  static __attribute__ ((section(".data"))) ulong putc_offset;
>  static __attribute__ ((section(".data"))) void *putc_ctx;
>  
> +/*
> + * No special segment handling required, since the value doesn't need to 
> survive.
> + * The secure-os is loaded only once very early. Therefore this variable is
> + * checked only once too.
> + */
> +static int disable_secure_chosen_stdout;
> +
> +void pbl_set_disable_secure_chosen_stdout(void)
> +{
> +     disable_secure_chosen_stdout = 1;
> +}
> +
> +int pbl_disable_secure_chosen_stdout(void)
> +{
> +     return disable_secure_chosen_stdout;
> +}

What are these for? fdt_remove_secure_chosen_stdout() uses none of the
three symbols defined above.

> +
>  /**
>   * pbl_set_putc() - setup UART used for PBL console
>   * @putc: The putc function.
> diff --git a/pbl/fdt.c b/pbl/fdt.c
> index 
> fa61c3c71298a2e036e0d324c09d452d8f0f7bbe..d8160e4a09867aab91dc89de5dc7b00dd08a4155
>  100644
> --- a/pbl/fdt.c
> +++ b/pbl/fdt.c
> @@ -342,3 +342,29 @@ int fdt_copy_node(const void *src_fdt, void *dest_fdt, 
> const char *path,
>  
>       return _fdt_copy_node(src_fdt, src_node, dest_fdt, dest_node);
>  }
> +
> +int fdt_remove_secure_chosen_stdout(void *fdt)
> +{
> +     int sec_chosen;
> +     int ret;
> +
> +     if (!fdt)
> +             return 0;
> +
> +     sec_chosen = fdt_path_offset(fdt, "/secure-chosen");
> +     /* No secure-chosen node found, nothing to do */
> +     if (sec_chosen < 0)
> +             return 0;
> +
> +     ret = fdt_delprop(fdt, sec_chosen, "stdout-path");
> +     if (ret) {
> +             if (ret == -FDT_ERR_NOTFOUND)
> +                     return 0;
> +
> +             pr_warn("Failed to delete /secure-chosen/stdout-path with:%s\n",
> +                     fdt_strerror(ret));
> +             return -EINVAL;
> +     }
> +
> +     return 0;
> +}
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |


Reply via email to