[PATCH v3 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Mar 18 04:53:00 PDT 2026
Hello,
On 3/18/26 10:22, Fabian Pflug wrote:
> Going through the kernel dts and replacing
> barebox,policy-<active_policy> with default in order to change pinctrl
> not only for barebox, but also for kernel when booting with security
> profiles.
>
> Signed-off-by: Fabian Pflug <f.pflug at pengutronix.de>
> ---
> security/Makefile | 1 +
> security/kernel_pinctrl.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 57 insertions(+)
>
> diff --git a/security/Makefile b/security/Makefile
> index 1096cbfb9b..2e8cdfe7c2 100644
> --- a/security/Makefile
> +++ b/security/Makefile
> @@ -2,6 +2,7 @@
>
> obj-$(CONFIG_SECURITY_POLICY) += policy.o
> obj-$(CONFIG_SECURITY_POLICY_NAMES) += sconfig_names.o
> +obj-$(CONFIG_SECURITY_POLICY_PINCTRL) += kernel_pinctrl.o
> obj-$(CONFIG_CRYPTO_KEYSTORE) += keystore.o
> obj-$(CONFIG_JWT) += jwt.o
> obj-pbl-$(CONFIG_HAVE_OPTEE) += optee.o
> diff --git a/security/kernel_pinctrl.c b/security/kernel_pinctrl.c
> new file mode 100644
> index 0000000000..01ccac3ec3
> --- /dev/null
> +++ b/security/kernel_pinctrl.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <common.h>
> +#include <linux/printk.h>
> +#include <pinctrl.h>
> +#include <security/policy.h>
> +#include <security/config.h>
> +
> +/* Maximun number of names to be available in pinctrl-names. Best guess.*/
> +#define MAX_NAMES 10
> +
> +
> +/**
> + * Replace 'default' with 'old_default' and 'barebox,policy-<active_policy>'
> + * with 'default', if both are found in pinctrl.
> + */
> +static void kernel_of_fixup_pinctrl(struct device_node *root_node, char *policy_name)
> +{
> + struct device_node *node;
> +
> + list_for_each_entry(node, &root_node->list, list) {
I am surprised of.h didn't have a macro for that.
> + const char *names[MAX_NAMES];
> + int num_read, pos_default = -1, pos_policy = -1;
> +
> + num_read = of_property_read_string_array(node, "pinctrl-names", names, MAX_NAMES);
> +
> + for (int i = 0; i < num_read; i++) {
> + if (strcmp(policy_name, names[i]) == 0)
> + pos_policy = i;
> + if (strcmp("default", names[i]) == 0)
> + pos_default = i;
> + }
> +
> + if (pos_default >= 0 && pos_policy >= 0) {
> + names[pos_default] = "old_default";
> + names[pos_policy] = "default";
> + of_property_write_string_array(node, "pinctrl-names", names, num_read);
> + }
Wouldn't it be simpler to use of_property_for_each_string()?
> + }
> +}
> +
> +static int kernel_of_fixup_pinctrl_start(struct device_node *root, void *unused)
> +{
> + char *policy_pinctrl;
> +
> + policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
> + kernel_of_fixup_pinctrl(root, policy_pinctrl);
> + free(policy_pinctrl);
> + return 0;
> +}
What's the point of this intermediary function?
> +
> +static int policy_console_pinctrl_init(void)
> +{
> + return of_register_fixup(kernel_of_fixup_pinctrl_start, NULL);
> +}
> +late_initcall(policy_console_pinctrl_init);
>
--
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 |
More information about the barebox
mailing list