From a48d6c2615266ee3151769f494552de547a33be6 Mon Sep 17 00:00:00 2001 From: Rajkumar Ayyasamy Date: Fri, 24 Sep 2021 16:50:31 +0530 Subject: [PATCH 1/2] lib: fdt: use ULONG_MAX for boundary checks We are typecasting the fdt_start and other parameters to unit64_t. So ULONG_MAX should be used for the boundary check. Signed-off-by: Rajkumar Ayyasamy Change-Id: I42b4c0cb05902410c4e18553017c016bdd312207 --- lib/libfdt/fdt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libfdt/fdt.c b/lib/libfdt/fdt.c index 673bab44e6..b548d5cf05 100644 --- a/lib/libfdt/fdt.c +++ b/lib/libfdt/fdt.c @@ -14,7 +14,7 @@ #include "libfdt_internal.h" -#define UINT_MAX (~0U) +#define ULONG_MAX (~0UL) int fdt_check_header(const void *fdt) { @@ -41,13 +41,13 @@ int fdt_check_header(const void *fdt) } fdt_end = fdt_start + fdt_totalsize(fdt); - if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_struct(fdt) + (uint64_t)fdt_size_dt_struct(fdt)) > UINT_MAX) + if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_struct(fdt) + (uint64_t)fdt_size_dt_struct(fdt)) > ULONG_MAX) return FDT_ERR_BADOFFSET; if ((fdt_start + fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt)) > fdt_end) return FDT_ERR_BADOFFSET; - if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_strings(fdt) + (uint64_t)fdt_size_dt_strings(fdt)) > UINT_MAX) + if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_strings(fdt) + (uint64_t)fdt_size_dt_strings(fdt)) > ULONG_MAX) return FDT_ERR_BADOFFSET; if ((fdt_start + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)) > fdt_end) From 63c2c3a2c5039801440f9cea860a89a53b5015b9 Mon Sep 17 00:00:00 2001 From: Karthick Shanmugham Date: Tue, 21 Sep 2021 13:38:02 +0530 Subject: [PATCH 2/2] ipq: Indicate SDx when host resets Change-Id: I202725bffe1ecbdf69aeac4d99a6b6a010f6cbce Signed-off-by: Karthick Shanmugham --- arch/arm/dts/ipq5018-mp03.6-c1.dts | 5 ++++ arch/arm/dts/ipq807x-hk01-c5.dts | 4 +++ board/qca/arm/ipq5018/ipq5018.c | 34 ++++++++++++++++++++++++++ board/qca/arm/ipq807x/ipq807x.c | 39 ++++++++++++++++++++++++++++++ common/autoboot.c | 3 +++ 5 files changed, 85 insertions(+) diff --git a/arch/arm/dts/ipq5018-mp03.6-c1.dts b/arch/arm/dts/ipq5018-mp03.6-c1.dts index 03456de139..61a3e28efd 100644 --- a/arch/arm/dts/ipq5018-mp03.6-c1.dts +++ b/arch/arm/dts/ipq5018-mp03.6-c1.dts @@ -157,4 +157,9 @@ }; + sdx-gpio { + ap2mdm = <25>; + }; + + }; diff --git a/arch/arm/dts/ipq807x-hk01-c5.dts b/arch/arm/dts/ipq807x-hk01-c5.dts index a63ede27c1..a6d1234959 100644 --- a/arch/arm/dts/ipq807x-hk01-c5.dts +++ b/arch/arm/dts/ipq807x-hk01-c5.dts @@ -31,6 +31,10 @@ aquantia_port = <5>; aquantia_gpio = <44>; }; + sdx-gpio { + x55-ap2mdm = <26>; + x65-ap2mdm = <45>; + }; }; diff --git a/board/qca/arm/ipq5018/ipq5018.c b/board/qca/arm/ipq5018/ipq5018.c index 01b4d44498..1807833910 100644 --- a/board/qca/arm/ipq5018/ipq5018.c +++ b/board/qca/arm/ipq5018/ipq5018.c @@ -160,6 +160,40 @@ void uart1_set_rate_mnd(unsigned int m, writel(two_d, GCC_BLSP1_UART1_APPS_D); } +int get_ap2mdm_gpio(void) +{ + int ap2mdm_gpio = -1, node; + + node = fdt_path_offset(gd->fdt_blob, "/sdx-gpio"); + if (node >= 0) { + ap2mdm_gpio = fdtdec_get_uint(gd->fdt_blob, node, "ap2mdm", -1); + } else + return node; + + return ap2mdm_gpio; +} + +void indicate_sdx_device(void) +{ + int ap2mdm_gpio; + unsigned int *ap2mdm_gpio_base; + + unsigned int machid = gd->bd->bi_arch_number; + if (machid != 0x8040003) + return; + + ap2mdm_gpio = get_ap2mdm_gpio(); + if(ap2mdm_gpio >= 0) { + /* Enabling OE in gpio cfg reg */ + ap2mdm_gpio_base = (unsigned int *)GPIO_CONFIG_ADDR(ap2mdm_gpio); + writel(0x2c0, ap2mdm_gpio_base); + /* Indicate SDx by writing low to ap2mdm */ + gpio_set_value(ap2mdm_gpio, 0x1); + gpio_set_value(ap2mdm_gpio, 0x0); + } + +} + void reset_board(void) { run_command("reset", 0); diff --git a/board/qca/arm/ipq807x/ipq807x.c b/board/qca/arm/ipq807x/ipq807x.c index da5b2e62cb..4d398bad9f 100644 --- a/board/qca/arm/ipq807x/ipq807x.c +++ b/board/qca/arm/ipq807x/ipq807x.c @@ -430,6 +430,45 @@ void reset_cpu(unsigned long a) while(1); } + +int sdx65_attached(void); + +int get_ap2mdm_gpio(void) +{ + int ap2mdm_gpio = -1, node; + + node = fdt_path_offset(gd->fdt_blob, "/sdx-gpio"); + if (node >= 0) { + if(sdx65_attached()) + ap2mdm_gpio = fdtdec_get_uint(gd->fdt_blob, node, "x65-ap2mdm", -1); + else + ap2mdm_gpio = fdtdec_get_uint(gd->fdt_blob, node, "x55-ap2mdm", -1); + } else + return node; + + return ap2mdm_gpio; +} + +void indicate_sdx_device(void) +{ + int ap2mdm_gpio; + unsigned int *ap2mdm_gpio_base; + + unsigned int machid = gd->bd->bi_arch_number; + if (machid != 0x08010400) + return; + + ap2mdm_gpio = get_ap2mdm_gpio(); + if(ap2mdm_gpio >= 0) { + /* Enabling OE in gpio cfg reg */ + ap2mdm_gpio_base = (unsigned int *)GPIO_CONFIG_ADDR(ap2mdm_gpio); + writel(0x2c0, ap2mdm_gpio_base); + /* Indicate SDx by writing low to ap2mdm */ + gpio_set_value(ap2mdm_gpio, 0x0); + } + +} + void reset_board(void) { run_command("reset", 0); diff --git a/common/autoboot.c b/common/autoboot.c index 48b06063ab..96d2a841cc 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -366,6 +366,8 @@ __weak int apps_iscrashed_crashdump_disabled(void) return 0; } +__weak void indicate_sdx_device(void) {} + void autoboot_command(const char *s) { debug("### main_loop: bootcmd=\"%s\"\n", s ? s : ""); @@ -377,6 +379,7 @@ void autoboot_command(const char *s) */ if (apps_iscrashed()) { printf("Crashdump magic found, initializing dump activity..\n"); + indicate_sdx_device(); s = getenv("dump_to_flash"); if (!s) { s = getenv("dump_minimal");