X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fkinetis_ke.c;h=fe207286547fc21c731352584a9dd7ab6197b1df;hp=0d094b5f9eec5500e4aa9439ab313c11aa1e63e5;hb=HEAD;hpb=64c2e03b23d9cadc1b919d38e902a079d015ddc6 diff --git a/src/flash/nor/kinetis_ke.c b/src/flash/nor/kinetis_ke.c index 0d094b5f9e..c069f3ac89 100644 --- a/src/flash/nor/kinetis_ke.c +++ b/src/flash/nor/kinetis_ke.c @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + /*************************************************************************** * Copyright (C) 2015 by Ivan Meleca * * ivan@artekit.eu * @@ -18,19 +20,6 @@ * * * Copyright (C) 2015 Tomas Vanek * * vanekt@fbl.cz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -41,6 +30,7 @@ #include "imp.h" #include #include +#include #include #include @@ -146,16 +136,23 @@ struct kinetis_ke_flash_bank { static int kinetis_ke_mdm_write_register(struct adiv5_dap *dap, unsigned reg, uint32_t value) { - int retval; LOG_DEBUG("MDM_REG[0x%02x] <- %08" PRIX32, reg, value); - retval = dap_queue_ap_write(dap_ap(dap, 1), reg, value); + struct adiv5_ap *ap = dap_get_ap(dap, 1); + if (!ap) { + LOG_DEBUG("MDM: failed to get AP"); + return ERROR_FAIL; + } + + int retval = dap_queue_ap_write(ap, reg, value); if (retval != ERROR_OK) { LOG_DEBUG("MDM: failed to queue a write request"); + dap_put_ap(ap); return retval; } retval = dap_run(dap); + dap_put_ap(ap); if (retval != ERROR_OK) { LOG_DEBUG("MDM: dap_run failed"); return retval; @@ -166,14 +163,21 @@ static int kinetis_ke_mdm_write_register(struct adiv5_dap *dap, unsigned reg, ui static int kinetis_ke_mdm_read_register(struct adiv5_dap *dap, unsigned reg, uint32_t *result) { - int retval; - retval = dap_queue_ap_read(dap_ap(dap, 1), reg, result); + struct adiv5_ap *ap = dap_get_ap(dap, 1); + if (!ap) { + LOG_DEBUG("MDM: failed to get AP"); + return ERROR_FAIL; + } + + int retval = dap_queue_ap_read(ap, reg, result); if (retval != ERROR_OK) { LOG_DEBUG("MDM: failed to queue a read request"); + dap_put_ap(ap); return retval; } retval = dap_run(dap); + dap_put_ap(ap); if (retval != ERROR_OK) { LOG_DEBUG("MDM: dap_run failed"); return retval; @@ -932,39 +936,6 @@ static int kinetis_ke_ftmrx_command(struct flash_bank *bank, uint8_t count, return ERROR_OK; } -COMMAND_HANDLER(kinetis_ke_securing_test) -{ - int result; - struct target *target = get_current_target(CMD_CTX); - struct flash_bank *bank = NULL; - uint32_t address; - - uint8_t FCCOBIX[2], FCCOBHI[2], FCCOBLO[2], fstat; - - result = get_flash_bank_by_addr(target, 0x00000000, true, &bank); - if (result != ERROR_OK) - return result; - - assert(bank != NULL); - - if (target->state != TARGET_HALTED) { - LOG_ERROR("Target not halted"); - return ERROR_TARGET_NOT_HALTED; - } - - address = bank->base + 0x00000400; - - FCCOBIX[0] = 0; - FCCOBHI[0] = FTMRX_CMD_ERASESECTOR; - FCCOBLO[0] = address >> 16; - - FCCOBIX[1] = 1; - FCCOBHI[1] = address >> 8; - FCCOBLO[1] = address; - - return kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat); -} - static int kinetis_ke_erase(struct flash_bank *bank, unsigned int first, unsigned int last) { @@ -1000,8 +971,6 @@ static int kinetis_ke_erase(struct flash_bank *bank, unsigned int first, return ERROR_FLASH_OPERATION_FAILED; } - bank->sectors[i].is_erased = 1; - if (i == 2) fcf_erased = true; } @@ -1046,7 +1015,7 @@ static int kinetis_ke_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t old_count = count; count = (old_count | 3) + 1; new_buffer = malloc(count); - if (new_buffer == NULL) { + if (!new_buffer) { LOG_ERROR("odd number of bytes to write and no memory " "for padding buffer"); return ERROR_FAIL; @@ -1242,24 +1211,17 @@ static const struct command_registration kinetis_ke_security_command_handlers[] { .name = "check_security", .mode = COMMAND_EXEC, - .help = "", + .help = "Check status of device security lock", .usage = "", .handler = kinetis_ke_check_flash_security_status, }, { .name = "mass_erase", .mode = COMMAND_EXEC, - .help = "", + .help = "Issue a complete flash erase via the MDM-AP", .usage = "", .handler = kinetis_ke_mdm_mass_erase, }, - { - .name = "test_securing", - .mode = COMMAND_EXEC, - .help = "", - .usage = "", - .handler = kinetis_ke_securing_test, - }, COMMAND_REGISTRATION_DONE }; @@ -1267,7 +1229,7 @@ static const struct command_registration kinetis_ke_exec_command_handlers[] = { { .name = "mdm", .mode = COMMAND_ANY, - .help = "", + .help = "MDM-AP command group", .usage = "", .chain = kinetis_ke_security_command_handlers, }, @@ -1285,7 +1247,7 @@ static const struct command_registration kinetis_ke_command_handler[] = { { .name = "kinetis_ke", .mode = COMMAND_ANY, - .help = "Kinetis KE NAND flash controller commands", + .help = "Kinetis KE flash controller commands", .usage = "", .chain = kinetis_ke_exec_command_handlers, },