mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-21 04:14:34 +00:00
ubi: allow to write to volume with offset
Introduce ubi_volume_offset_write() helper, which allow to write to ubi volume with specified offset. Signed-off-by: Alexey Romanov <avromanov@salutedevices.com> Reviewed-by: Heiko Schocher <hs@denx.de> Acked-by: Heiko Schocher <hs@denx.de> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
This commit is contained in:
parent
cead69c528
commit
25ee9c2005
3 changed files with 75 additions and 9 deletions
72
cmd/ubi.c
72
cmd/ubi.c
|
@ -423,9 +423,75 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t size,
|
||||||
return ubi_volume_continue_write(volume, buf, size);
|
return ubi_volume_continue_write(volume, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ubi_volume_write(char *volume, void *buf, size_t size)
|
static int ubi_volume_offset_write(char *volume, void *buf, loff_t offset,
|
||||||
|
size_t size)
|
||||||
{
|
{
|
||||||
return ubi_volume_begin_write(volume, buf, size, size);
|
int len, tbuf_size, ret;
|
||||||
|
u64 lnum;
|
||||||
|
struct ubi_volume *vol;
|
||||||
|
loff_t off = offset;
|
||||||
|
void *tbuf;
|
||||||
|
|
||||||
|
vol = ubi_find_volume(volume);
|
||||||
|
if (!vol)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
if (size > vol->reserved_pebs * (ubi->leb_size - vol->data_pad))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
tbuf_size = vol->usable_leb_size;
|
||||||
|
tbuf = malloc_cache_aligned(tbuf_size);
|
||||||
|
if (!tbuf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
lnum = off;
|
||||||
|
off = do_div(lnum, vol->usable_leb_size);
|
||||||
|
|
||||||
|
do {
|
||||||
|
struct ubi_volume_desc desc = {
|
||||||
|
.vol = vol,
|
||||||
|
.mode = UBI_READWRITE,
|
||||||
|
};
|
||||||
|
|
||||||
|
len = size > tbuf_size ? tbuf_size : size;
|
||||||
|
if (off + len >= vol->usable_leb_size)
|
||||||
|
len = vol->usable_leb_size - off;
|
||||||
|
|
||||||
|
ret = ubi_read(&desc, (int)lnum, tbuf, 0, tbuf_size);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("Failed to read leb %lld (%d)\n", lnum, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(tbuf + off, buf, len);
|
||||||
|
|
||||||
|
ret = ubi_leb_change(&desc, (int)lnum, tbuf, tbuf_size);
|
||||||
|
if (ret) {
|
||||||
|
pr_err("Failed to write leb %lld (%d)\n", lnum, ret);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
off += len;
|
||||||
|
if (off >= vol->usable_leb_size) {
|
||||||
|
lnum++;
|
||||||
|
off -= vol->usable_leb_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf += len;
|
||||||
|
size -= len;
|
||||||
|
} while (size);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
free(tbuf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size)
|
||||||
|
{
|
||||||
|
if (!offset)
|
||||||
|
return ubi_volume_begin_write(volume, buf, size, size);
|
||||||
|
|
||||||
|
return ubi_volume_offset_write(volume, buf, offset, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
|
int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
|
||||||
|
@ -769,7 +835,7 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||||
(void *)addr, size, full_size);
|
(void *)addr, size, full_size);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = ubi_volume_write(argv[3], (void *)addr, size);
|
ret = ubi_volume_write(argv[3], (void *)addr, 0, size);
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
printf("%lld bytes written to volume %s\n", size,
|
printf("%lld bytes written to volume %s\n", size,
|
||||||
|
|
10
env/ubi.c
vendored
10
env/ubi.c
vendored
|
@ -53,7 +53,7 @@ static int env_ubi_save(void)
|
||||||
if (gd->env_valid == ENV_VALID) {
|
if (gd->env_valid == ENV_VALID) {
|
||||||
puts("Writing to redundant UBI... ");
|
puts("Writing to redundant UBI... ");
|
||||||
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
|
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
|
||||||
(void *)env_new, CONFIG_ENV_SIZE)) {
|
(void *)env_new, 0, CONFIG_ENV_SIZE)) {
|
||||||
printf("\n** Unable to write env to %s:%s **\n",
|
printf("\n** Unable to write env to %s:%s **\n",
|
||||||
CONFIG_ENV_UBI_PART,
|
CONFIG_ENV_UBI_PART,
|
||||||
CONFIG_ENV_UBI_VOLUME_REDUND);
|
CONFIG_ENV_UBI_VOLUME_REDUND);
|
||||||
|
@ -62,7 +62,7 @@ static int env_ubi_save(void)
|
||||||
} else {
|
} else {
|
||||||
puts("Writing to UBI... ");
|
puts("Writing to UBI... ");
|
||||||
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
|
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
|
||||||
(void *)env_new, CONFIG_ENV_SIZE)) {
|
(void *)env_new, 0, CONFIG_ENV_SIZE)) {
|
||||||
printf("\n** Unable to write env to %s:%s **\n",
|
printf("\n** Unable to write env to %s:%s **\n",
|
||||||
CONFIG_ENV_UBI_PART,
|
CONFIG_ENV_UBI_PART,
|
||||||
CONFIG_ENV_UBI_VOLUME);
|
CONFIG_ENV_UBI_VOLUME);
|
||||||
|
@ -92,7 +92,7 @@ static int env_ubi_save(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new,
|
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, 0,
|
||||||
CONFIG_ENV_SIZE)) {
|
CONFIG_ENV_SIZE)) {
|
||||||
printf("\n** Unable to write env to %s:%s **\n",
|
printf("\n** Unable to write env to %s:%s **\n",
|
||||||
CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
|
CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
|
||||||
|
@ -196,7 +196,7 @@ static int env_ubi_erase(void)
|
||||||
memset(env_buf, 0x0, CONFIG_ENV_SIZE);
|
memset(env_buf, 0x0, CONFIG_ENV_SIZE);
|
||||||
|
|
||||||
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
|
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
|
||||||
(void *)env_buf, CONFIG_ENV_SIZE)) {
|
(void *)env_buf, 0, CONFIG_ENV_SIZE)) {
|
||||||
printf("\n** Unable to erase env to %s:%s **\n",
|
printf("\n** Unable to erase env to %s:%s **\n",
|
||||||
CONFIG_ENV_UBI_PART,
|
CONFIG_ENV_UBI_PART,
|
||||||
CONFIG_ENV_UBI_VOLUME);
|
CONFIG_ENV_UBI_VOLUME);
|
||||||
|
@ -204,7 +204,7 @@ static int env_ubi_erase(void)
|
||||||
}
|
}
|
||||||
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
|
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
|
||||||
if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
|
if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
|
||||||
(void *)env_buf, CONFIG_ENV_SIZE)) {
|
(void *)env_buf, 0, CONFIG_ENV_SIZE)) {
|
||||||
printf("\n** Unable to erase env to %s:%s **\n",
|
printf("\n** Unable to erase env to %s:%s **\n",
|
||||||
CONFIG_ENV_UBI_PART,
|
CONFIG_ENV_UBI_PART,
|
||||||
ENV_UBI_VOLUME_REDUND);
|
ENV_UBI_VOLUME_REDUND);
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
|
||||||
extern int ubi_init(void);
|
extern int ubi_init(void);
|
||||||
extern void ubi_exit(void);
|
extern void ubi_exit(void);
|
||||||
extern int ubi_part(char *part_name, const char *vid_header_offset);
|
extern int ubi_part(char *part_name, const char *vid_header_offset);
|
||||||
extern int ubi_volume_write(char *volume, void *buf, size_t size);
|
extern int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size);
|
||||||
extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size);
|
extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size);
|
||||||
|
|
||||||
extern struct ubi_device *ubi_devices[];
|
extern struct ubi_device *ubi_devices[];
|
||||||
|
|
Loading…
Add table
Reference in a new issue