flash write_image bug causes error - Not enough working area

The “flash write_image” command on an LCP2102 always results in the error: “not enough working area available(requested 4096, free 3924)”

It appears the LPC2000 driver ignores the -work-area-size command.

ex: $_TARGETNAME configure -work-area-virt 0x0 -work-area-phys 0x40000000 -work-area-size 0x1000 -work-area-backup 0x0

(Note: If you tell it you only have 1kB of work area it still tries to load 4096 bytes into it.)

It sets the work area size based on the flash size specified in the flash bank command.

The issue appears to be in “flash/lpc2000.c” (rev: 1238)

int lpc2000_build_sector_list(struct flash_bank_s *bank)
{
...
        /* default to a 4096 write buffer */
        lpc2000_info->cmd51_max_buffer = 4096;
...
        else if (lpc2000_info->variant == 2)
        {
...
                switch (bank->size)
                {
                        case 4 * 1024:
                                lpc2000_info->cmd51_max_buffer = 1024;
                                num_sectors = 1;
                                break;
                        case 8 * 1024:
                                lpc2000_info->cmd51_max_buffer = 1024;
                                num_sectors = 2;
                                break;
                        case 16 * 1024:
                                num_sectors = 4;
                                break;

ex-1: flash bank lpc2000 0x0 0x2000 0 0 0 lpc2000_v2 12000 calc_checksum

will set the buffer size to 1024.

ex-2: flash bank lpc2000 0x0 0x4000 0 0 0 lpc2000_v2 12000 calc_checksum

will set the buffer size to a default of 4096.

The LPC2102 has 16kB of flash and 4kB of SRAM.

This means no matter what you set your work area to the value that is actually used is based on the size of the flash. In the case of the LPC2102 the default value (4096) is too big.

The work around is to tell flash bank you only have 8kB of flash and “flash write_image” then works fine.

It appears setting the buffer size to 1024 for 8kB was a “fix” to get around this error for the lpc2101.

I wanted to post the issue here to get feedback first before I entered a bug report. Just in case I missed something, or it was a well know issue.

openOCD version: 0.1.0