This is an automated email from Gerrit. Svetoslav Enchev (svetoslav.enc...@gmail.com) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/4636
-- gerrit commit b6b9f5401b63c3decab971979c2e810f54e40f23 Author: Svetoslav Enchev <svetoslav.enc...@gmail.com> Date: Sun Aug 5 13:18:04 2018 +0300 flash/at91sam4: fix getting sector protection bits Fix bug where 4*32 lock bits were always read. Fix bug where only the last 32-bit block was used as the value for the first block, and other blocks were ignored. Also add support for possible banks with more than 128 lock regions. Change-Id: I5af5b9f2f4036f64508c7a20cf7de6c75d382c6f Signed-off-by: Svetoslav Enchev <svetoslav.enc...@gmail.com> diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index c5b31e9..f6c84f7 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -1791,20 +1791,21 @@ static int FLASHD_SetGPNVM(struct sam4_bank_private *pPrivate, unsigned gpnvm) } /** - * Returns a bit field (at most 64) of locked regions within a page. + * Returns a bit field of locked regions within a bank. * @param pPrivate info about the bank * @param v where to store locked bits + * @param num_lock_bits number of locked regions */ -static int FLASHD_GetLockBits(struct sam4_bank_private *pPrivate, uint32_t *v) +static int FLASHD_GetLockBits(struct sam4_bank_private *pPrivate, uint32_t *v, unsigned num_lock_bits) { int r; + unsigned lock_bits_fetched = 0; LOG_DEBUG("Here"); r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL); - if (r == ERROR_OK) { - EFC_GetResult(pPrivate, v); - EFC_GetResult(pPrivate, v); - EFC_GetResult(pPrivate, v); - r = EFC_GetResult(pPrivate, v); + while (r == ERROR_OK && lock_bits_fetched < num_lock_bits) { + r = EFC_GetResult(pPrivate, v); + v++; + lock_bits_fetched += 32; } LOG_DEBUG("End: %d", r); return r; @@ -2411,6 +2412,8 @@ static int sam4_protect_check(struct flash_bank *bank) { int r; uint32_t v[4] = {0}; + uint32_t *lock_bits; + unsigned num_lock_regions; unsigned x; struct sam4_bank_private *pPrivate; @@ -2428,14 +2431,24 @@ static int sam4_protect_check(struct flash_bank *bank) if (!(pPrivate->probed)) return ERROR_FLASH_BANK_NOT_PROBED; - r = FLASHD_GetLockBits(pPrivate, v); - if (r != ERROR_OK) { - LOG_DEBUG("Failed: %d", r); - return r; - } - - for (x = 0; x < pPrivate->nsectors; x++) + num_lock_regions = pPrivate->nsectors; + if (num_lock_regions > 4*32) + lock_bits = calloc(num_lock_regions/32, sizeof(uint32_t)); + else + lock_bits = v; + + r = FLASHD_GetLockBits(pPrivate, lock_bits, num_lock_regions); + if (r != ERROR_OK) { + LOG_DEBUG("Failed: %d", r); + return r; + } + + for (x = 0; x < num_lock_regions; x++) bank->sectors[x].is_protected = (!!(v[x >> 5] & (1 << (x % 32)))); + + if (lock_bits != v) + free(lock_bits); + LOG_DEBUG("Done"); return ERROR_OK; } -- ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ OpenOCD-devel mailing list OpenOCD-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openocd-devel