Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
u-boot-2015.04
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vesta
u-boot-2015.04
Commits
62043ed0
Commit
62043ed0
authored
14 years ago
by
Wolfgang Denk
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
git://git.denx.de/u-boot-ubi
parents
9063fda9
7f5d8a4d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/cmd_ubi.c
+65
-72
65 additions, 72 deletions
common/cmd_ubi.c
with
65 additions
and
72 deletions
common/cmd_ubi.c
+
65
−
72
View file @
62043ed0
...
@@ -123,7 +123,7 @@ static int ubi_info(int layout)
...
@@ -123,7 +123,7 @@ static int ubi_info(int layout)
static
int
verify_mkvol_req
(
const
struct
ubi_device
*
ubi
,
static
int
verify_mkvol_req
(
const
struct
ubi_device
*
ubi
,
const
struct
ubi_mkvol_req
*
req
)
const
struct
ubi_mkvol_req
*
req
)
{
{
int
n
,
err
=
-
EINVAL
;
int
n
,
err
=
EINVAL
;
if
(
req
->
bytes
<
0
||
req
->
alignment
<
0
||
req
->
vol_type
<
0
||
if
(
req
->
bytes
<
0
||
req
->
alignment
<
0
||
req
->
vol_type
<
0
||
req
->
name_len
<
0
)
req
->
name_len
<
0
)
...
@@ -136,8 +136,11 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
...
@@ -136,8 +136,11 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
if
(
req
->
alignment
==
0
)
if
(
req
->
alignment
==
0
)
goto
bad
;
goto
bad
;
if
(
req
->
bytes
==
0
)
if
(
req
->
bytes
==
0
)
{
printf
(
"No space left in UBI device!
\n
"
);
err
=
ENOMEM
;
goto
bad
;
goto
bad
;
}
if
(
req
->
vol_type
!=
UBI_DYNAMIC_VOLUME
&&
if
(
req
->
vol_type
!=
UBI_DYNAMIC_VOLUME
&&
req
->
vol_type
!=
UBI_STATIC_VOLUME
)
req
->
vol_type
!=
UBI_STATIC_VOLUME
)
...
@@ -151,13 +154,13 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
...
@@ -151,13 +154,13 @@ static int verify_mkvol_req(const struct ubi_device *ubi,
goto
bad
;
goto
bad
;
if
(
req
->
name_len
>
UBI_VOL_NAME_MAX
)
{
if
(
req
->
name_len
>
UBI_VOL_NAME_MAX
)
{
err
=
-
ENAMETOOLONG
;
printf
(
"Name too long!
\n
"
);
err
=
ENAMETOOLONG
;
goto
bad
;
goto
bad
;
}
}
return
0
;
return
0
;
bad:
bad:
printf
(
"bad volume creation request"
);
return
err
;
return
err
;
}
}
...
@@ -191,34 +194,39 @@ static int ubi_create_vol(char *volume, int size, int dynamic)
...
@@ -191,34 +194,39 @@ static int ubi_create_vol(char *volume, int size, int dynamic)
return
ubi_create_volume
(
ubi
,
&
req
);
return
ubi_create_volume
(
ubi
,
&
req
);
}
}
static
in
t
ubi_
remove
_vol
(
char
*
volume
)
static
struc
t
ubi_
volume
*
ubi_find
_vol
ume
(
char
*
volume
)
{
{
int
i
,
err
,
reserved_pebs
;
int
found
=
0
,
vol_id
=
0
;
struct
ubi_volume
*
vol
=
NULL
;
struct
ubi_volume
*
vol
=
NULL
;
int
i
;
for
(
i
=
0
;
i
<
ubi
->
vtbl_slots
;
i
++
)
{
for
(
i
=
0
;
i
<
ubi
->
vtbl_slots
;
i
++
)
{
vol
=
ubi
->
volumes
[
i
];
vol
=
ubi
->
volumes
[
i
];
if
(
vol
&&
!
strcmp
(
vol
->
name
,
volume
))
{
if
(
vol
&&
!
strcmp
(
vol
->
name
,
volume
))
printf
(
"Volume %s found at valid %d
\n
"
,
volume
,
i
);
return
vol
;
vol_id
=
i
;
found
=
1
;
break
;
}
}
}
if
(
!
found
)
{
printf
(
"%s volume not found
\n
"
,
volume
);
printf
(
"Volume %s not found!
\n
"
,
volume
);
return
-
ENODEV
;
return
NULL
;
}
}
printf
(
"remove UBI volume %s (id %d)
\n
"
,
vol
->
name
,
vol
->
vol_id
);
static
int
ubi_remove_vol
(
char
*
volume
)
{
int
err
,
reserved_pebs
,
i
;
struct
ubi_volume
*
vol
;
vol
=
ubi_find_volume
(
volume
);
if
(
vol
==
NULL
)
return
ENODEV
;
printf
(
"Remove UBI volume %s (id %d)
\n
"
,
vol
->
name
,
vol
->
vol_id
);
if
(
ubi
->
ro_mode
)
{
if
(
ubi
->
ro_mode
)
{
printf
(
"It's read-only mode
\n
"
);
printf
(
"It's read-only mode
\n
"
);
err
=
-
EROFS
;
err
=
EROFS
;
goto
out_err
;
goto
out_err
;
}
}
err
=
ubi_change_vtbl_record
(
ubi
,
vol_id
,
NULL
);
err
=
ubi_change_vtbl_record
(
ubi
,
vol
->
vol_id
,
NULL
);
if
(
err
)
{
if
(
err
)
{
printf
(
"Error changing Vol tabel record err=%x
\n
"
,
err
);
printf
(
"Error changing Vol tabel record err=%x
\n
"
,
err
);
goto
out_err
;
goto
out_err
;
...
@@ -231,8 +239,8 @@ static int ubi_remove_vol(char *volume)
...
@@ -231,8 +239,8 @@ static int ubi_remove_vol(char *volume)
}
}
kfree
(
vol
->
eba_tbl
);
kfree
(
vol
->
eba_tbl
);
ubi
->
volumes
[
vol_id
]
->
eba_tbl
=
NULL
;
ubi
->
volumes
[
vol
->
vol
_id
]
->
eba_tbl
=
NULL
;
ubi
->
volumes
[
vol_id
]
=
NULL
;
ubi
->
volumes
[
vol
->
vol
_id
]
=
NULL
;
ubi
->
rsvd_pebs
-=
reserved_pebs
;
ubi
->
rsvd_pebs
-=
reserved_pebs
;
ubi
->
avail_pebs
+=
reserved_pebs
;
ubi
->
avail_pebs
+=
reserved_pebs
;
...
@@ -249,56 +257,46 @@ static int ubi_remove_vol(char *volume)
...
@@ -249,56 +257,46 @@ static int ubi_remove_vol(char *volume)
return
0
;
return
0
;
out_err:
out_err:
ubi_err
(
"cannot remove volume %d, error %d"
,
vol_id
,
err
);
ubi_err
(
"cannot remove volume %s, error %d"
,
volume
,
err
);
if
(
err
<
0
)
err
=
-
err
;
return
err
;
return
err
;
}
}
static
int
ubi_volume_write
(
char
*
volume
,
void
*
buf
,
size_t
size
)
static
int
ubi_volume_write
(
char
*
volume
,
void
*
buf
,
size_t
size
)
{
{
int
i
=
0
,
err
=
-
1
;
int
err
=
1
;
int
rsvd_bytes
=
0
;
int
rsvd_bytes
=
0
;
int
found
=
0
;
struct
ubi_volume
*
vol
;
struct
ubi_volume
*
vol
;
for
(
i
=
0
;
i
<
ubi
->
vtbl_slots
;
i
++
)
{
vol
=
ubi_find_volume
(
volume
);
vol
=
ubi
->
volumes
[
i
];
if
(
vol
==
NULL
)
if
(
vol
&&
!
strcmp
(
vol
->
name
,
volume
))
{
return
ENODEV
;
printf
(
"Volume
\"
%s
\"
found at volume id %d
\n
"
,
volume
,
i
);
found
=
1
;
break
;
}
}
if
(
!
found
)
{
printf
(
"%s volume not found
\n
"
,
volume
);
return
1
;
}
rsvd_bytes
=
vol
->
reserved_pebs
*
(
ubi
->
leb_size
-
vol
->
data_pad
);
rsvd_bytes
=
vol
->
reserved_pebs
*
(
ubi
->
leb_size
-
vol
->
data_pad
);
if
(
size
<
0
||
size
>
rsvd_bytes
)
{
if
(
size
<
0
||
size
>
rsvd_bytes
)
{
printf
(
"rsvd_bytes=%d vol->reserved_pebs=%d ubi->leb_size=%d
\n
"
,
printf
(
"size > volume size! Aborting!
\n
"
);
rsvd_bytes
,
vol
->
reserved_pebs
,
ubi
->
leb_size
);
return
EINVAL
;
printf
(
"vol->data_pad=%d
\n
"
,
vol
->
data_pad
);
printf
(
"Size > volume size !!
\n
"
);
return
1
;
}
}
err
=
ubi_start_update
(
ubi
,
vol
,
size
);
err
=
ubi_start_update
(
ubi
,
vol
,
size
);
if
(
err
<
0
)
{
if
(
err
<
0
)
{
printf
(
"Cannot start volume update
\n
"
);
printf
(
"Cannot start volume update
\n
"
);
return
err
;
return
-
err
;
}
}
err
=
ubi_more_update_data
(
ubi
,
vol
,
buf
,
size
);
err
=
ubi_more_update_data
(
ubi
,
vol
,
buf
,
size
);
if
(
err
<
0
)
{
if
(
err
<
0
)
{
printf
(
"Couldnt or partially wrote data
\n
"
);
printf
(
"Couldnt or partially wrote data
\n
"
);
return
err
;
return
-
err
;
}
}
if
(
err
)
{
if
(
err
)
{
size
=
err
;
size
=
err
;
err
=
ubi_check_volume
(
ubi
,
vol
->
vol_id
);
err
=
ubi_check_volume
(
ubi
,
vol
->
vol_id
);
if
(
err
<
0
)
if
(
err
<
0
)
return
err
;
return
-
err
;
if
(
err
)
{
if
(
err
)
{
ubi_warn
(
"volume %d on UBI device %d is corrupted"
,
ubi_warn
(
"volume %d on UBI device %d is corrupted"
,
...
@@ -310,47 +308,39 @@ static int ubi_volume_write(char *volume, void *buf, size_t size)
...
@@ -310,47 +308,39 @@ static int ubi_volume_write(char *volume, void *buf, size_t size)
ubi_gluebi_updated
(
vol
);
ubi_gluebi_updated
(
vol
);
}
}
printf
(
"%d bytes written to volume %s
\n
"
,
size
,
volume
);
return
0
;
return
0
;
}
}
static
int
ubi_volume_read
(
char
*
volume
,
char
*
buf
,
size_t
size
)
static
int
ubi_volume_read
(
char
*
volume
,
char
*
buf
,
size_t
size
)
{
{
int
err
,
lnum
,
off
,
len
,
tbuf_size
,
i
=
0
;
int
err
,
lnum
,
off
,
len
,
tbuf_size
;
size_t
count_save
=
size
;
size_t
count_save
=
size
;
void
*
tbuf
;
void
*
tbuf
;
unsigned
long
long
tmp
;
unsigned
long
long
tmp
;
struct
ubi_volume
*
vol
=
NULL
;
struct
ubi_volume
*
vol
;
loff_t
offp
=
0
;
loff_t
offp
=
0
;
for
(
i
=
0
;
i
<
ubi
->
vtbl_slots
;
i
++
)
{
vol
=
ubi_find_volume
(
volume
);
vol
=
ubi
->
volumes
[
i
];
if
(
vol
==
NULL
)
if
(
vol
&&
!
strcmp
(
vol
->
name
,
volume
))
{
return
ENODEV
;
printf
(
"Volume %s found at volume id %d
\n
"
,
volume
,
vol
->
vol_id
);
break
;
}
}
if
(
i
==
ubi
->
vtbl_slots
)
{
printf
(
"%s volume not found
\n
"
,
volume
);
return
-
ENODEV
;
}
printf
(
"read %i bytes from volume %d to %x(buf address)
\n
"
,
printf
(
"Read %d bytes from volume %s to %p
\n
"
,
size
,
volume
,
buf
);
(
int
)
size
,
vol
->
vol_id
,
(
unsigned
)
buf
);
if
(
vol
->
updating
)
{
if
(
vol
->
updating
)
{
printf
(
"updating"
);
printf
(
"updating"
);
return
-
EBUSY
;
return
EBUSY
;
}
}
if
(
vol
->
upd_marker
)
{
if
(
vol
->
upd_marker
)
{
printf
(
"damaged volume, update marker is set"
);
printf
(
"damaged volume, update marker is set"
);
return
-
EBADF
;
return
EBADF
;
}
}
if
(
offp
==
vol
->
used_bytes
)
if
(
offp
==
vol
->
used_bytes
)
return
0
;
return
0
;
if
(
size
==
0
)
{
if
(
size
==
0
)
{
printf
(
"
Read [%lu] bytes
\n
"
,
(
unsigned
long
)
vol
->
used_bytes
);
printf
(
"
No size specified -> Using max size (%lld)
\n
"
,
vol
->
used_bytes
);
size
=
vol
->
used_bytes
;
size
=
vol
->
used_bytes
;
}
}
...
@@ -365,7 +355,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
...
@@ -365,7 +355,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
tbuf
=
malloc
(
tbuf_size
);
tbuf
=
malloc
(
tbuf_size
);
if
(
!
tbuf
)
{
if
(
!
tbuf
)
{
printf
(
"NO MEM
\n
"
);
printf
(
"NO MEM
\n
"
);
return
-
ENOMEM
;
return
ENOMEM
;
}
}
len
=
size
>
tbuf_size
?
tbuf_size
:
size
;
len
=
size
>
tbuf_size
?
tbuf_size
:
size
;
...
@@ -379,6 +369,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
...
@@ -379,6 +369,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
err
=
ubi_eba_read_leb
(
ubi
,
vol
,
lnum
,
tbuf
,
off
,
len
,
0
);
err
=
ubi_eba_read_leb
(
ubi
,
vol
,
lnum
,
tbuf
,
off
,
len
,
0
);
if
(
err
)
{
if
(
err
)
{
printf
(
"read err %x
\n
"
,
err
);
printf
(
"read err %x
\n
"
,
err
);
err
=
-
err
;
break
;
break
;
}
}
off
+=
len
;
off
+=
len
;
...
@@ -397,7 +388,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
...
@@ -397,7 +388,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
}
while
(
size
);
}
while
(
size
);
free
(
tbuf
);
free
(
tbuf
);
return
err
?
err
:
count_save
-
size
;
return
err
;
}
}
static
int
ubi_dev_scan
(
struct
mtd_info
*
info
,
char
*
ubidev
,
static
int
ubi_dev_scan
(
struct
mtd_info
*
info
,
char
*
ubidev
,
...
@@ -427,13 +418,13 @@ static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
...
@@ -427,13 +418,13 @@ static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
err
=
ubi_mtd_param_parse
(
ubi_mtd_param_buffer
,
NULL
);
err
=
ubi_mtd_param_parse
(
ubi_mtd_param_buffer
,
NULL
);
if
(
err
)
{
if
(
err
)
{
del_mtd_partitions
(
info
);
del_mtd_partitions
(
info
);
return
err
;
return
-
err
;
}
}
err
=
ubi_init
();
err
=
ubi_init
();
if
(
err
)
{
if
(
err
)
{
del_mtd_partitions
(
info
);
del_mtd_partitions
(
info
);
return
err
;
return
-
err
;
}
}
ubi_initialized
=
1
;
ubi_initialized
=
1
;
...
@@ -565,8 +556,10 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
...
@@ -565,8 +556,10 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
argc
--
;
argc
--
;
}
}
/* Use maximum available size */
/* Use maximum available size */
if
(
!
size
)
if
(
!
size
)
{
size
=
ubi
->
avail_pebs
*
ubi
->
leb_size
;
size
=
ubi
->
avail_pebs
*
ubi
->
leb_size
;
printf
(
"No size specified -> Using max size (%u)
\n
"
,
size
);
}
/* E.g., create volume */
/* E.g., create volume */
if
(
argc
==
3
)
if
(
argc
==
3
)
return
ubi_create_vol
(
argv
[
2
],
size
,
dynamic
);
return
ubi_create_vol
(
argv
[
2
],
size
,
dynamic
);
...
@@ -610,7 +603,7 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
...
@@ -610,7 +603,7 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
}
}
printf
(
"Please see usage
\n
"
);
printf
(
"Please see usage
\n
"
);
return
-
1
;
return
1
;
}
}
U_BOOT_CMD
(
U_BOOT_CMD
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment