From 419aae494059b9677f37d3227023b12a3ac0dcc3 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Wed, 6 Jul 2016 10:34:51 +1200 Subject: [PATCH] lpc15xx cleanup --- src/include/lpc_common.h | 4 +++- src/lpc11xx.c | 22 ++------------------- src/lpc15xx.c | 41 +++++++++++++++++++++------------------- src/lpc_common.c | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/include/lpc_common.h b/src/include/lpc_common.h index 4886156..8ca361d 100644 --- a/src/include/lpc_common.h +++ b/src/include/lpc_common.h @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2015 Gareth McMullin + * Copyright (C) 2016 Gareth McMullin * * 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 @@ -63,6 +63,8 @@ enum iap_status lpc_iap_call(struct lpc_flash *f, enum iap_cmd cmd, ...); int lpc_flash_erase(struct target_flash *f, uint32_t addr, size_t len); int lpc_flash_write(struct target_flash *f, uint32_t dest, const void *src, size_t len); +int lpc_flash_write_magic_vect(struct target_flash *f, + uint32_t dest, const void *src, size_t len); #endif diff --git a/src/lpc11xx.c b/src/lpc11xx.c index 8b21995..fcf9f0e 100644 --- a/src/lpc11xx.c +++ b/src/lpc11xx.c @@ -2,7 +2,7 @@ * This file is part of the Black Magic Debug project. * * Copyright (C) 2011 Mike Smith - * Copyright (C) 2015 Gareth McMullin + * Copyright (C) 2016 Gareth McMullin * * 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 @@ -34,15 +34,12 @@ #define LPC11XX_DEVICE_ID 0x400483F4 #define LPC8XX_DEVICE_ID 0x400483F8 -static int lpc11xx_flash_write(struct target_flash *f, - uint32_t dest, const void *src, size_t len); - void lpc11xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize) { struct lpc_flash *lf = lpc_add_flash(t, addr, len); lf->f.blocksize = erasesize; lf->f.buf_size = IAP_PGM_CHUNKSIZE; - lf->f.write_buf = lpc11xx_flash_write; + lf->f.write_buf = lpc_flash_write_magic_vect; lf->iap_entry = IAP_ENTRYPOINT; lf->iap_ram = IAP_RAM_BASE; lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES; @@ -118,18 +115,3 @@ lpc11xx_probe(target *t) return false; } -static int lpc11xx_flash_write(struct target_flash *f, - uint32_t dest, const void *src, size_t len) -{ - if (dest == 0) { - /* Fill in the magic vector to allow booting the flash */ - uint32_t *w = (uint32_t *)src; - uint32_t sum = 0; - - for (unsigned i = 0; i < 7; i++) - sum += w[i]; - w[7] = ~sum + 1; - } - return lpc_flash_write(f, dest, src, len); -} - diff --git a/src/lpc15xx.c b/src/lpc15xx.c index 32b9ad6..3f23f9f 100644 --- a/src/lpc15xx.c +++ b/src/lpc15xx.c @@ -1,3 +1,24 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 Mike Smith + * Copyright (C) 2016 Gareth McMullin + * Copyright (C) 2016 David Lawrence + * + * 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 3 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 . + */ + #include "general.h" #include "target.h" #include "cortexm.h" @@ -13,15 +34,12 @@ #define LPC15XX_DEVICE_ID 0x400743F8 -static int lpc15xx_flash_write(struct target_flash *f, - uint32_t dest, const void *src, size_t len); - void lpc15xx_add_flash(target *t, uint32_t addr, size_t len, size_t erasesize) { struct lpc_flash *lf = lpc_add_flash(t, addr, len); lf->f.blocksize = erasesize; lf->f.buf_size = IAP_PGM_CHUNKSIZE; - lf->f.write_buf = lpc15xx_flash_write; + lf->f.write_buf = lpc_flash_write_magic_vect; lf->iap_entry = IAP_ENTRYPOINT; lf->iap_ram = IAP_RAM_BASE; lf->iap_msp = IAP_RAM_BASE + MIN_RAM_SIZE - RAM_USAGE_FOR_IAP_ROUTINES; @@ -59,18 +77,3 @@ lpc15xx_probe(target *t) return false; } -static int lpc15xx_flash_write(struct target_flash *f, - uint32_t dest, const void *src, size_t len) -{ - if (dest == 0) { - /* Fill in the magic vector to allow booting the flash */ - uint32_t *w = (uint32_t *)src; - uint32_t sum = 0; - - for (unsigned i = 0; i < 7; i++) - sum += w[i]; - w[7] = ~sum + 1; - } - return lpc_flash_write(f, dest, src, len); -} - diff --git a/src/lpc_common.c b/src/lpc_common.c index d9abc76..ad62e15 100644 --- a/src/lpc_common.c +++ b/src/lpc_common.c @@ -133,3 +133,18 @@ int lpc_flash_write(struct target_flash *tf, return 0; } +int lpc_flash_write_magic_vect(struct target_flash *f, + uint32_t dest, const void *src, size_t len) +{ + if (dest == 0) { + /* Fill in the magic vector to allow booting the flash */ + uint32_t *w = (uint32_t *)src; + uint32_t sum = 0; + + for (unsigned i = 0; i < 7; i++) + sum += w[i]; + w[7] = ~sum + 1; + } + return lpc_flash_write(f, dest, src, len); +} +