From 8b945c15504cfc91c8e88b7219167533cdef87db Mon Sep 17 00:00:00 2001 From: Balaji Prakash J Date: Thu, 14 Nov 2019 11:27:03 +0530 Subject: [PATCH] ipq: fdt_fixup: Add support to change dts params using env The env name should "fdtedit" followed by number from 0. example: fdtedit0, fdtedit1, fdtedit2, ... Set the number of envs to parse, "setenv fdteditnum " can be between 1 to 99. eg: "setenv fdteditnum 5" Without setting 'fdteditnum' fdtedit envs will not parsed. To change add/change a particular property of a node: setenv fdtedit0 %% example: fdtedit0=/soc/qca,scm_restart_reason%qca,coldreboot-enabled%1 fdtedit1=/soc/usb3@8A00000/dwc3@8A00000%dr_mode%?peripheral To delete a property of a node: setenv fdtedit0 %delete% example: fdtedit2=/soc/q6v5_wcss@CD00000%delete%?qca,secure The last param in both case, if it is a string, it should start with '?' else if it is a number, it can be put directly. check above examples for reference. Change-Id: Ib22ec8098925b49b013bc115f11e043bf8ab3ef5 Signed-off-by: Balaji Prakash J --- board/qca/arm/common/fdt_fixup.c | 93 ++++++++++++++++++++++++++++++++ include/common.h | 2 + include/configs/ipq6018.h | 1 + 3 files changed, 96 insertions(+) diff --git a/board/qca/arm/common/fdt_fixup.c b/board/qca/arm/common/fdt_fixup.c index 2c7000031b..1ee06667dc 100644 --- a/board/qca/arm/common/fdt_fixup.c +++ b/board/qca/arm/common/fdt_fixup.c @@ -19,6 +19,11 @@ DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_IPQ_FDT_FIXUP +#define FDT_EDIT "fdtedit" +/* Buffer size to hold numbers from 0-99 + 1 NULL character */ +#define NUM_BUF_SIZE 3 +#endif /* * Don't have this as a '.bss' variable. The '.bss' and '.rel.dyn' * sections seem to overlap. @@ -481,6 +486,91 @@ static int ipq40xx_patch_eth_params(void *blob, unsigned long gmac_no) return 0; } +#ifdef CONFIG_IPQ_FDT_FIXUP +void parse_fdt_fixup(char* buf, void *blob) +{ + int nodeoff, value, ret; + char *node, *property, *node_value; + bool str = true; + + node = strsep(&buf, "%"); + property = strsep(&buf, "%"); + node_value = strsep(&buf, "%"); + + debug("node: %s, property: %s, node_value: %s\n", + node, property, node_value); + + if (node_value && node_value[0] != '?') { + str = false; + value = simple_strtoul(node_value, NULL, 10); + } else { + node_value++; + } + + nodeoff = fdt_path_offset(blob, node); + if (nodeoff < 0) { + printf("%s: unable to find node '%s'\n", + __func__, node); + return; + } + + if (!strncmp(property, "delete", strlen("delete"))) { + ret = fdt_delprop(blob, nodeoff, node_value); + if (ret) { + printf("%s: unable to delete %s\n", + __func__, node_value); + return; + } + } else if (!str) { + ret = fdt_setprop_u32(blob, nodeoff, property, + value); + if (ret) { + printf("%s: failed to set prop %s\n", + __func__, property); + return; + } + } else { + ret = fdt_setprop(blob, nodeoff, property, + node_value, + (strlen(node_value) + 1)); + if (ret) { + printf("%s: failed to set prop %s\n", + __func__, property); + return; + } + } +} + +void ipq_fdt_fixup(void *blob) +{ + int i, fdteditnum; + char buf[sizeof(FDT_EDIT) + NUM_BUF_SIZE], num[NUM_BUF_SIZE]; + char *s; + + /* fdteditnum - defines the number of envs to parse + * starting from 0. eg: fdtedit0, fdtedit1, and so on. + */ + s = getenv("fdteditnum"); + if (s) + fdteditnum = simple_strtoul(s, NULL, 10); + else + return; + + printf("%s: fixup fdtedits\n", __func__); + + for (i = 0; i <= fdteditnum; i++) { + /* Generate env names fdtedit0, fdtedit1,..fdteditn */ + strlcpy(buf, FDT_EDIT, sizeof(buf)); + snprintf(num, sizeof(num), "%d", i); + strlcat(buf, num, sizeof(buf)); + + s = getenv(buf); + if (s) + parse_fdt_fixup(s, blob); + } +} +#endif + __weak void fdt_fixup_sd_ldo_gpios_toggle(void *blob) { return; @@ -616,6 +706,9 @@ int ft_board_setup(void *blob, bd_t *bd) ipq40xx_patch_eth_params(blob, gmac_no); } dcache_disable(); +#ifdef CONFIG_IPQ_FDT_FIXUP + ipq_fdt_fixup(blob); +#endif fdt_fixup_ethernet(blob); ipq_fdt_fixup_usb_device_mode(blob); fdt_fixup_auto_restart(blob); diff --git a/include/common.h b/include/common.h index 10ef43aa88..0fe5ffc595 100644 --- a/include/common.h +++ b/include/common.h @@ -359,6 +359,8 @@ void board_show_dram(phys_size_t size); */ int arch_fixup_fdt(void *blob); +void parse_fdt_fixup(char* buf, void *blob); + /* common/flash.c */ void flash_perror (int); diff --git a/include/configs/ipq6018.h b/include/configs/ipq6018.h index 75e230d072..5d9263ec7e 100644 --- a/include/configs/ipq6018.h +++ b/include/configs/ipq6018.h @@ -362,5 +362,6 @@ extern loff_t board_env_size; #define CONFIG_IPQ_ELF_AUTH #define IPQ_UBI_VOL_WRITE_SUPPORT #define CONFIG_IPQ_TZT +#define CONFIG_IPQ_FDT_FIXUP #endif /* _IPQ6018_H */