예제 #1
0
static int
program_file(FlashControl* flash_control, const char *file, uint32_t start, uint32_t size)
{
	int fd, rc;
	ssize_t len;
	uint32_t actual_size = 0;

	fd = open(file, O_RDONLY);
	if(fd == -1) {
		perror("Failed to open file");
		return(fd);
	}
	printf("About to program \"%s\" at 0x%08x..0x%08x !\n",
			file, start, size);

	printf("Programming & Verifying...\n");
	//progress_init(size >> 8);
	unsigned int save_size = size;
	uint8_t last_progress = 0;
	while(size) {
		len = read(fd, file_buf, FILE_BUF_SIZE);
		if(len < 0) {
			perror("Error reading file");
			return(1);
		}
		if(len == 0)
			break;
		if(len > size)
			len = size;
		size -= len;
		actual_size += len;
		rc = flash_write(fl_chip, start, file_buf, len, true);
		if(rc) {
			if(rc == FLASH_ERR_VERIFY_FAILURE)
				fprintf(stderr, "Verification failed for"
						" chunk at 0x%08x\n", start);
			else
				fprintf(stderr, "Flash write error %d for"
						" chunk at 0x%08x\n", rc, start);
			return(rc);
		}
		start += len;
		unsigned int percent = (100*actual_size/save_size);
		uint8_t progress = (uint8_t)(percent);
		if(progress != last_progress) {
			flash_control_emit_progress(flash_control,file,progress);
			last_progress = progress;
		}
	}
	close(fd);

	/* If this is a flash partition, adjust its size */
	if(ffsh && ffs_index >= 0) {
		printf("Updating actual size in partition header...\n");
		ffs_update_act_size(ffsh, ffs_index, actual_size);
	}
	return(0);
}
예제 #2
0
static void program_file(const char *file, uint32_t start, uint32_t size)
{
    int fd, rc;
    ssize_t len;
    uint32_t actual_size = 0;

    fd = open(file, O_RDONLY);
    if (fd == -1) {
        perror("Failed to open file");
        exit(1);
    }
    printf("About to program \"%s\" at 0x%08x..0x%08x !\n",
           file, start, start + size);
    check_confirm();

    if (dummy_run) {
        printf("skipped (dummy)\n");
        close(fd);
        return;
    }

    printf("Programming & Verifying...\n");
    progress_init(size >> 8);
    while(size) {
        len = read(fd, file_buf, FILE_BUF_SIZE);
        if (len < 0) {
            perror("Error reading file");
            exit(1);
        }
        if (len == 0)
            break;
        if (len > size)
            len = size;
        size -= len;
        actual_size += len;
        rc = blocklevel_write(bl, start, file_buf, len);
        if (rc) {
            if (rc == FLASH_ERR_VERIFY_FAILURE)
                fprintf(stderr, "Verification failed for"
                        " chunk at 0x%08x\n", start);
            else
                fprintf(stderr, "Flash write error %d for"
                        " chunk at 0x%08x\n", rc, start);
            exit(1);
        }
        start += len;
        progress_tick(actual_size >> 8);
    }
    progress_end();
    close(fd);

    /* If this is a flash partition, adjust its size */
    if (ffsh && ffs_index >= 0) {
        printf("Updating actual size in partition header...\n");
        ffs_update_act_size(ffsh, ffs_index, actual_size);
    }
}
예제 #3
0
static void erase_range(uint32_t start, uint32_t size, bool will_program)
{
    uint32_t done = 0;
    int rc;

    printf("About to erase 0x%08x..0x%08x !\n", start, start + size);
    check_confirm();

    if (dummy_run) {
        printf("skipped (dummy)\n");
        return;
    }

    printf("Erasing...\n");
    progress_init(size >> 8);
    while(size) {
        /* If aligned to 64k and at least 64k, use 64k erase */
        if ((start & 0xffff) == 0 && size >= 0x10000) {
            rc = blocklevel_erase(bl, start, 0x10000);
            if (rc) {
                fprintf(stderr, "Error %d erasing 0x%08x\n",
                        rc, start);
                exit(1);
            }
            start += 0x10000;
            size -= 0x10000;
            done += 0x10000;
        } else {
            rc = blocklevel_erase(bl, start, 0x1000);
            if (rc) {
                fprintf(stderr, "Error %d erasing 0x%08x\n",
                        rc, start);
                exit(1);
            }
            start += 0x1000;
            size -= 0x1000;
            done += 0x1000;
        }
        progress_tick(done >> 8);
    }
    progress_end();

    /* If this is a flash partition, mark it empty if we aren't
     * going to program over it as well
     */
    if (ffsh && ffs_index >= 0 && !will_program) {
        printf("Updating actual size in partition header...\n");
        ffs_update_act_size(ffsh, ffs_index, 0);
    }
}