From: OpenOCD-Gerrit <ope...@us...> - 2022-05-14 08:59:29
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 0b241ca042b1376efdcaacc52a798a20a0d9fc2a (commit) from cc75aa37c5ba6267956a3613069b7d35420b76fc (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0b241ca042b1376efdcaacc52a798a20a0d9fc2a Author: Steve Marple <ste...@go...> Date: Tue Apr 19 23:22:31 2022 +0100 bcm2835gpio: Fix incorrect GPIO validation Incorrect validation prevented GPIO0 from controlling the direction of the SWDIO buffer or operating TRST/SRST. Have all GPIO number validation checks performed by is_gpio_valid(). Change-Id: Ib8fb704ab588a618ac41c111f6168d658891d92c Signed-off-by: Steve Marple <ste...@go...> Reviewed-on: https://review.openocd.org/c/openocd/+/6938 Tested-by: jenkins Reviewed-by: Antonio Borneo <bor...@gm...> Reviewed-by: Andreas Fritiofson <and...@gm...> diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index b7a4d998c..22d237f22 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -94,6 +94,11 @@ static int speed_coeff = 113714; static int speed_offset = 28; static unsigned int jtag_delay; +static int is_gpio_valid(int gpio) +{ + return gpio >= 0 && gpio <= 31; +} + static bb_value_t bcm2835gpio_read(void) { return (GPIO_LEV & 1<<tdo_gpio) ? BB_HIGH : BB_LOW; @@ -133,12 +138,12 @@ static int bcm2835gpio_reset(int trst, int srst) uint32_t set = 0; uint32_t clear = 0; - if (trst_gpio > 0) { + if (is_gpio_valid(trst_gpio)) { set |= !trst<<trst_gpio; clear |= trst<<trst_gpio; } - if (srst_gpio > 0) { + if (is_gpio_valid(srst_gpio)) { set |= !srst<<srst_gpio; clear |= srst<<srst_gpio; } @@ -151,7 +156,7 @@ static int bcm2835gpio_reset(int trst, int srst) static void bcm2835_swdio_drive(bool is_output) { - if (swdio_dir_gpio > 0) { + if (is_gpio_valid(swdio_dir_gpio)) { if (is_output) { GPIO_SET = 1 << swdio_dir_gpio; OUT_GPIO(swdio_gpio); @@ -196,11 +201,6 @@ static int bcm2835gpio_speed(int speed) return ERROR_OK; } -static int is_gpio_valid(int gpio) -{ - return gpio >= 0 && gpio <= 31; -} - COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionums) { if (CMD_ARGC == 4) { @@ -557,7 +557,7 @@ static int bcm2835gpio_init(void) OUT_GPIO(tck_gpio); OUT_GPIO(tms_gpio); - if (trst_gpio != -1) { + if (is_gpio_valid(trst_gpio)) { trst_gpio_mode = MODE_GPIO(trst_gpio); GPIO_SET = 1 << trst_gpio; OUT_GPIO(trst_gpio); @@ -566,7 +566,7 @@ static int bcm2835gpio_init(void) if (transport_is_swd()) { /* Make buffer an output before the GPIO connected to it */ - if (swdio_dir_gpio != -1) { + if (is_gpio_valid(swdio_dir_gpio)) { swdio_dir_gpio_mode = MODE_GPIO(swdio_dir_gpio); GPIO_SET = 1 << swdio_dir_gpio; OUT_GPIO(swdio_dir_gpio); @@ -581,7 +581,7 @@ static int bcm2835gpio_init(void) OUT_GPIO(swdio_gpio); } - if (srst_gpio != -1) { + if (is_gpio_valid(srst_gpio)) { srst_gpio_mode = MODE_GPIO(srst_gpio); GPIO_SET = 1 << srst_gpio; OUT_GPIO(srst_gpio); @@ -601,7 +601,7 @@ static int bcm2835gpio_quit(void) SET_MODE_GPIO(tdi_gpio, tdi_gpio_mode); SET_MODE_GPIO(tck_gpio, tck_gpio_mode); SET_MODE_GPIO(tms_gpio, tms_gpio_mode); - if (trst_gpio != -1) + if (is_gpio_valid(trst_gpio)) SET_MODE_GPIO(trst_gpio, trst_gpio_mode); } @@ -610,10 +610,10 @@ static int bcm2835gpio_quit(void) SET_MODE_GPIO(swdio_gpio, swdio_gpio_mode); } - if (srst_gpio != -1) + if (is_gpio_valid(srst_gpio)) SET_MODE_GPIO(srst_gpio, srst_gpio_mode); - if (swdio_dir_gpio != -1) + if (is_gpio_valid(swdio_dir_gpio)) SET_MODE_GPIO(swdio_dir_gpio, swdio_dir_gpio_mode); return ERROR_OK; ----------------------------------------------------------------------- Summary of changes: src/jtag/drivers/bcm2835gpio.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) hooks/post-receive -- Main OpenOCD repository |