Beispiel #1
0
static int feed_section(struct elf32_info *info,
			FILE *in, uint32_t offset, uint32_t size,
			binfile_imgcb_t cb, void *user_data)
{
	uint8_t buf[1024];
	uint32_t addr = file_to_phys(info, offset);

	if (fseek(in, offset, SEEK_SET) < 0) {
		pr_error("elf32: can't seek to section");
		return -1;
	}

	while (size) {
		int ask = size > sizeof(buf) ? sizeof(buf) : size;
		int len = fread(buf, 1, ask, in);

		if (len < 0) {
			pr_error("elf32: can't read section");
			return -1;
		}

		if (cb(user_data, addr, buf, len) < 0)
			return -1;

		size -= len;
		offset += len;
		addr += len;
	}

	return 0;
}
Beispiel #2
0
static int feed_section(struct elf32_info *info,
			FILE *in, const Elf32_Shdr *sh,
			binfile_imgcb_t cb, void *user_data)
{
	uint32_t offset = sh->sh_offset;
	uint32_t size = sh->sh_size;
	uint8_t buf[1024];
	uint32_t addr = file_to_phys(info, offset);
	const char *name = NULL;

	if (fseek(in, offset, SEEK_SET) < 0) {
		pr_error("elf32: can't seek to section");
		return -1;
	}

	if (info->string_tab &&
	    sh->sh_name < info->string_len)
		name = info->string_tab + sh->sh_name;

	while (size) {
		int ask = size > sizeof(buf) ? sizeof(buf) : size;
		int len = fread(buf, 1, ask, in);
		struct binfile_chunk ch = {0};

		if (len < 0) {
			pr_error("elf32: can't read section");
			return -1;
		}

		ch.name = name;
		ch.addr = addr;
		ch.data = buf;
		ch.len = len;

		if (cb(user_data, &ch) < 0)
			return -1;

		size -= len;
		offset += len;
		addr += len;
	}

	return 0;
}