Пример #1
0
void handle_flash(const char *name, unsigned addr, unsigned sz)
{
	struct ptentry *ptn;
	struct ptable *ptable;
	void *data = (void *)addr;
	unsigned extra = 0;

	ptable = flash_get_ptable();
	if (ptable == NULL) {
		jtag_fail("partition table doesn't exist");
		return;
	}

	ptn = ptable_find(ptable, name);
	if (ptn == NULL) {
		jtag_fail("unknown partition name");
		return;
	}

	if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) {
		if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
			jtag_fail("image is not a boot image");
			return;
		}
	}

	if (!strcmp(ptn->name, "system") || !strcmp(ptn->name, "userdata")
	    || !strcmp(ptn->name, "persist"))
		extra = ((page_size >> 9) * 16);
	else
void handle_dump(const char *name, unsigned offset)
{
    ptentry *p;

    if(tmpbuf == 0) {
        tmpbuf = alloc(4096);
    }

    dprintf("dump '%s' partition\n", name);
    p = flash_find_ptn(name);

    if(p == 0) {
        jtag_fail("partition not found");
        return;
    }

    if(flash_init()) {
        jtag_fail("flash_init() failed");
        return;
    }

#if 0
    /* XXX reimpl */
    if(flash_read_page(p->start * 64, tmpbuf, tmpbuf + 2048)) {
        jtag_fail("flash_read() failed");
        return;
    }
#endif

    dprintf("page %d data:\n", p->start * 64);
    hexdump(tmpbuf, 256);
    dprintf("page %d extra:\n", p->start * 64);
    hexdump(tmpbuf, 16);
    jtag_okay("done");
}
Пример #3
0
/* XXX */
void verify_flash(struct ptentry *p, void *addr, unsigned len, int extra)
{
	uint32_t offset = 0;
	void *buf = malloc(FLASH_PAGE_SIZE + extra);
	int verify_extra = extra;
	if (verify_extra > 4)
		verify_extra = 16;
	while (len > 0) {
		flash_read_ext(p, extra, offset, buf, FLASH_PAGE_SIZE);
		if (memcmp(addr, buf, FLASH_PAGE_SIZE + verify_extra)) {
			dprintf(CRITICAL, "verify failed at 0x%08x\n", offset);
			jtag_fail("verify failed");
			return;
		}
		offset += FLASH_PAGE_SIZE;
		addr += FLASH_PAGE_SIZE;
		len -= FLASH_PAGE_SIZE;
		if (extra) {
			addr += extra;
			len -= extra;
		}
	}
	dprintf(INFO, "verify done %d extra bytes\n", verify_extra);
	jtag_okay("verify done");
}
void verify_flash(ptentry *p, void *addr, unsigned len, int extra)
{
    int offset = 0;
    void *buf = alloc(FLASH_PAGE_SIZE + extra);
    int verify_extra = extra;
    if(verify_extra > 4)
        verify_extra = 16;
    while(len > 0) {
        /* coverity[unchecked_value] */
        flash_read_ext(p, extra, offset, buf, FLASH_PAGE_SIZE, 0);
        if(memcmp(addr, buf, FLASH_PAGE_SIZE + verify_extra)) {
            dprintf("verify failed at %x\n", offset);
            jtag_fail("verify failed");
            return;
        }
        offset += FLASH_PAGE_SIZE;
        addr += FLASH_PAGE_SIZE;
        len -= FLASH_PAGE_SIZE;
        if(extra) {
            addr += extra;
            len -= extra;
        }
    }
    dprintf("verify done %d extra bytes\n", verify_extra);
    jtag_okay("verify done");
}
void handle_command(const char *cmd, unsigned a0, unsigned a1, unsigned a2)
{
    if(startswith(cmd,"flash:")) {
        handle_flash(cmd + 6, a0, a1);
        return;
    }

    if(startswith(cmd,"dump:")) {
        handle_dump(cmd + 5, a0);
        return;
    }

    jtag_fail("unknown command");
}