From: OpenOCD-Gerrit <ope...@us...> - 2021-08-14 12:30:55
|
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 08a0cfdeebbad10a33a6a5bc25d468ebd3ab6119 (commit) via 9544cd653df120266582f69bddc77d32541caae7 (commit) from 41efc6c419cf5c63a1f555dc5b7634a2e18d9c04 (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 08a0cfdeebbad10a33a6a5bc25d468ebd3ab6119 Author: Antonio Borneo <bor...@gm...> Date: Fri May 14 00:48:31 2021 +0200 helper/align.h: use it Use the new helper to make the code more readable. Change-Id: I11b2a79dbc6f93f6cfde382bcc00dd7ff710d908 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6375 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tar...@gm...> diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index d70895c53..e6d3a8350 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -24,6 +24,7 @@ #endif #include "imp.h" +#include <helper/align.h> #include <helper/binarybuffer.h> #include <target/algorithm.h> #include <target/armv7m.h> @@ -1591,7 +1592,7 @@ static int stm32l4_probe(struct flash_bank *bank) * max_flash_size is always power of two, so max_pages too */ uint32_t max_pages = stm32l4_info->part_info->max_flash_size_kb / page_size_kb; - assert((max_pages & (max_pages - 1)) == 0); + assert(IS_PWR_OF_2(max_pages)); /* in dual bank mode number of pages is doubled, but extra bit is bank selection */ stm32l4_info->wrpxxr_mask = ((max_pages >> (stm32l4_info->dual_bank_mode ? 1 : 0)) - 1); diff --git a/src/flash/nor/xmc1xxx.c b/src/flash/nor/xmc1xxx.c index 11542ac5b..a519ab864 100644 --- a/src/flash/nor/xmc1xxx.c +++ b/src/flash/nor/xmc1xxx.c @@ -11,6 +11,7 @@ #endif #include "imp.h" +#include <helper/align.h> #include <helper/binarybuffer.h> #include <target/algorithm.h> #include <target/armv7m.h> @@ -256,12 +257,12 @@ static int xmc1xxx_write(struct flash_bank *bank, const uint8_t *buffer, LOG_DEBUG("Infineon XMC1000 write at 0x%08" PRIx32 " (%" PRIu32 " bytes)", offset, byte_count); - if (offset & (NVM_BLOCK_SIZE - 1)) { + if (!IS_ALIGNED(offset, NVM_BLOCK_SIZE)) { LOG_ERROR("offset 0x%" PRIx32 " breaks required block alignment", offset); return ERROR_FLASH_DST_BREAKS_ALIGNMENT; } - if (byte_count & (NVM_BLOCK_SIZE - 1)) { + if (!IS_ALIGNED(byte_count, NVM_BLOCK_SIZE)) { LOG_WARNING("length %" PRIu32 " is not block aligned, rounding up", byte_count); } diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 4a8cfcd4b..923cdf877 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -68,6 +68,7 @@ #include "config.h" #endif +#include <helper/align.h> #include <helper/time_support.h> #include "mips32.h" @@ -658,7 +659,7 @@ static int mips32_pracc_synchronize_cache(struct mips_ejtag *ejtag_info, goto exit; /* Nothing to do */ /* make sure clsiz is power of 2 */ - if (clsiz & (clsiz - 1)) { + if (!IS_PWR_OF_2(clsiz)) { LOG_DEBUG("clsiz must be power of 2"); ctx.retval = ERROR_FAIL; goto exit; diff --git a/src/target/target.c b/src/target/target.c index a67712009..7bace83f9 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -41,6 +41,7 @@ #include "config.h" #endif +#include <helper/align.h> #include <helper/time_support.h> #include <jtag/jtag.h> #include <flash/nor/core.h> @@ -1004,7 +1005,7 @@ int target_run_flash_async_algorithm(struct target *target, uint32_t rp = fifo_start_addr; /* validate block_size is 2^n */ - assert(!block_size || !(block_size & (block_size - 1))); + assert(IS_PWR_OF_2(block_size)); retval = target_write_u32(target, wp_addr, wp); if (retval != ERROR_OK) @@ -1042,7 +1043,7 @@ int target_run_flash_async_algorithm(struct target *target, break; } - if (((rp - fifo_start_addr) & (block_size - 1)) || rp < fifo_start_addr || rp >= fifo_end_addr) { + if (!IS_ALIGNED(rp - fifo_start_addr, block_size) || rp < fifo_start_addr || rp >= fifo_end_addr) { LOG_ERROR("corrupted fifo read pointer 0x%" PRIx32, rp); break; } @@ -1157,7 +1158,7 @@ int target_run_read_async_algorithm(struct target *target, uint32_t rp = fifo_start_addr; /* validate block_size is 2^n */ - assert(!block_size || !(block_size & (block_size - 1))); + assert(IS_PWR_OF_2(block_size)); retval = target_write_u32(target, wp_addr, wp); if (retval != ERROR_OK) @@ -1194,7 +1195,7 @@ int target_run_read_async_algorithm(struct target *target, break; } - if (((wp - fifo_start_addr) & (block_size - 1)) || wp < fifo_start_addr || wp >= fifo_end_addr) { + if (!IS_ALIGNED(wp - fifo_start_addr, block_size) || wp < fifo_start_addr || wp >= fifo_end_addr) { LOG_ERROR("corrupted fifo write pointer 0x%" PRIx32, wp); break; } commit 9544cd653df120266582f69bddc77d32541caae7 Author: Antonio Borneo <bor...@gm...> Date: Thu May 13 19:07:50 2021 +0200 helper: add align.h OpenOCD has to often align values or check for alignment. Use a dedicated set of macros instead of reinventing the wheel each time. Change-Id: Ia58711608aae0801deeaccb5f33148f2073b0bbd Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6374 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tar...@gm...> diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am index bedc9f707..42cee80d3 100644 --- a/src/helper/Makefile.am +++ b/src/helper/Makefile.am @@ -15,6 +15,7 @@ noinst_LTLIBRARIES += %D%/libhelper.la %D%/util.c \ %D%/jep106.c \ %D%/jim-nvp.c \ + %D%/align.h \ %D%/binarybuffer.h \ %D%/bits.h \ %D%/configuration.h \ diff --git a/src/helper/align.h b/src/helper/align.h new file mode 100644 index 000000000..935a6a3b2 --- /dev/null +++ b/src/helper/align.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * The content of this file is mainly copied/inspired from Linux kernel + * code in include/linux/align.h and include/uapi/linux/const.h + * + * Macro name 'ALIGN' conflicts with macOS/BSD file param.h + */ + +#ifndef OPENOCD_HELPER_ALIGN_H +#define OPENOCD_HELPER_ALIGN_H + +#define ALIGN_MASK(x, mask) \ +({ \ + typeof(mask) _mask = (mask); \ + ((x) + _mask) & ~_mask; \ +}) + +/* @a is a power of 2 value */ +#define ALIGN_UP(x, a) ALIGN_MASK(x, (typeof(x))(a) - 1) +#define ALIGN_DOWN(x, a) ((x) & ~((typeof(x))(a) - 1)) +#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +#define IS_PWR_OF_2(x) \ +({ \ + typeof(x) _x = (x); \ + _x == 0 || (_x & (_x - 1)) == 0; \ +}) + +#endif /* OPENOCD_HELPER_ALIGN_H */ ----------------------------------------------------------------------- Summary of changes: src/flash/nor/stm32l4x.c | 3 ++- src/flash/nor/xmc1xxx.c | 5 +++-- src/helper/Makefile.am | 1 + src/helper/align.h | 30 ++++++++++++++++++++++++++++++ src/target/mips32_pracc.c | 3 ++- src/target/target.c | 9 +++++---- 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 src/helper/align.h hooks/post-receive -- Main OpenOCD repository |