Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nuttx-apps
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
f4grx
nuttx-apps
Commits
11d87d9e
Commit
11d87d9e
authored
11 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
Changes to get the MTD test working
parent
469c5e62
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
examples/mtdpart/mtdpart_main.c
+72
-29
72 additions, 29 deletions
examples/mtdpart/mtdpart_main.c
with
72 additions
and
29 deletions
examples/mtdpart/mtdpart_main.c
+
72
−
29
View file @
11d87d9e
...
...
@@ -156,6 +156,7 @@ int mtdpart_main(int argc, char *argv[])
FAR
uint32_t
*
buffer
;
char
blockname
[
32
];
char
charname
[
32
];
size_t
partsize
;
ssize_t
nbytes
;
off_t
nblocks
;
off_t
offset
;
...
...
@@ -217,27 +218,39 @@ int mtdpart_main(int argc, char *argv[])
}
message
(
"Flash Geometry:
\n
"
);
message
(
" blocksize:
%uld
\n
"
,
(
unsigned
long
)
geo
.
blocksize
);
message
(
" erasesize:
%uld
\n
"
,
(
unsigned
long
)
geo
.
erasesize
);
message
(
" neraseblocks:
%uld
\n
"
,
(
unsigned
long
)
geo
.
neraseblocks
);
message
(
" blocksize:
%lu
\n
"
,
(
unsigned
long
)
geo
.
blocksize
);
message
(
" erasesize:
%lu
\n
"
,
(
unsigned
long
)
geo
.
erasesize
);
message
(
" neraseblocks:
%lu
\n
"
,
(
unsigned
long
)
geo
.
neraseblocks
);
/* Determine the size of each partition */
/* Determine the size of each partition. Make each partition an even
* multiple of the erase block size (perhaps not using some space at the
* end of the FLASH).
*/
blkpererase
=
geo
.
erasesize
/
geo
.
blocksize
;
nblocks
=
geo
.
neraseblocks
*
blkpererase
/
CONFIG_EXAMPLES_MTDPART_NPARTITIONS
;
nblocks
=
(
geo
.
neraseblocks
/
CONFIG_EXAMPLES_MTDPART_NPARTITIONS
)
*
blkpererase
;
partsize
=
nblocks
*
geo
.
blocksize
;
message
(
" No. partitions: %u
\n
"
,
CONFIG_EXAMPLES_MTDPART_NPARTITIONS
);
message
(
" Partition size: %lu Blocks (%lu bytes)
\n
"
,
nblocks
,
partsize
);
/* Now create MTD FLASH partitions */
message
(
"Creating partitions
\n
"
);
for
(
offset
=
0
,
i
=
1
;
i
<=
CONFIG_EXAMPLES_MTDPART_NPARTITIONS
;
offset
+=
nblocks
,
i
++
)
{
message
(
" Partition %d. Block offset=%lu, size=%lu
\n
"
,
i
,
(
unsigned
long
)
offset
,
(
unsigned
long
)
nblocks
);
/* Create the partition */
part
[
i
]
=
mtd_partition
(
master
,
offset
,
nblocks
);
if
(
!
part
[
i
])
{
message
(
"ERROR: mtd_partition failed. offset=%u
ld
nblocks=%u
ld
\n
"
,
message
(
"ERROR: mtd_partition failed. offset=%
l
u nblocks=%
l
u
\n
"
,
(
unsigned
long
)
offset
,
(
unsigned
long
)
nblocks
);
msgflush
();
exit
(
4
);
...
...
@@ -289,6 +302,8 @@ int mtdpart_main(int argc, char *argv[])
/* Now write the offset into every block */
message
(
"Initializing media:
\n
"
);
offset
=
0
;
for
(
i
=
0
;
i
<
geo
.
neraseblocks
;
i
++
)
{
...
...
@@ -318,10 +333,15 @@ int mtdpart_main(int argc, char *argv[])
/* Now read each partition */
message
(
"Checking partitions:
\n
"
);
for
(
offset
=
0
,
i
=
1
;
i
<=
CONFIG_EXAMPLES_MTDPART_NPARTITIONS
;
offset
+=
nblocks
,
i
++
)
offset
+=
partsize
,
i
++
)
{
message
(
" Partition %d. Byte offset=%lu, size=%lu
\n
"
,
i
,
(
unsigned
long
)
offset
,
(
unsigned
long
)
partsize
);
/* Open the master MTD partition character driver for writing */
snprintf
(
charname
,
32
,
"/dev/mtd%d"
,
i
);
...
...
@@ -336,35 +356,57 @@ int mtdpart_main(int argc, char *argv[])
/* Now verify the offset in every block */
check
=
offset
;
for
(
i
=
0
;
i
<
nblocks
;
i
++
)
for
(
j
=
0
;
j
<
nblocks
;
j
++
)
{
for
(
j
=
0
;
j
<
blkpererase
;
j
++
)
#if 0 /* Too much */
message(" block=%u offset=%lu\n", j, (unsigned long) check);
#endif
/* Read the next block into memory */
nbytes
=
read
(
fd
,
buffer
,
geo
.
blocksize
);
if
(
nbytes
<
0
)
{
/* Read the next block into memory */
message
(
"ERROR: read from %s failed: %d
\n
"
,
charname
,
errno
);
msgflush
();
exit
(
11
);
}
nbytes
=
read
(
fd
,
buffer
,
geo
.
blocksize
);
if
(
nbytes
<
0
)
{
message
(
"ERROR: read from %s failed: %d
\n
"
,
charname
,
errno
);
msgflush
();
exit
(
11
);
}
/* Since we forced the size of the partition to be an even number
* of erase blocks, we do not expect to encounter the end of file
* indication.
*/
/* Verfy the offsets in the block */
else
if
(
nbytes
==
0
)
{
message
(
"ERROR: Unexpected end of file on %s
\n
"
,
charname
);
msgflush
();
exit
(
11
);
}
check
=
offset
;
for
(
k
=
0
;
k
<
geo
.
blocksize
/
sizeof
(
uint32_t
);
k
++
)
/* This is not expected at all */
else
if
(
nbytes
!=
geo
.
blocksize
)
{
message
(
"ERROR: Short read from %s failed: %lu
\n
"
,
charname
,
(
unsigned
long
)
nbytes
);
msgflush
();
exit
(
11
);
}
/* Verfy the offsets in the block */
for
(
k
=
0
;
k
<
geo
.
blocksize
/
sizeof
(
uint32_t
);
k
++
)
{
if
(
buffer
[
k
]
!=
check
)
{
if
(
buffer
[
k
]
!=
check
)
{
message
(
"ERROR: Bad offset %uld, expected %uld
\n
"
,
buffer
[
k
],
check
);
msgflush
();
exit
(
12
);
}
check
+=
4
;
message
(
"ERROR: Bad offset %lu, expected %lu
\n
"
,
(
long
)
buffer
[
k
],
(
long
)
check
);
msgflush
();
exit
(
12
);
}
check
+=
4
;
}
}
...
...
@@ -373,6 +415,7 @@ int mtdpart_main(int argc, char *argv[])
/* And exit without bothering to clean up */
message
(
"PASS: Everything looks good
\n
"
);
msgflush
();
return
0
;
}
...
...
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