Esempio n. 1
0
target_flash_status_t target_flash_erase_sector(unsigned int sector) {
    if (!swd_flash_syscall_exec(&flash.sys_call_param, flash.erase_sector, sector*target_device.sector_size, 0, 0, 0)) {
        return TARGET_FAIL_ERASE_SECTOR;
    }

    return TARGET_OK;
}
Esempio n. 2
0
target_flash_status_t target_flash_program_page(uint32_t addr, uint8_t * buf, uint32_t size)
{
    uint32_t bytes_written = 0;
    target_flash_status_t status = TARGET_OK;
    // we need to erase a sector
    if (addr % target_device.sector_size == 0) {
        status = target_flash_erase_sector(addr / target_device.sector_size);
        if (status != TARGET_OK) {
            return status;
        }
    }

    // Program a page in target flash.
    if (!swd_write_memory(flash.program_buffer, buf, size)) {
        return TARGET_FAIL_ALGO_DATA_SEQ;
    }

    while(bytes_written < size) {
        if (!swd_flash_syscall_exec(&flash.sys_call_param,
                                    flash.program_page,
                                    addr,
                                    flash.ram_to_flash_bytes_to_be_written,
                                    flash.program_buffer + bytes_written, 0)) {
            return TARGET_FAIL_WRITE;
        }

        bytes_written += flash.ram_to_flash_bytes_to_be_written;
        addr += flash.ram_to_flash_bytes_to_be_written;
    }

    return TARGET_OK;
}
Esempio n. 3
0
uint8_t target_flash_program_page(const TARGET_FLASH* flash, uint32_t addr, uint8_t * buf, uint32_t size)
{
    uint32_t bytes_written = 0;

    // call a target dependent function to check if
    // we don't want to write specific bits (flash security bits, ...)
//    if (!check_security_bits(addr, buf)) {
//        return 0;
//    }

    // Program a page in target flash.
    if(SWJ_WriteMem(flash->program_buffer, buf, size))
    {
        printf("SWJ_WriteMem failed\r\n");
        return 1;
    }

    while(bytes_written < size) {
        if (swd_flash_syscall_exec(&flash->sys_call_param,
                                    flash->program_page,
                                    addr,
                                    flash->ram_to_flash_bytes_to_be_written,
                                    flash->program_buffer + bytes_written, 0))
        {
                                        printf("call error\r\n");
            return 1;
        }

        bytes_written += flash->ram_to_flash_bytes_to_be_written;
        addr += flash->ram_to_flash_bytes_to_be_written;
    }

    return 0;
}
Esempio n. 4
0
static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size)
{
    const program_target_t *const flash = target_device.flash_algo;

    // check if security bits were set
    if (1 == security_bits_set(addr, (uint8_t *)buf, size)) {
        return ERROR_SECURITY_BITS;
    }

    while (size > 0) {
        uint32_t write_size = MIN(size, flash->program_buffer_size);

        // Write page to buffer
        if (!swd_write_memory(flash->program_buffer, (uint8_t *)buf, write_size)) {
            return ERROR_ALGO_DATA_SEQ;
        }

        // Run flash programming
        if (!swd_flash_syscall_exec(&flash->sys_call_s,
                                    flash->program_page,
                                    addr,
                                    flash->program_buffer_size,
                                    flash->program_buffer,
                                    0)) {
            return ERROR_WRITE;
        }

        addr += write_size;
        buf += write_size;
        size -= write_size;
    }

    return ERROR_SUCCESS;
}
Esempio n. 5
0
target_flash_status_t target_flash_erase_chip(void)
{
    if (!swd_flash_syscall_exec(&flash.sys_call_param, flash.erase_chip, 0, 0, 0, 0)) {
        return TARGET_FAIL_ERASE_ALL;
    }

    return TARGET_OK;
}
Esempio n. 6
0
static error_t target_flash_erase_sector(uint32_t sector)
{
    const program_target_t *const flash = target_device.flash_algo;

    if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_sector, sector * target_device.sector_size, 0, 0, 0)) {
        return ERROR_ERASE_SECTOR;
    }

    return ERROR_SUCCESS;
}
Esempio n. 7
0
target_flash_status_t target_flash_erase_chip(void) {
    //
	// 1 == O.K.
	// 0 == Error
	//
   if (!swd_flash_syscall_exec(&flash.sys_call_param, flash.erase_chip, 0, 0, 0, 0)) {   // 1 == O.K., 0 == Error
        return TARGET_FAIL_ERASE_ALL;
    }
    
    target_set_state(RESET_PROGRAM);
    //target_flash_init();    
    
    return TARGET_OK;
}
Esempio n. 8
0
uint8_t TFlash_Init(const TARGET_FLASH* flash)
{
    uint8_t err;
    
    /* Download flash programming algorithm to target and initialise. */
    err = SWJ_WriteMem(flash->algo_start, (uint8_t *)flash->image, flash->algo_size);
    if(err)
    {
        printf("write flash algo to RAM failed\r\n");
    }
    
    err = swd_flash_syscall_exec(&flash->sys_call_param, flash->init, 0, 0 /* clk value is not used */, 0, 0);
    
    return err;
}
Esempio n. 9
0
static error_t target_flash_erase_sector(uint32_t addr)
{
    const program_target_t *const flash = target_device.flash_algo;

    // Check to make sure the address is on a sector boundary
    if ((addr % target_flash_erase_sector_size(addr)) != 0) {
        return ERROR_ERASE_SECTOR;
    }

    if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_sector, addr, 0, 0, 0)) {
        return ERROR_ERASE_SECTOR;
    }

    return ERROR_SUCCESS;
}
Esempio n. 10
0
static error_t target_flash_erase_chip(void)
{
    error_t status = ERROR_SUCCESS;
    const program_target_t *const flash = target_device.flash_algo;

    if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_chip, 0, 0, 0, 0)) {
        return ERROR_ERASE_ALL;
    }

    // Reset and re-initialize the target after the erase if required
    if (target_device.erase_reset) {
        status = target_flash_init();
    }

    return status;
}
Esempio n. 11
0
target_flash_status_t target_flash_init(extension_t ext)
{
        return TARGET_FAIL_RESET;
    PORT_SWD_SETUP();
    if (!target_set_state(RESET_PROGRAM)) {
        return TARGET_FAIL_RESET;
    }

    // Download flash programming algorithm to target and initialise.
    if (!swd_write_memory(flash.algo_start, (uint8_t *)flash.image, flash.algo_size)) {
        return TARGET_FAIL_ALGO_DL;
    }

    if (!swd_flash_syscall_exec(&flash.sys_call_param, flash.init, 0, 0 /* clk value is not used */, 0, 0)) {
        return TARGET_FAIL_INIT;
    }

    return TARGET_OK;
}
Esempio n. 12
0
static error_t target_flash_init()
{
    const program_target_t *const flash = target_device.flash_algo;

    if (0 == target_set_state(RESET_PROGRAM)) {
        return ERROR_RESET;
    }

    // Download flash programming algorithm to target and initialise.
    if (0 == swd_write_memory(flash->algo_start, (uint8_t *)flash->algo_blob, flash->algo_size)) {
        return ERROR_ALGO_DL;
    }

    if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->init, target_device.flash_start, 0, 0, 0)) {
        return ERROR_INIT;
    }

    return ERROR_SUCCESS;
}
Esempio n. 13
0
uint8_t target_flash_erase_chip(const TARGET_FLASH* flash)
{
    uint8_t err;
    err = swd_flash_syscall_exec(&flash->sys_call_param, flash->erase_chip, 0, 0, 0, 0);
    return err;
}
Esempio n. 14
0
uint8_t target_flash_erase_sector(const TARGET_FLASH* flash, unsigned int sector)
{
    uint8_t err;
    err = swd_flash_syscall_exec(&flash->sys_call_param, flash->erase_sector, sector * FLASH_SECTOR_SIZE, 0, 0, 0);
    return err;
}
Esempio n. 15
0
static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size)
{
    const program_target_t *const flash = target_device.flash_algo;

    // check if security bits were set
    if (1 == security_bits_set(addr, (uint8_t *)buf, size)) {
        return ERROR_SECURITY_BITS;
    }

    while (size > 0) {
        uint32_t write_size = MIN(size, flash->program_buffer_size);

        // Write page to buffer
        if (!swd_write_memory(flash->program_buffer, (uint8_t *)buf, write_size)) {
            return ERROR_ALGO_DATA_SEQ;
        }

        // Run flash programming
        if (!swd_flash_syscall_exec(&flash->sys_call_s,
                                    flash->program_page,
                                    addr,
                                    flash->program_buffer_size,
                                    flash->program_buffer,
                                    0)) {
            return ERROR_WRITE;
        }

        if (config_get_automation_allowed()) {
            // Verify data flashed if in automation mode
            if (flash->verify != 0) {
                if (!swd_flash_syscall_exec(&flash->sys_call_s,
                                    flash->verify,
                                    addr,
                                    write_size,
                                    flash->program_buffer,
                                    0)) {
                    return ERROR_WRITE;
                }
            } else {
                while (write_size > 0) {
                    uint8_t rb_buf[16];
                    uint32_t verify_size = MIN(write_size, sizeof(rb_buf));
                    if (!swd_read_memory(addr, rb_buf, verify_size)) {
                        return ERROR_ALGO_DATA_SEQ;
                    }
                    if (memcmp(buf, rb_buf, verify_size) != 0) {
                        return ERROR_WRITE;
                    }
                    addr += verify_size;
                    buf += verify_size;
                    size -= verify_size;
                    write_size -= verify_size;
                }
                continue;
            }
        }
        addr += write_size;
        buf += write_size;
        size -= write_size;
        
    }

    return ERROR_SUCCESS;
}