diff --git a/contrib/loaders/flash/max32xxx/max32xxx_write.c b/contrib/loaders/flash/max32xxx/max32xxx_write.c index cfdd13711b45f1da720b8b571723c17b717b3884..d70100522042164b69757a1351bd981db06e26b0 100644 --- a/contrib/loaders/flash/max32xxx/max32xxx_write.c +++ b/contrib/loaders/flash/max32xxx/max32xxx_write.c @@ -53,8 +53,6 @@ #define MXC_TPU ((mxc_tpu_regs_t*)MXC_BASE_TPU) #define MXC_BASE_GCR ((uint32_t)0x40000000UL) #define MXC_GCR ((mxc_gcr_regs_t*)MXC_BASE_GCR) -#define MXC_BASE_FLC ((uint32_t)0x40029000UL) -#define MXC_FLC ((mxc_flc_regs_t*)MXC_BASE_FLC) /******************************************************************************/ #define getbyte(temp8) \ @@ -63,7 +61,7 @@ temp8 = **read_ptr; \ \ /* Increment and wrap around the read pointer */ \ - if ((*read_ptr + 1) >= (uint8_t*)(work_end - 4 - 256)) { \ + if ((*read_ptr + 1) >= (uint8_t*)(work_end - 8 - 256)) { \ *read_ptr = (uint8_t *)(work_start + 8); \ } else { \ (*read_ptr)++; \ @@ -82,16 +80,33 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a uint8_t * volatile *write_ptr = (uint8_t **)work_start; uint8_t * volatile *read_ptr = (uint8_t **)(work_start + 4); - uint32_t options = *(uint32_t *)(work_end - 4 - 128); - uint32_t *enc_buffer = (uint32_t *)(work_end - 4 - 256); + uint32_t *flc_base = (uint32_t *)(work_end - 4 - 128); + uint32_t *options = (uint32_t *)(work_end - 8 - 128); + uint32_t *enc_buffer = (uint32_t *)(work_end - 8 - 256); uint8_t temp8; uint32_t addr_save; int i; + mxc_flc_regs_t * MXC_FLC=(mxc_flc_regs_t*)*flc_base; - printf(" > w%08x r%08x o%08x b%08x b%08x\n", - (uint32_t)write_ptr, (uint32_t)read_ptr, (uint32_t)options, (uint32_t)enc_buffer, (uint32_t)(enc_buffer + 256)); + printf(" > w%08x r%08x o%08x f%08x b%08x b%08x\n", + (uint32_t)write_ptr, (uint32_t)read_ptr, (uint32_t)*options, (uint32_t)*flc_base, (uint32_t)enc_buffer, (uint32_t)(enc_buffer + 256)); - if(options & OPTIONS_ENC) { + if(*options & OPTIONS_ENC) { + /* Enable Memory Protection */ + MXC_GCR->scon |= MXC_F_GCR_SCON_MEMPROT_EN; + + /* Set the keysize */ + if(*options & OPTIONS_KEYSIZE) { + MXC_GCR->scon |= MXC_F_GCR_SCON_MEMPROT_KEYSZ; + } else { + MXC_GCR->scon &= ~(MXC_F_GCR_SCON_MEMPROT_KEYSZ); + } + } else { + /* Disable memory protection */ + MXC_GCR->scon &= ~MXC_F_GCR_SCON_MEMPROT_EN; + } + + if(*options & OPTIONS_ENC) { // Setup the AES /* Enable CRYPTO clock */ @@ -117,7 +132,7 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a while(len) { - if((options & OPTIONS_128) == 0) { + if((*options & OPTIONS_128) == 0) { // Save the current address before we read from the working area addr_save = addr; @@ -139,6 +154,9 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a // Unlock the flash MXC_FLC->cn = (MXC_FLC->cn & ~MXC_F_FLC_CN_UNLOCK) | MXC_S_FLC_CN_UNLOCK_UNLOCKED; + // 32-bit write + MXC_FLC->cn |= MXC_F_FLC_CN_WDTH; + MXC_FLC->addr = addr_save; MXC_FLC->data[0] = enc_buffer[0]; @@ -199,11 +217,11 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a enc_buffer[i] |= (temp8 << (24)); } - if(options & OPTIONS_ENC) { + if(*options & OPTIONS_ENC) { // XOR data with the address for(i = 0; i < 4; i++) { - if(options & OPTIONS_RELATIVE_XOR) { + if(*options & OPTIONS_RELATIVE_XOR) { enc_buffer[i] ^= ((addr_save & 0x00FFFFFF) + i*4); } else { enc_buffer[i] ^= (addr_save + i*4); @@ -217,7 +235,7 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a MXC_TPU->cipher_ctrl = ((0x0 << MXC_F_TPU_CIPHER_CTRL_MODE_POS) | (0x0 << MXC_F_TPU_CIPHER_CTRL_ENC_POS)); - if(options & OPTIONS_KEYSIZE) { + if(*options & OPTIONS_KEYSIZE) { // ECB, AES-256, encrypt MXC_TPU->cipher_ctrl |= (0x3 << MXC_F_TPU_CIPHER_CTRL_CIPHER_POS); } else { @@ -278,18 +296,6 @@ void algo_write(uint8_t *work_start, uint8_t *work_end, uint32_t len, uint32_t a } } } - - if(options & OPTIONS_ENC) { - /* Setup the memory protection */ - MXC_GCR->scon |= MXC_F_GCR_SCON_MEMPROT_EN; - - /* Set the keysize */ - if(options & OPTIONS_KEYSIZE) { - MXC_GCR->scon |= MXC_F_GCR_SCON_MEMPROT_KEYSZ; - } else { - MXC_GCR->scon &= ~(MXC_F_GCR_SCON_MEMPROT_KEYSZ); - } - } #ifndef ALGO_TEST __asm("bkpt\n"); diff --git a/contrib/loaders/flash/max32xxx/max32xxx_write.inc b/contrib/loaders/flash/max32xxx/max32xxx_write.inc index 4f4f904520d2aacc34eab1ff1febcd8d59147513..45d2653caac3c64e26acf182086e7c9568463e1b 100644 --- a/contrib/loaders/flash/max32xxx/max32xxx_write.inc +++ b/contrib/loaders/flash/max32xxx/max32xxx_write.inc @@ -1,58 +1,59 @@ /* Autogenerated with ../../../../src/helper/bin2char.sh */ -0x9b,0x46,0x51,0xf8,0x84,0x3c,0x02,0x93,0x13,0xf0,0x02,0x03,0xa1,0xf5,0x82,0x77, -0x05,0x93,0x1e,0xd0,0x4f,0xf0,0x80,0x43,0x9c,0x68,0x64,0x03,0x5e,0xbf,0x9c,0x68, -0x44,0xf4,0x80,0x24,0x9c,0x60,0x5c,0x6a,0x64,0x04,0x42,0xbf,0x5c,0x6a,0x24,0xf4, -0x80,0x44,0x5c,0x62,0x45,0x4b,0x01,0x24,0x1c,0x60,0x1c,0x68,0x44,0xf4,0x80,0x44, -0x1c,0x60,0x1c,0x68,0x44,0xf0,0x10,0x04,0x1c,0x60,0x1c,0x68,0x44,0xf0,0x20,0x04, -0x1c,0x60,0x02,0x9b,0x3d,0x4c,0x03,0xf0,0x01,0x03,0x04,0x93,0x00,0xf1,0x08,0x03, -0x03,0x93,0x3b,0x4b,0xa1,0xf5,0x80,0x7a,0x92,0xb9,0x05,0x9b,0x7b,0xb1,0x4f,0xf0, -0x80,0x43,0x1a,0x68,0x42,0xf4,0x80,0x12,0x1a,0x60,0x02,0x9a,0x12,0xf0,0x40,0x0f, -0x1a,0x68,0x14,0xbf,0x42,0xf4,0x00,0x12,0x22,0xf4,0x00,0x12,0x1a,0x60,0x00,0xbe, -0x04,0x9d,0x00,0x2d,0x5e,0xd1,0x9d,0x68,0x45,0xf0,0x10,0x05,0x9d,0x60,0xa1,0xf5, -0x82,0x7c,0x04,0x9d,0xcc,0xf8,0x00,0x50,0xcd,0xf8,0x04,0xb0,0xae,0x46,0x00,0x2a, -0x4a,0xd0,0xd0,0xf8,0x04,0x80,0x05,0x68,0xa8,0x45,0xfa,0xd0,0x45,0x68,0xd0,0xf8, -0x04,0x80,0x2d,0x78,0x08,0xf1,0x01,0x08,0x47,0x45,0x96,0xbf,0x03,0x9e,0xd0,0xf8, -0x04,0x80,0x46,0x60,0x01,0x9e,0x88,0xbf,0x08,0xf1,0x01,0x08,0x06,0xf1,0x01,0x06, -0x88,0xbf,0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x96,0x05,0xfa,0x0e,0xf8,0xdc,0xf8, -0x00,0x50,0x0e,0xf1,0x08,0x0e,0x45,0xea,0x08,0x05,0xbe,0xf1,0x20,0x0f,0xcc,0xf8, -0x00,0x50,0xd4,0xd1,0x9d,0x68,0x25,0xf0,0x70,0x45,0x45,0xf0,0x00,0x55,0x9d,0x60, -0xc3,0xf8,0x00,0xb0,0xdc,0xf8,0x00,0x50,0x1d,0x63,0x9d,0x68,0x45,0xf0,0x01,0x05, -0x9d,0x60,0x9d,0x68,0xed,0x07,0xfc,0xd4,0x9d,0x68,0x25,0xf0,0x70,0x45,0x9d,0x60, -0x5d,0x6a,0x15,0xf0,0x02,0x0f,0x04,0xd0,0x5d,0x6a,0x25,0xf0,0x02,0x05,0x5d,0x62, -0x00,0xbe,0xdd,0xf8,0x04,0xb0,0x8f,0xe7,0xff,0x25,0xce,0xe7,0x00,0x10,0x00,0x40, -0x00,0x90,0x02,0x40,0xa1,0xf5,0x84,0x7e,0xa1,0xf1,0xf8,0x05,0x06,0x95,0xf4,0x46, -0xcd,0xf8,0x04,0xb0,0x00,0x25,0x4c,0xf8,0x04,0x5f,0x00,0x2a,0x00,0xf0,0xfd,0x80, -0xd0,0xf8,0x04,0x80,0x05,0x68,0xa8,0x45,0xfa,0xd0,0x45,0x68,0xd0,0xf8,0x04,0x80, -0x2d,0x78,0x08,0xf1,0x01,0x08,0x47,0x45,0x96,0xbf,0x03,0x9e,0xd0,0xf8,0x04,0x80, -0x46,0x60,0x01,0x9e,0x88,0xbf,0x08,0xf1,0x01,0x08,0x06,0xf1,0x01,0x06,0x88,0xbf, -0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x96,0xcc,0xf8,0x00,0x50,0x00,0x2a,0x00,0xf0, -0xde,0x80,0xd0,0xf8,0x04,0x90,0xd0,0xf8,0x00,0x80,0xc1,0x45,0xf9,0xd0,0xd0,0xf8, -0x04,0x80,0x98,0xf8,0x00,0x90,0xd0,0xf8,0x04,0x80,0x08,0xf1,0x01,0x08,0x47,0x45, -0x96,0xbf,0x03,0x9e,0xd0,0xf8,0x04,0x80,0x46,0x60,0x01,0x9e,0x88,0xbf,0x08,0xf1, -0x01,0x08,0x06,0xf1,0x01,0x06,0x88,0xbf,0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x96, -0x45,0xea,0x09,0x25,0xcc,0xf8,0x00,0x50,0x00,0x2a,0x00,0xf0,0xbb,0x80,0xd0,0xf8, -0x04,0x90,0xd0,0xf8,0x00,0x80,0xc1,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x80,0x98,0xf8, -0x00,0x90,0xd0,0xf8,0x04,0x80,0x08,0xf1,0x01,0x08,0x47,0x45,0x96,0xbf,0x03,0x9e, -0xd0,0xf8,0x04,0x80,0x46,0x60,0x01,0x9e,0x88,0xbf,0x08,0xf1,0x01,0x08,0x06,0xf1, -0x01,0x06,0x88,0xbf,0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x96,0x45,0xea,0x09,0x45, -0xcc,0xf8,0x00,0x50,0x00,0x2a,0x00,0xf0,0x98,0x80,0xd0,0xf8,0x04,0x90,0xd0,0xf8, -0x00,0x80,0xc1,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x80,0x98,0xf8,0x00,0x90,0xd0,0xf8, -0x04,0x80,0x08,0xf1,0x01,0x08,0x47,0x45,0x96,0xbf,0x03,0x9e,0xd0,0xf8,0x04,0x80, -0x46,0x60,0x01,0x9e,0x88,0xbf,0x08,0xf1,0x01,0x08,0x06,0xf1,0x01,0x06,0x88,0xbf, -0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x96,0x45,0xea,0x09,0x65,0xcc,0xf8,0x00,0x50, -0x06,0x9d,0x65,0x45,0x7f,0xf4,0x66,0xaf,0x05,0x9d,0x00,0x2d,0x46,0xd0,0x02,0x9d, -0x05,0xf0,0x20,0x05,0x06,0x95,0x2b,0xf0,0x7f,0x45,0x07,0x95,0x06,0x9e,0xde,0xf8, -0x04,0x80,0x0e,0xf5,0x84,0x75,0x0e,0xf1,0x04,0x09,0x6d,0x1a,0x00,0x2e,0x5f,0xd0, -0x07,0x9e,0x35,0x44,0x85,0xea,0x08,0x05,0xe1,0x45,0xce,0xf8,0x04,0x50,0xce,0x46, -0xec,0xd1,0x25,0x68,0x45,0xf0,0x00,0x65,0x25,0x60,0x00,0x25,0x65,0x60,0x02,0x9d, -0x15,0xf0,0x40,0x0f,0x65,0x68,0x14,0xbf,0x45,0xf0,0x30,0x05,0x45,0xf0,0x10,0x05, -0x65,0x60,0x65,0x68,0x45,0xf0,0x0c,0x05,0x65,0x60,0x3d,0x68,0x25,0x62,0xda,0xf8, -0x00,0x50,0x65,0x62,0x51,0xf8,0xfc,0x5c,0xa5,0x62,0x51,0xf8,0xf8,0x5c,0xe5,0x62, -0x25,0x68,0x2d,0x01,0xfc,0xd5,0x25,0x6b,0x3d,0x60,0x65,0x6b,0xca,0xf8,0x00,0x50, -0xa5,0x6b,0x41,0xf8,0xfc,0x5c,0xe5,0x6b,0x41,0xf8,0xf8,0x5c,0x9d,0x68,0x25,0xf0, -0x70,0x45,0x45,0xf0,0x00,0x55,0x9d,0x60,0x9d,0x68,0x25,0xf0,0x10,0x05,0x9d,0x60, -0xc3,0xf8,0x00,0xb0,0x3d,0x68,0x1d,0x63,0xda,0xf8,0x00,0x50,0x5d,0x63,0x51,0xf8, -0xfc,0x5c,0x9d,0x63,0x51,0xf8,0xf8,0x5c,0xdd,0x63,0x9d,0x68,0x45,0xf0,0x01,0x05, -0x9d,0x60,0x9d,0x68,0xed,0x07,0xfc,0xd4,0xde,0xe6,0xff,0x25,0x1c,0xe7,0x4f,0xf0, -0xff,0x09,0x3d,0xe7,0x4f,0xf0,0xff,0x09,0x60,0xe7,0x4f,0xf0,0xff,0x09,0x83,0xe7, -0x5d,0x44,0x9f,0xe7, +0x51,0xe9,0x22,0x54,0x15,0xf0,0x02,0x0f,0x4f,0xf0,0x80,0x45,0x01,0x93,0xa1,0xf5, +0x84,0x76,0x2f,0x68,0x3f,0xd0,0x47,0xf4,0x80,0x17,0x2f,0x60,0x51,0xf8,0x88,0x7c, +0x17,0xf0,0x40,0x0f,0x2f,0x68,0x14,0xbf,0x47,0xf4,0x00,0x17,0x27,0xf4,0x00,0x17, +0x2f,0x60,0x51,0xf8,0x88,0x5c,0xad,0x07,0x1e,0xd5,0x4f,0xf0,0x80,0x45,0xaf,0x68, +0x7b,0x03,0x5e,0xbf,0xaf,0x68,0x47,0xf4,0x80,0x27,0xaf,0x60,0x6f,0x6a,0x7f,0x04, +0x42,0xbf,0x6f,0x6a,0x27,0xf4,0x80,0x47,0x6f,0x62,0x40,0x4d,0x01,0x27,0x2f,0x60, +0x2f,0x68,0x47,0xf4,0x80,0x47,0x2f,0x60,0x2f,0x68,0x47,0xf0,0x10,0x07,0x2f,0x60, +0x2f,0x68,0x47,0xf0,0x20,0x07,0x2f,0x60,0xa1,0xf5,0x86,0x75,0xa1,0xf5,0x82,0x77, +0x05,0x95,0x00,0xf1,0x08,0x05,0x02,0x95,0x03,0x97,0x34,0x4d,0xa1,0xf5,0x80,0x77, +0x04,0x97,0x1a,0xb9,0x00,0xbe,0x27,0xf4,0x80,0x17,0xc9,0xe7,0x51,0xf8,0x88,0x7c, +0x17,0xf0,0x01,0x0c,0x5c,0xd1,0xa7,0x68,0x47,0xf0,0x10,0x07,0xa7,0x60,0x01,0x9f, +0xc6,0xf8,0x00,0xc0,0x00,0x2a,0x4d,0xd0,0xd0,0xf8,0x04,0x80,0xd0,0xf8,0x00,0xe0, +0xf0,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0xe0,0xd0,0xf8,0x04,0x80,0x9e,0xf8,0x00,0xe0, +0x08,0xf1,0x01,0x08,0x46,0x45,0x8d,0xbf,0xd0,0xf8,0x04,0x80,0x02,0x9b,0x43,0x60, +0x08,0xf1,0x01,0x08,0x88,0xbf,0xc0,0xf8,0x04,0x80,0x01,0x3a,0x01,0x37,0x33,0x68, +0x0e,0xfa,0x0c,0xfe,0x0c,0xf1,0x08,0x0c,0x43,0xea,0x0e,0x0e,0xbc,0xf1,0x20,0x0f, +0xc6,0xf8,0x00,0xe0,0xd6,0xd1,0xd4,0xf8,0x08,0xc0,0x01,0x9b,0x2c,0xf0,0x70,0x4c, +0x4c,0xf0,0x00,0x5c,0xc4,0xf8,0x08,0xc0,0xd4,0xf8,0x08,0xc0,0x4c,0xf0,0x10,0x0c, +0xc4,0xf8,0x08,0xc0,0x23,0x60,0x33,0x68,0x23,0x63,0xa3,0x68,0x43,0xf0,0x01,0x03, +0xa3,0x60,0xa3,0x68,0xdb,0x07,0xfc,0xd4,0xa3,0x68,0x23,0xf0,0x70,0x43,0xa3,0x60, +0x63,0x6a,0x9b,0x07,0x04,0xd5,0x63,0x6a,0x23,0xf0,0x02,0x03,0x63,0x62,0x00,0xbe, +0x01,0x97,0x9e,0xe7,0x4f,0xf0,0xff,0x0e,0xc9,0xe7,0x00,0xbf,0x00,0x10,0x00,0x40, +0xdd,0xf8,0x14,0xe0,0x01,0x9f,0xa1,0xf1,0xfc,0x0b,0xf4,0x46,0x00,0x23,0x4c,0xf8, +0x04,0x3f,0x00,0x2a,0x00,0xf0,0x06,0x81,0xd0,0xf8,0x04,0x90,0xd0,0xf8,0x00,0x80, +0xc1,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x80,0xd0,0xf8,0x04,0x90,0x98,0xf8,0x00,0x80, +0x09,0xf1,0x01,0x09,0x4e,0x45,0x8d,0xbf,0xd0,0xf8,0x04,0x90,0x02,0x9b,0x43,0x60, +0x09,0xf1,0x01,0x09,0x88,0xbf,0xc0,0xf8,0x04,0x90,0x01,0x3a,0x01,0x37,0xcc,0xf8, +0x00,0x80,0x00,0x2a,0x00,0xf0,0xe9,0x80,0xd0,0xf8,0x04,0xa0,0xd0,0xf8,0x00,0x90, +0xca,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x90,0x99,0xf8,0x00,0xa0,0xd0,0xf8,0x04,0x90, +0x09,0xf1,0x01,0x09,0x4e,0x45,0x8d,0xbf,0xd0,0xf8,0x04,0x90,0x02,0x9b,0x43,0x60, +0x09,0xf1,0x01,0x09,0x88,0xbf,0xc0,0xf8,0x04,0x90,0x01,0x3a,0x01,0x37,0x48,0xea, +0x0a,0x28,0xcc,0xf8,0x00,0x80,0x00,0x2a,0x00,0xf0,0xca,0x80,0xd0,0xf8,0x04,0xa0, +0xd0,0xf8,0x00,0x90,0xca,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x90,0x99,0xf8,0x00,0xa0, +0xd0,0xf8,0x04,0x90,0x09,0xf1,0x01,0x09,0x4e,0x45,0x8d,0xbf,0xd0,0xf8,0x04,0x90, +0x02,0x9b,0x43,0x60,0x09,0xf1,0x01,0x09,0x88,0xbf,0xc0,0xf8,0x04,0x90,0x01,0x3a, +0x01,0x37,0x48,0xea,0x0a,0x48,0xcc,0xf8,0x00,0x80,0x00,0x2a,0x00,0xf0,0xab,0x80, +0xd0,0xf8,0x04,0xa0,0xd0,0xf8,0x00,0x90,0xca,0x45,0xf9,0xd0,0xd0,0xf8,0x04,0x90, +0x99,0xf8,0x00,0xa0,0xd0,0xf8,0x04,0x90,0x09,0xf1,0x01,0x09,0x4e,0x45,0x8d,0xbf, +0xd0,0xf8,0x04,0x90,0x02,0x9b,0x43,0x60,0x09,0xf1,0x01,0x09,0x88,0xbf,0xc0,0xf8, +0x04,0x90,0x01,0x3a,0x01,0x37,0x48,0xea,0x0a,0x68,0xdc,0x45,0xcc,0xf8,0x00,0x80, +0x7f,0xf4,0x74,0xaf,0x51,0xf8,0x88,0x3c,0x9b,0x07,0x58,0xd5,0x01,0x9b,0x23,0xf0, +0x7f,0x4a,0x51,0xf8,0x88,0x3c,0xde,0xf8,0x04,0x80,0x13,0xf0,0x20,0x0f,0x0e,0xf5, +0x86,0x7b,0x08,0xbf,0x01,0x9b,0xab,0xeb,0x01,0x0b,0x0e,0xf1,0x04,0x09,0x14,0xbf, +0xd3,0x44,0x9b,0x44,0x8b,0xea,0x08,0x0b,0xe1,0x45,0xce,0xf8,0x04,0xb0,0xce,0x46, +0xe7,0xd1,0xd5,0xf8,0x00,0xc0,0x4c,0xf0,0x00,0x6c,0xc5,0xf8,0x00,0xc0,0x4f,0xf0, +0x00,0x0c,0xc5,0xf8,0x04,0xc0,0x51,0xf8,0x88,0x3c,0xd5,0xf8,0x04,0xc0,0x5b,0x06, +0x4c,0xbf,0x4c,0xf0,0x30,0x0c,0x4c,0xf0,0x10,0x0c,0xc5,0xf8,0x04,0xc0,0xd5,0xf8, +0x04,0xc0,0x4c,0xf0,0x0c,0x0c,0xc5,0xf8,0x04,0xc0,0x33,0x68,0x2b,0x62,0x03,0x9b, +0x1b,0x68,0x6b,0x62,0x04,0x9b,0x1b,0x68,0xab,0x62,0x51,0xf8,0xfc,0x3c,0xeb,0x62, +0xd5,0xf8,0x00,0xc0,0x1c,0xf0,0x00,0x6f,0xfa,0xd0,0xd5,0xf8,0x30,0xc0,0xc6,0xf8, +0x00,0xc0,0x03,0x9b,0xd5,0xf8,0x34,0xc0,0xc3,0xf8,0x00,0xc0,0x04,0x9b,0xd5,0xf8, +0x38,0xc0,0xc3,0xf8,0x00,0xc0,0xd5,0xf8,0x3c,0xc0,0x41,0xf8,0xfc,0xcc,0xd4,0xf8, +0x08,0xc0,0x01,0x9b,0x2c,0xf0,0x70,0x4c,0x4c,0xf0,0x00,0x5c,0xc4,0xf8,0x08,0xc0, +0xd4,0xf8,0x08,0xc0,0x2c,0xf0,0x10,0x0c,0xc4,0xf8,0x08,0xc0,0x23,0x60,0x33,0x68, +0x23,0x63,0x03,0x9b,0x1b,0x68,0x63,0x63,0x04,0x9b,0x1b,0x68,0xa3,0x63,0x51,0xf8, +0xfc,0x3c,0xe3,0x63,0xa3,0x68,0x43,0xf0,0x01,0x03,0xa3,0x60,0xa3,0x68,0xdb,0x07, +0xfc,0xd4,0xd9,0xe6,0x4f,0xf0,0xff,0x08,0x11,0xe7,0x4f,0xf0,0xff,0x0a,0x2e,0xe7, +0x4f,0xf0,0xff,0x0a,0x4d,0xe7,0x4f,0xf0,0xff,0x0a,0x6c,0xe7, diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index d33c14489907f6f3285cb0a3ef9df079c84c49dc..7d80cb18fde8e966cf44e9539b43f1f007a13589 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -391,7 +391,7 @@ static int max32xxx_write_block(struct flash_bank *bank, const uint8_t *buffer, struct working_area *write_algorithm; uint32_t address = bank->base + offset; struct reg_param reg_params[5]; - struct mem_param mem_param[1]; + struct mem_param mem_param[2]; struct armv7m_algorithm armv7m_info; int retval = ERROR_OK; /* power of two, and multiple of word size */ @@ -445,12 +445,14 @@ static int max32xxx_write_block(struct flash_bank *bank, const uint8_t *buffer, buf_set_u32(reg_params[4].value, 0, 32, source->address + source->size); /* mem_params for options */ - init_mem_param(&mem_param[0], source->address + (source->size - 4 - 128), 4, PARAM_OUT); + init_mem_param(&mem_param[0], source->address + (source->size - 8 - 128), 4, PARAM_OUT); + init_mem_param(&mem_param[1], source->address + (source->size - 4 - 128), 4, PARAM_OUT); buf_set_u32(mem_param[0].value, 0, 32, info->options); + buf_set_u32(mem_param[1].value, 0, 32, info->flc_base); /* leave room for stack, 32-bit options and encryption buffer */ - retval = target_run_flash_async_algorithm(target, buffer, wcount*4, 1, 1, mem_param, - 5, reg_params, source->address, (source->size - 4 - 256), write_algorithm->address, 0, &armv7m_info); + retval = target_run_flash_async_algorithm(target, buffer, wcount*4, 1, 2, mem_param, + 5, reg_params, source->address, (source->size - 8 - 256), write_algorithm->address, 0, &armv7m_info); if (retval == ERROR_FLASH_OPERATION_FAILED) LOG_ERROR("error %d executing max32xxx flash write algorithm", retval);