~ubuntu-branches/ubuntu/wily/openocd/wily

« back to all changes in this revision

Viewing changes to src/flash/lpc2000.c

  • Committer: Bazaar Package Importer
  • Author(s): Uwe Hermann
  • Date: 2009-11-25 12:20:04 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091125122004-4cnrzqw7v9qu064n
Tags: 0.3.1-1
* New upstream release (Closes: #554598, #537740).
* Add sh4 (instead of sh) to the list of architectures (Closes: #555553).
* Standards-Version: 3.8.3 (no changes required).
* debian/watch: Add file.
* debian/docs: Updates, some files were removed, some added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *   Copyright (C) 2005 by Dominic Rath                                    *
3
3
 *   Dominic.Rath@gmx.de                                                   *
4
4
 *                                                                         *
 
5
 *   LPC1700 support Copyright (C) 2009 by Audrius Urmanavicius            *
 
6
 *   didele.deze@gmail.com                                                 *
 
7
 *                                                                         *
5
8
 *   This program is free software; you can redistribute it and/or modify  *
6
9
 *   it under the terms of the GNU General Public License as published by  *
7
10
 *   the Free Software Foundation; either version 2 of the License, or     *
24
27
 
25
28
#include "lpc2000.h"
26
29
#include "armv4_5.h"
 
30
#include "armv7m.h"
27
31
#include "binarybuffer.h"
28
32
 
29
33
 
30
 
/* flash programming support for Philips LPC2xxx devices
 
34
/* flash programming support for NXP LPC17xx and LPC2xxx devices
31
35
 * currently supported devices:
32
36
 * variant 1 (lpc2000_v1):
33
 
 * - 2104 | 5|6
 
37
 * - 2104 | 5 | 6
34
38
 * - 2114 | 9
35
39
 * - 2124 | 9
36
40
 * - 2194
40
44
 * variant 2 (lpc2000_v2):
41
45
 * - 213x
42
46
 * - 214x
43
 
 * - 2101 | 2|3
44
 
 * - 2364 | 6|8
 
47
 * - 2101 | 2 | 3
 
48
 * - 2364 | 6 | 8
45
49
 * - 2378
 
50
 *
 
51
 * lpc1700:
 
52
 * - 175x
 
53
 * - 176x (tested with LPC1768)
46
54
 */
47
55
 
48
56
static int lpc2000_register_commands(struct command_context_s *cmd_ctx);
85
93
static int lpc2000_build_sector_list(struct flash_bank_s *bank)
86
94
{
87
95
        lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
 
96
        int i;
 
97
        uint32_t offset = 0;
88
98
 
89
99
        /* default to a 4096 write buffer */
90
100
        lpc2000_info->cmd51_max_buffer = 4096;
91
101
 
92
 
        if (lpc2000_info->variant == 1)
 
102
        if (lpc2000_info->variant == lpc2000_v1)
93
103
        {
94
 
                int i = 0;
95
 
                uint32_t offset = 0;
96
 
 
97
104
                /* variant 1 has different layout for 128kb and 256kb flashes */
98
105
                if (bank->size == 128 * 1024)
99
106
                {
144
151
                        exit(-1);
145
152
                }
146
153
        }
147
 
        else if (lpc2000_info->variant == 2)
 
154
        else if (lpc2000_info->variant == lpc2000_v2)
148
155
        {
149
 
                int num_sectors;
150
 
                int i;
151
 
                uint32_t offset = 0;
152
 
 
153
156
                /* variant 2 has a uniform layout, only number of sectors differs */
154
157
                switch (bank->size)
155
158
                {
156
159
                        case 4 * 1024:
157
160
                                lpc2000_info->cmd51_max_buffer = 1024;
158
 
                                num_sectors = 1;
 
161
                                bank->num_sectors = 1;
159
162
                                break;
160
163
                        case 8 * 1024:
161
164
                                lpc2000_info->cmd51_max_buffer = 1024;
162
 
                                num_sectors = 2;
 
165
                                bank->num_sectors = 2;
163
166
                                break;
164
167
                        case 16 * 1024:
165
 
                                num_sectors = 4;
 
168
                                bank->num_sectors = 4;
166
169
                                break;
167
170
                        case 32 * 1024:
168
 
                                num_sectors = 8;
 
171
                                bank->num_sectors = 8;
169
172
                                break;
170
173
                        case 64 * 1024:
171
 
                                num_sectors = 9;
 
174
                                bank->num_sectors = 9;
172
175
                                break;
173
176
                        case 128 * 1024:
174
 
                                num_sectors = 11;
 
177
                                bank->num_sectors = 11;
175
178
                                break;
176
179
                        case 256 * 1024:
177
 
                                num_sectors = 15;
 
180
                                bank->num_sectors = 15;
178
181
                                break;
179
182
                        case 512 * 1024:
180
183
                        case 500 * 1024:
181
 
                                num_sectors = 27;
 
184
                                bank->num_sectors = 27;
182
185
                                break;
183
186
                        default:
184
187
                                LOG_ERROR("BUG: unknown bank->size encountered");
186
189
                                break;
187
190
                }
188
191
 
189
 
                bank->num_sectors = num_sectors;
190
 
                bank->sectors = malloc(sizeof(flash_sector_t) * num_sectors);
 
192
                bank->sectors = malloc(sizeof(flash_sector_t) * bank->num_sectors);
191
193
 
192
 
                for (i = 0; i < num_sectors; i++)
 
194
                for (i = 0; i < bank->num_sectors; i++)
193
195
                {
194
196
                        if ((i >= 0) && (i < 8))
195
197
                        {
217
219
                        }
218
220
                }
219
221
        }
 
222
        else if (lpc2000_info->variant == lpc1700)
 
223
        {
 
224
                switch(bank->size)
 
225
                {
 
226
                        case 32 * 1024:
 
227
                                bank->num_sectors = 8;
 
228
                                break;
 
229
                        case 64 * 1024:
 
230
                                bank->num_sectors = 16;
 
231
                                break;
 
232
                        case 128 * 1024:
 
233
                                bank->num_sectors = 18;
 
234
                                break;
 
235
                        case 256 * 1024:
 
236
                                bank->num_sectors = 22;
 
237
                                break;
 
238
                        case 512 * 1024:
 
239
                                bank->num_sectors = 30;
 
240
                                break;
 
241
                        default:
 
242
                                LOG_ERROR("BUG: unknown bank->size encountered");
 
243
                                exit(-1);
 
244
                }
 
245
 
 
246
                bank->sectors = malloc(sizeof(flash_sector_t) * bank->num_sectors);
 
247
 
 
248
                for(i = 0; i < bank->num_sectors; i++)
 
249
                {
 
250
                        bank->sectors[i].offset = offset;
 
251
                        /* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx devices */
 
252
                        bank->sectors[i].size = (i < 16)? 4 * 1024 : 32 * 1024;
 
253
                        offset += bank->sectors[i].size;
 
254
                        bank->sectors[i].is_erased = -1;
 
255
                        bank->sectors[i].is_protected = 1;
 
256
                }
 
257
        }
220
258
        else
221
259
        {
222
260
                LOG_ERROR("BUG: unknown lpc2000_info->variant encountered");
226
264
        return ERROR_OK;
227
265
}
228
266
 
229
 
/* call LPC2000 IAP function
230
 
 * uses 172 bytes working area
 
267
/* call LPC1700/LPC2000 IAP function
 
268
 * uses 180 bytes working area
231
269
 * 0x0 to 0x7: jump gate (BX to thumb state, b -2 to wait)
232
 
 * 0x8 to 0x1f: command parameter table
233
 
 * 0x20 to 0x2b: command result table
234
 
 * 0x2c to 0xac: stack (only 128b needed)
 
270
 * 0x8 to 0x1f: command parameter table (1+5 words)
 
271
 * 0x20 to 0x33: command result table (1+4 words)
 
272
 * 0x34 to 0xb3: stack (only 128b needed)
235
273
 */
236
 
static int lpc2000_iap_call(flash_bank_t *bank, int code, uint32_t param_table[5], uint32_t result_table[2])
 
274
static int lpc2000_iap_call(flash_bank_t *bank, int code, uint32_t param_table[5], uint32_t result_table[4])
237
275
{
238
276
        int retval;
239
277
        lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
240
278
        target_t *target = bank->target;
241
279
        mem_param_t mem_params[2];
242
280
        reg_param_t reg_params[5];
243
 
        armv4_5_algorithm_t armv4_5_info;
244
 
        uint32_t status_code;
 
281
        armv4_5_algorithm_t armv4_5_info; /* for LPC2000 */
 
282
        armv7m_algorithm_t armv7m_info;   /* for LPC1700 */
 
283
        uint32_t status_code;
 
284
        uint32_t iap_entry_point = 0; /* to make compiler happier */
245
285
 
246
286
        /* regrab previously allocated working_area, or allocate a new one */
247
287
        if (!lpc2000_info->iap_working_area)
249
289
                uint8_t jump_gate[8];
250
290
 
251
291
                /* make sure we have a working area */
252
 
                if (target_alloc_working_area(target, 172, &lpc2000_info->iap_working_area) != ERROR_OK)
 
292
                if (target_alloc_working_area(target, 180, &lpc2000_info->iap_working_area) != ERROR_OK)
253
293
                {
254
294
                        LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
255
295
                        return ERROR_FLASH_OPERATION_FAILED;
256
296
                }
257
297
 
258
298
                /* write IAP code to working area */
259
 
                target_buffer_set_u32(target, jump_gate, ARMV4_5_BX(12));
260
 
                target_buffer_set_u32(target, jump_gate + 4, ARMV4_5_B(0xfffffe, 0));
 
299
                switch(lpc2000_info->variant)
 
300
                {
 
301
                        case lpc1700:
 
302
                                target_buffer_set_u32(target, jump_gate, ARMV7M_T_BX(12));
 
303
                                target_buffer_set_u32(target, jump_gate + 4, ARMV7M_T_B(0xfffffe));
 
304
                                break;
 
305
                        case lpc2000_v1:
 
306
                        case lpc2000_v2:
 
307
                                target_buffer_set_u32(target, jump_gate, ARMV4_5_BX(12));
 
308
                                target_buffer_set_u32(target, jump_gate + 4, ARMV4_5_B(0xfffffe, 0));
 
309
                                break;
 
310
                        default:
 
311
                                LOG_ERROR("BUG: unknown bank->size encountered");
 
312
                                exit(-1);
 
313
                }
 
314
 
261
315
                if ((retval = target_write_memory(target, lpc2000_info->iap_working_area->address, 4, 2, jump_gate)) != ERROR_OK)
262
316
                {
 
317
                        LOG_ERROR("Write memory at address 0x%8.8" PRIx32 " failed (check work_area definition)", lpc2000_info->iap_working_area->address);
263
318
                        return retval;
264
319
                }
265
320
        }
266
321
 
267
 
        armv4_5_info.common_magic = ARMV4_5_COMMON_MAGIC;
268
 
        armv4_5_info.core_mode = ARMV4_5_MODE_SVC;
269
 
        armv4_5_info.core_state = ARMV4_5_STATE_ARM;
 
322
        switch(lpc2000_info->variant)
 
323
        {
 
324
                case lpc1700:
 
325
                        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
 
326
                        armv7m_info.core_mode = ARMV7M_MODE_ANY;
 
327
                        iap_entry_point = 0x1fff1ff1;
 
328
                        break;
 
329
                case lpc2000_v1:
 
330
                case lpc2000_v2:
 
331
                        armv4_5_info.common_magic = ARMV4_5_COMMON_MAGIC;
 
332
                        armv4_5_info.core_mode = ARMV4_5_MODE_SVC;
 
333
                        armv4_5_info.core_state = ARMV4_5_STATE_ARM;
 
334
                        iap_entry_point = 0x7ffffff1;
 
335
                        break;
 
336
                default:
 
337
                        LOG_ERROR("BUG: unknown lpc2000->variant encountered");
 
338
                        exit(-1);
 
339
        }
270
340
 
271
341
        /* command parameter table */
272
 
        init_mem_param(&mem_params[0], lpc2000_info->iap_working_area->address + 8, 4 * 6, PARAM_OUT);
 
342
        init_mem_param(&mem_params[0], lpc2000_info->iap_working_area->address + 8, 6 * 4, PARAM_OUT);
273
343
        target_buffer_set_u32(target, mem_params[0].value, code);
274
 
        target_buffer_set_u32(target, mem_params[0].value + 0x4, param_table[0]);
275
 
        target_buffer_set_u32(target, mem_params[0].value + 0x8, param_table[1]);
276
 
        target_buffer_set_u32(target, mem_params[0].value + 0xc, param_table[2]);
 
344
        target_buffer_set_u32(target, mem_params[0].value + 0x04, param_table[0]);
 
345
        target_buffer_set_u32(target, mem_params[0].value + 0x08, param_table[1]);
 
346
        target_buffer_set_u32(target, mem_params[0].value + 0x0c, param_table[2]);
277
347
        target_buffer_set_u32(target, mem_params[0].value + 0x10, param_table[3]);
278
348
        target_buffer_set_u32(target, mem_params[0].value + 0x14, param_table[4]);
279
349
 
280
350
        init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
281
 
        buf_set_u32(reg_params[0].value, 0, 32, lpc2000_info->iap_working_area->address + 0x8);
 
351
        buf_set_u32(reg_params[0].value, 0, 32, lpc2000_info->iap_working_area->address + 0x08);
282
352
 
283
353
        /* command result table */
284
 
        init_mem_param(&mem_params[1], lpc2000_info->iap_working_area->address + 0x20, 4 * 3, PARAM_IN);
 
354
        init_mem_param(&mem_params[1], lpc2000_info->iap_working_area->address + 0x20, 5 * 4, PARAM_IN);
285
355
 
286
356
        init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
287
357
        buf_set_u32(reg_params[1].value, 0, 32, lpc2000_info->iap_working_area->address + 0x20);
288
358
 
289
359
        /* IAP entry point */
290
360
        init_reg_param(&reg_params[2], "r12", 32, PARAM_OUT);
291
 
        buf_set_u32(reg_params[2].value, 0, 32, 0x7ffffff1);
292
 
 
293
 
        /* IAP stack */
294
 
        init_reg_param(&reg_params[3], "r13_svc", 32, PARAM_OUT);
295
 
        buf_set_u32(reg_params[3].value, 0, 32, lpc2000_info->iap_working_area->address + 0xac);
296
 
 
297
 
        /* return address */
298
 
        init_reg_param(&reg_params[4], "lr_svc", 32, PARAM_OUT);
299
 
        buf_set_u32(reg_params[4].value, 0, 32, lpc2000_info->iap_working_area->address + 0x4);
300
 
 
301
 
        target_run_algorithm(target, 2, mem_params, 5, reg_params, lpc2000_info->iap_working_area->address, lpc2000_info->iap_working_area->address + 0x4, 10000, &armv4_5_info);
302
 
 
303
 
        status_code = buf_get_u32(mem_params[1].value, 0, 32);
304
 
        result_table[0] = target_buffer_get_u32(target, mem_params[1].value);
305
 
        result_table[1] = target_buffer_get_u32(target, mem_params[1].value + 4);
 
361
        buf_set_u32(reg_params[2].value, 0, 32, iap_entry_point);
 
362
 
 
363
        switch(lpc2000_info->variant)
 
364
        {
 
365
                case lpc1700:
 
366
                        /* IAP stack */
 
367
                        init_reg_param(&reg_params[3], "sp", 32, PARAM_OUT);
 
368
                        buf_set_u32(reg_params[3].value, 0, 32, lpc2000_info->iap_working_area->address + 0xb4);
 
369
 
 
370
                        /* return address */
 
371
                        init_reg_param(&reg_params[4], "lr", 32, PARAM_OUT);
 
372
                        buf_set_u32(reg_params[4].value, 0, 32, (lpc2000_info->iap_working_area->address + 0x04) | 1); /* bit0 of LR = 1 to return in Thumb mode */
 
373
 
 
374
                        target_run_algorithm(target, 2, mem_params, 5, reg_params, lpc2000_info->iap_working_area->address, lpc2000_info->iap_working_area->address + 0x4, 10000, &armv7m_info);
 
375
                        break;
 
376
                case lpc2000_v1:
 
377
                case lpc2000_v2:
 
378
                        /* IAP stack */
 
379
                        init_reg_param(&reg_params[3], "r13_svc", 32, PARAM_OUT);
 
380
                        buf_set_u32(reg_params[3].value, 0, 32, lpc2000_info->iap_working_area->address + 0xb4);
 
381
 
 
382
                        /* return address */
 
383
                        init_reg_param(&reg_params[4], "lr_svc", 32, PARAM_OUT);
 
384
                        buf_set_u32(reg_params[4].value, 0, 32, lpc2000_info->iap_working_area->address + 0x04);
 
385
 
 
386
                        target_run_algorithm(target, 2, mem_params, 5, reg_params, lpc2000_info->iap_working_area->address, lpc2000_info->iap_working_area->address + 0x4, 10000, &armv4_5_info);
 
387
                        break;
 
388
                default:
 
389
                        LOG_ERROR("BUG: unknown lpc2000->variant encountered");
 
390
                        exit(-1);
 
391
        }
 
392
 
 
393
 
 
394
        status_code     = target_buffer_get_u32(target, mem_params[1].value);
 
395
        result_table[0] = target_buffer_get_u32(target, mem_params[1].value + 0x04);
 
396
        result_table[1] = target_buffer_get_u32(target, mem_params[1].value + 0x08);
 
397
        result_table[2] = target_buffer_get_u32(target, mem_params[1].value + 0x0c);
 
398
        result_table[3] = target_buffer_get_u32(target, mem_params[1].value + 0x10);
 
399
 
 
400
        LOG_DEBUG("IAP command = %i (0x%8.8" PRIx32", 0x%8.8" PRIx32", 0x%8.8" PRIx32", 0x%8.8" PRIx32", 0x%8.8" PRIx32") completed with result = %8.8" PRIx32,
 
401
                          code, param_table[0], param_table[1], param_table[2], param_table[3], param_table[4], status_code);
306
402
 
307
403
        destroy_mem_param(&mem_params[0]);
308
404
        destroy_mem_param(&mem_params[1]);
319
415
static int lpc2000_iap_blank_check(struct flash_bank_s *bank, int first, int last)
320
416
{
321
417
        uint32_t param_table[5];
322
 
        uint32_t result_table[2];
 
418
        uint32_t result_table[4];
323
419
        int status_code;
324
420
        int i;
325
421
 
349
445
                                return ERROR_FLASH_BUSY;
350
446
                                break;
351
447
                        default:
352
 
                                LOG_ERROR("BUG: unknown LPC2000 status code");
 
448
                                LOG_ERROR("BUG: unknown LPC2000 status code %i", status_code);
353
449
                                exit(-1);
354
450
                }
355
451
        }
357
453
        return ERROR_OK;
358
454
}
359
455
 
360
 
/* flash bank lpc2000 <base> <size> 0 0 <target#> <lpc_variant> <cclk> [calc_checksum]
 
456
/*
 
457
 * flash bank lpc2000 <base> <size> 0 0 <target#> <lpc_variant> <cclk> [calc_checksum]
361
458
 */
362
459
static int lpc2000_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
363
460
{
374
471
 
375
472
        if (strcmp(args[6], "lpc2000_v1") == 0)
376
473
        {
377
 
                lpc2000_info->variant = 1;
 
474
                lpc2000_info->variant = lpc2000_v1;
378
475
                lpc2000_info->cmd51_dst_boundary = 512;
379
476
                lpc2000_info->cmd51_can_256b = 0;
380
477
                lpc2000_info->cmd51_can_8192b = 1;
 
478
                lpc2000_info->checksum_vector = 5;
381
479
        }
382
480
        else if (strcmp(args[6], "lpc2000_v2") == 0)
383
481
        {
384
 
                lpc2000_info->variant = 2;
385
 
                lpc2000_info->cmd51_dst_boundary = 256;
386
 
                lpc2000_info->cmd51_can_256b = 1;
387
 
                lpc2000_info->cmd51_can_8192b = 0;
 
482
                lpc2000_info->variant = lpc2000_v2;
 
483
                lpc2000_info->cmd51_dst_boundary = 256;
 
484
                lpc2000_info->cmd51_can_256b = 1;
 
485
                lpc2000_info->cmd51_can_8192b = 0;
 
486
                lpc2000_info->checksum_vector = 5;
 
487
        }
 
488
        else if (strcmp(args[6], "lpc1700") == 0)
 
489
        {
 
490
                lpc2000_info->variant = lpc1700;
 
491
                lpc2000_info->cmd51_dst_boundary = 256;
 
492
                lpc2000_info->cmd51_can_256b = 1;
 
493
                lpc2000_info->cmd51_can_8192b = 0;
 
494
                lpc2000_info->checksum_vector = 7;
388
495
        }
389
496
        else
390
497
        {
391
 
                LOG_ERROR("unknown LPC2000 variant");
 
498
                LOG_ERROR("unknown LPC2000 variant: %s", args[6]);
392
499
                free(lpc2000_info);
393
500
                return ERROR_FLASH_BANK_INVALID;
394
501
        }
411
518
{
412
519
        lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
413
520
        uint32_t param_table[5];
414
 
        uint32_t result_table[2];
 
521
        uint32_t result_table[4];
415
522
        int status_code;
416
523
 
417
524
        if (bank->target->state != TARGET_HALTED)
475
582
        int first_sector = 0;
476
583
        int last_sector = 0;
477
584
        uint32_t param_table[5];
478
 
        uint32_t result_table[2];
 
585
        uint32_t result_table[4];
479
586
        int status_code;
480
587
        int i;
481
588
        working_area_t *download_area;
490
597
        if (offset + count > bank->size)
491
598
                return ERROR_FLASH_DST_OUT_OF_BANK;
492
599
 
493
 
        if (lpc2000_info->cmd51_can_256b)
494
 
                dst_min_alignment = 256;
495
 
        else
496
 
                dst_min_alignment = 512;
 
600
        dst_min_alignment = lpc2000_info->cmd51_dst_boundary;
497
601
 
498
602
        if (offset % dst_min_alignment)
499
603
        {
515
619
        if ((offset == 0) && (count >= 0x20) && lpc2000_info->calc_checksum)
516
620
        {
517
621
                uint32_t checksum = 0;
518
 
                int i = 0;
 
622
                int i;
519
623
                for (i = 0; i < 8; i++)
520
624
                {
521
 
                        LOG_DEBUG("0x%2.2x: 0x%8.8" PRIx32, i * 4, buf_get_u32(buffer + (i * 4), 0, 32));
522
 
                        if (i != 5)
 
625
                        LOG_DEBUG("Vector 0x%2.2x: 0x%8.8" PRIx32, i * 4, buf_get_u32(buffer + (i * 4), 0, 32));
 
626
                        if (i != lpc2000_info->checksum_vector)
523
627
                                checksum += buf_get_u32(buffer + (i * 4), 0, 32);
524
628
                }
525
629
                checksum = 0 - checksum;
526
630
                LOG_DEBUG("checksum: 0x%8.8" PRIx32, checksum);
527
631
 
528
 
                uint32_t original_value = buf_get_u32(buffer + (5 * 4), 0, 32);
 
632
                uint32_t original_value = buf_get_u32(buffer + (lpc2000_info->checksum_vector * 4), 0, 32);
529
633
                if (original_value != checksum)
530
634
                {
531
 
                        LOG_WARNING("Verification will fail since checksum in image(0x%8.8" PRIx32 ") written to flash was different from calculated vector checksum(0x%8.8" PRIx32 ").",
 
635
                        LOG_WARNING("Verification will fail since checksum in image (0x%8.8" PRIx32 ") to be written to flash is different from calculated vector checksum (0x%8.8" PRIx32 ").",
532
636
                                        original_value, checksum);
533
637
                        LOG_WARNING("To remove this warning modify build tools on developer PC to inject correct LPC vector checksum.");
534
638
                }
535
639
 
536
 
                buf_set_u32(buffer + 0x14, 0, 32, checksum);
 
640
                buf_set_u32(buffer + (lpc2000_info->checksum_vector * 4), 0, 32, checksum);
537
641
        }
538
642
 
539
643
        /* allocate a working area */
590
694
                else
591
695
                {
592
696
                        uint8_t *last_buffer = malloc(thisrun_bytes);
593
 
                        uint32_t i;
594
697
                        memcpy(last_buffer, buffer + bytes_written, bytes_remaining);
595
 
                        for (i = bytes_remaining; i < thisrun_bytes; i++)
596
 
                                last_buffer[i] = 0xff;
 
698
                        memset(last_buffer + bytes_remaining, 0xff, thisrun_bytes - bytes_remaining);
597
699
                        target_write_buffer(bank->target, download_area->address, thisrun_bytes, last_buffer);
598
700
                        free(last_buffer);
599
701
                }
667
769
{
668
770
        lpc2000_flash_bank_t *lpc2000_info = bank->driver_priv;
669
771
 
670
 
        snprintf(buf, buf_size, "lpc2000 flash driver variant: %i, clk: %" PRIi32 , lpc2000_info->variant, lpc2000_info->cclk);
 
772
        snprintf(buf, buf_size, "lpc2000 flash driver variant: %i, clk: %" PRIi32 "kHz" , lpc2000_info->variant, lpc2000_info->cclk);
671
773
 
672
774
        return ERROR_OK;
673
775
}
676
778
{
677
779
        flash_bank_t *bank;
678
780
        uint32_t param_table[5];
679
 
        uint32_t result_table[2];
 
781
        uint32_t result_table[4];
680
782
        int status_code;
681
783
 
682
784
        if (argc < 1)