Beispiel #1
0
static int bootimg_write_image(int fd, const char *pathname, unsigned *size, unsigned page_size, struct cavan_sha_context *context)
{
	int ret;
	int img_fd;
	ssize_t wrlen;

	ret = cavan_file_seek_next_page(fd, page_size);
	if (ret < 0)
	{
		pr_red_info("cavan_file_seek_next_page");
		return ret;
	}

	img_fd = open(pathname, O_RDONLY);
	if (img_fd < 0)
	{
		pr_error_info("open file `%s'", pathname);
		return img_fd;
	}

	wrlen = ffile_copy(img_fd, fd);
	if (wrlen < 0)
	{
		ret = wrlen;
		pr_red_info("ffile_copy");
		goto out_close_img_fd;
	}

	if (lseek(img_fd, 0, SEEK_SET) != 0)
	{
		pr_error_info("lseek");

		ret = -EFAULT;
		goto out_close_img_fd;
	}

	ret = cavan_sha_update2(context, img_fd);
	if (ret < 0)
	{
		pr_red_info("cavan_sha_update2");
		goto out_close_img_fd;
	}

	*size = wrlen;

out_close_img_fd:
	close(img_fd);
	return ret;
}
Beispiel #2
0
int cavan_sha_update3(struct cavan_sha_context *context, const char *pathname)
{
	int fd;
	int ret;

	fd = open(pathname, O_RDONLY);
	if (fd < 0) {
		pr_error_info("open file %s", pathname);
		return fd;
	}

	ret = cavan_sha_update2(context, fd);

	close(fd);

	return ret;
}