static int blk_read(void *buf, int len, const char *path, int offset) { void *handle; int ret; ret = bchlib_setup(path, true, &handle); if (ret) { return ret; } ret = bchlib_read(handle, buf, offset, len); bchlib_teardown(handle); return ret; }
static void dd_infcloseblk(struct dd_s *dd) { (void)bchlib_teardown(DD_INHANDLE); }
static void dd_outfcloseblk(struct dd_s *dd) { (void)bchlib_teardown(DD_OUTHANDLE); }
static int install_recovery(const char *srcpath) { int rfd, i, len, rem; int ret = 0; void *handle = NULL; if (bchlib_setup(CONFIG_MTD_RECOVERY_DEVPATH, false, &handle)) { return -1; } rfd = open(srcpath, O_RDONLY, 0444); if (read(rfd, &upg_image, sizeof(upg_image)) != sizeof(upg_image)) { _info("read head"); ret = -EIO; goto err; } #ifdef IMG_SIGNATURE if (upg_image.sig != IMG_SIGNATURE) { _info("image signature missmatch. IPL2=%u, UPG=%u\n", IMG_SIGNATURE, upg_image.sig); _info("go normal boot\n"); memset(copybuf, 0, sizeof(copybuf)); snprintf(copybuf, sizeof(copybuf), "normal"); set_config(1, copybuf); sysreset(); /* NOT REACHED */ } #endif for (i = 0; i < upg_image.chunknum; i++) { if (!strcmp(basename(upg_image.chunk[i].fname), "recovery")) { break; } } if (i == upg_image.chunknum) { _info("recovery not found\n"); ret = -ENOENT; goto err; } lseek(rfd, upg_image.chunk[i].offset + ((void *)&upg_image.chunk[upg_image.chunknum] - (void *)&upg_image), SEEK_SET); rem = upg_image.chunk[i].size; while (rem > 0) { len = read(rfd, copybuf, rem > 512 ? 512 : rem); if (len < 0) { _info("read image"); ret = -EIO; goto err; } bchlib_write(handle, copybuf, upg_image.chunk[i].size - rem, len); rem -= len; } err: if (handle) { bchlib_teardown(handle); } close(rfd); _info("DONE\n"); return ret; }