Age | Commit message (Collapse) | Author |
|
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
The mtd_get_dev_info1 function reads (among other things) name and type
string into coresponding struct mtd_dev_info fields.
The struct mtd_dev_info has the string fields marked const, requiring
them to be cast to non-const version during initialization.
This cast was previously omitted from the dev_read_data calls,
triggering warnings during compilation.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
|
|
This patch fixes the return status of the mtd_torture function
in libmtd.
The torture test function is currently only used by the ubiformat
utility to check if a block is bad after a write fails (blocks are
marked bad if the function returns an error status). However, the
way the function was written, it ALWAYS returns an error value
regardless of whether it failed or not.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
Assuming the read() call does not return zero and the result is less
than len, the current implementation will overwrite the data already
read in buf which doesn't seem correct.
With this patch, subsequent calls to read() within the loop will now no
longer overwrite the existing contents of buf.
Signed-off-by: Marcus Prebble <marcus.prebble@axis.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
Fixes compilation on hosts with the musl C library.
Also drops the unused u_short typedef.
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
ioctl(MEMGETREGIONINFO) has one input parameter (regionindex) and three
output parameters (info about the erase region). There are two problems
in mtdinfo/libmtd here:
1. mtdinfo.c doesn't initialize its region_info_user struct, instead
passing uninitialized data to mtd_regioninfo()
2. mtd_regioninfo() fails to utilize the 'regidx' parameter to fill out
the regionindex parameter properly, so the garbage from mtdinfo.c is
propagated to the ioctl()
This means that mtdinfo will continuously probe the same (possibly
out-of-range) erase region, instead of looping over the valid regions.
Let's fix this in the mtd_regioninfo() helper, and at the same time,
let's zero out the mtdinfo.c buffer, as an additional precaution to keep
from using uninitialized data.
Initial error report from Yang, when running "mtdinfo /dev/mtd0" on a
Cavium 6100 board:
root@CN61XX:~# mtdinfo /dev/mtd0
mtd0
Name: phys_mapped_flash
Type: nor
Eraseblock size: 65536 bytes, 64.0 KiB
Amount of eraseblocks: 128 (8388608 bytes, 8.0 MiB)
Minimum input/output unit size: 1 byte
Sub-page size: 1 byte
Additional erase regions: 0
Character device major/minor: 90:0
Bad blocks are allowed: false
Device is writable: true
libmtd: error!: MEMGETREGIONINFO ioctl failed for erase region 0
error 22 (Invalid argument)
Eraseblock region 0: info is unavailable
libmtd: error!: MEMGETREGIONINFO ioctl failed for erase region 1
error 22 (Invalid argument)
Eraseblock region 1: info is unavailable
Reported-by: Yang Wei <Wei.Yang@windriver.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
On legacy systems, if "/proc/mtd" doesn't exist or gives a read error,
mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary
to what's specified in the header file.
This causes checks like
if (mtd_dev_present(n)) {
...
}
to give false positives. Fix this by comparing the return value to 1.
Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
In the current code, the MTD_NANDFLASH stands for both the SLC and MLC.
In the kernel, the MTD_NANDFLASH only stands for the SLC now,
so in order to keep the logic unchanged, we should also check the MLC
NAND by MTD_MLCNANDFLASH.
Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
The MTD_MLCNANDFLASH case is missed in the current code.
This patch adds it.
Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
|
|
We should use the off_t type instead of off64_t or u_int32_t as its
length is controlled by the WITHOUT_LARGEFILE flag.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
On legacy kernels with ROM devices, we can get mtdinfo errors like:
libmtd: error!: cannot open "/dev/mtd4"
error 13 (Permission denied)
mtdinfo: error!: libmtd failed get MTD device 4 information
error 13 (Permission denied)
We don't need O_RDRW access for informational ioctls(), so make this
O_RDONLY.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
If we don't check for the MTD before calling `legacy_get_dev_info1', we may
get errors like:
libmtd: MTD subsystem is old and does not support sysfs, so MTD character device nodes have to exist
libmtd: error!: "/dev/mtd2" is not a character device
mtdinfo: error!: libmtd failed get MTD device 2 information
error 22 (Invalid argument)
So reverse the order of these two checks.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
ioctl(MEMWRITE) is implemented with memdup_user(), and so it allocates
kernel memory in contiguous regions. This limits its usefulness for large
amounts of data, since contiguous kernel memory can become scarce. I have
experienced "out of memory" problems with ubiformat, for instance, which
writes in eraseblock-sized regions:
...
ubiformat: flashing eraseblock 12 -- 72 % complete
ubiformat: page allocation failure.
order:8, mode:0xd0
Call Trace:
[<8043fa7c>] dump_stack+0x8/0x34
[<8008c940>] __alloc_pages_nodemask+0x408/0x618
[<800bd748>] cache_alloc_refill+0x400/0x730
[<800bdbbc>] __kmalloc+0x144/0x154
[<8009cae4>] memdup_user+0x24/0x94
[<802d04e4>] mtd_ioctl+0xba8/0xbd0
[<802d0544>] mtd_unlocked_ioctl+0x38/0x5c
[<800d43c0>] do_vfs_ioctl+0xa4/0x6e4
[<800d4a44>] sys_ioctl+0x44/0xa0
[<8000f95c>] stack_done+0x20/0x40
...
libmtd: error!: MEMWRITE ioctl failed for eraseblock 12 (mtd0)
error 12 (Cannot allocate memory)
ubiformat: error!: cannot write eraseblock 12
error 12 (Cannot allocate memory)
This error can be mitigated for now by only using ioctl(MEMWRITE) when we
need to write OOB data, since we can only do this in small transactions
anyway. Then, data-only transactions (like those originating from
ubiformat) can be carried out with write() calls.
This issue can also be solved within the kernel ioctl(), but either way,
this patch is still useful, since write() is more straightforward (and
efficient?) than ioctl() for data-only writes.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
Legacy systems do not initialize lib->mtd, so we shouldn't perform
strlen(lib->mtd); this produces a segmentation fault. As this code isn't
used in the legacy codepath, we can just move it down to an 'else' branch.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
Implement the 'legacy_dev_present()' function which will check whether an MTD
device is present by scanning the /proc/mtd file when the MTD subsystem does
not support sysfs (the case for pre-2.6.30 kernels).
This patch also moves the 'mtd_dev_present()' function to a slightly more
logical position.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
Will be used for `mtdinfo --all'
Artem: add a temporary stub for pre-2.6.30 kernels.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
|
|
When compiling mtd-utils against Android's bionic libc using the
supplied cross compiler environment it errors:
lib/libmtd.c: In function 'dev_node2num':
lib/libmtd.c:444: error: called object 'major' is not a function
lib/libmtd.c:445: error: called object 'minor' is not a function
lib/libmtd.c: In function 'mtd_probe_node':
lib/libmtd.c:1384: error: called object 'major' is not a function
lib/libmtd.c:1385: error: called object 'minor' is not a function
This patch updates the variable names for "major" and "minor" in two
places. It then compiles cleanly.
Artem: pick different names, also rename major1/minor1 variables for
consistency.
Signed-off-by: Thomas Cannon <mail at thomascannon.net>
Cc: linux-mtd at lists.infradead.org
|
|
MEMWRITE is a recently introduced write interface for MTD; however, it
is only supported on NAND flash. mtd-utils should fall back to
old write methods when either ENOTTY or EOPNOTSUPP are returned.
This is a showstopper when, for instance, using ubiformat on NOR, which
don't have a mtd->write_oob interface (and thus don't support MEMWRITE):
ubiformat: formatting eraseblock 2 -- 1 % complete libmtd: error!: MEMWRITE ioctl failed for eraseblock 2 (mtd3)
error 122 (Operation not supported)
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
|
|
With the addition of the the new ioctl(MEMWRITE), we can use the
kernel's internal OOB autoplacement option. It's a cleaner interface and
avoids too much duplication of coding effort.
This patch moves any legacy code (using MEMGETOOBSEL) into a legacy
function in libmtd.c. It's not exactly a "pre-2.6.30" feature, so I'm not
moving it to libmtd_legacy.c.
Now, autoplacement features are only activated if we call mtd_write with
mode == MTD_OPS_AUTO_OOB. This should fix some discrepancies for
nandwrite, where we weren't handling OOB consistently (i.e., we had
different functionality when the kernel did/didn't support MEMWRITE).
But that also means that we now default to using MTD_OPS_PLACE_OOB
instead of AUTO layout. To re-enable autoplacement, we can re-implement
the `--autoplace' option that had previously rotted.
This patch also cleans up a need for an extra OOB buffer in nandwrite.
This has been tested a little in nandsim as well as on SLC NAND flash.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
`mtd_write()' now will first attempt to use MEMWRITE. Then, if that
doesn't exist, it will attempt to fall back to old methods for writing
OOB and/or page data.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
To support the MEMWRITE ioctl, we will need a different sort of libmtd
interface for writing to flash. We will expand mtd_write to include more
functionality; for now, we just change the function definition and
description as we begin to add the actual functionality.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
|
|
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
|
|
The ubi-utils/src/ subdir is tossed as it just complicates things for no
real gain. The dictionary.h header is relocated to the ubi-utils/include/
since other headers in there need it.
The top level clean is replaced with a `find -delete` on objects, so it
might prune more than necessary, but many projects now do this sort of
thing and no one complained there.
A "mkdep" helper generates the actual rule, and the variables are used
with "foreach" to expand these automatically.
The tests subdir is updated only to reflect the ubi-utils source move.
Otherwise, it is left untouched as making that non-recursive isn't really
worth the effort.
While we're gutting things, also through in kbuild style output while
building to make things more legible.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
|
|
The libcrc32.a is only used in one place: mkfs.ubifs. But this also
uses libmtd.a, and the only file in libcrc32.a is also in libmtd.a.
So libcrc32.a itself is completely redundant. Punt!
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This patch first of all, re-names 'mtd_islocked()' into 'mtd_is_locked()' since
this seems to be the name Mike wanted, and it looks a bit nicer.
This patch also makes 'mtd_is_locked()' print an error message if it fails. I'm
not sure if it is good idea for a library to do so, but all functions do this,
so it certainly _not_ a good idea to be inconsistent.
However, for the special case, when the the "is locked" ioctl is not supported
or is not valid for this device, we do not print an error message and return
ENOTSUPP error code.
Thus, the user can distinguish between real errors and non-fatal "not
supported" cases.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This extends the libmtd with the helper functions:
mtd_regioninfo: interface to MEMGETREGIONINFO
mtd_islocked: interface to MEMISLOCKED
Users of these functions will follow shortly ...
Artem: do not print error message in mtd_islocked()
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Not strictly necessary, but this is good library behavior and
should carry no runtime overhead.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
When reading and writing OOB we specify the address as absolute
offset from the beginning of the MTD device. This offset is
basically an absolute page offset plus the OOB offset. And it does
not have to be aligned to the min. I/O unit size (NAND page size).
So fix the 'do_oob_op()' function and remove incorrect checking
that the offset is page-aligned. This check leads to the following
errors:
libmtd: error!: unaligned address 2, mtd0 page size is 2048
But obviously, the intent was to write to offset 2 of the OOB area
of the very first NAND page.
Instead of that incorrect check, we should check that the OOB offset
we write to is within the OOB size and the length is withing the OOB
size. This patch adds such check.
Reported-by: Kelly Anderson <kelly@silka.with-linux.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tested-by: Kelly Anderson <kelly@silka.with-linux.com>
|
|
legacy_get_dev_info() forgot to set the OOB size
Signed-off-by: Ketil Froyn <ketil@froyn.name>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This converts libmtd to the common xalloc helpers and in doing so, makes
memory allocation failures fatal rather than returning an error to the
caller. I think this is acceptable behavior.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Since these functions take no parameters, declare them as such. The
subtle difference here is that gcc allows (without warning) people to
accidentally call funcs declared with "()" with arguments. Using void
makes sure that gcc will reject such typos at compile time.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
By using the same error message string, we only need one copy of it
in memory at runtime.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
The current fec code casts a pointer to an int which causes warnings on
64bit systems. So create a macro for the duplicate/complicated magic
computation, and add an unsigned long cast in it to fix the original
problem.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
libcrc32.a was generated without external symbols: nm -g libcrc32.a shoed
nothing. This patch fixes it to make libcrc32.a build to be the same as
libmtd.a. Frankly, I do not know why this happened and why this patch fixes
the issue, sorry for my ignorance. But this works.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Because of namespace collisions mkfs.ubifs uses crc32() implementation from
/lib/libz.so.1, which generates incompatible CRC and later on the kernel reports
many CRC errors.
Fix this by re-naming mtd-utils' crc32 function to mtd_crc32.
Reported-by: Jon Povey <Jon.Povey@racelogic.co.uk>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Fixed several compiler warnings, mainly when compiling on 64-bit
architectures (where "size_t"-related types are not necessarily
32-bit).
Signed-off-by: Brian Norris <norris@broadcom.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
gcc 4.4.3 on x86_64:
libcrc32.c:42: warning: ‘static’ is not at beginning of declaration
libfec.c:120: warning: initialization discards qualifiers from pointer target type
libfec.c:121: warning: initialization discards qualifiers from pointer target type
libfec.c:417: warning: passing argument 2 of ‘my_malloc’ discards qualifiers from pointer target type
recv_image.c:164: warning: comparison of unsigned expression < 0 is always false
recv_image.c:170: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’
recv_image.c:170: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘long unsigned int’
And many more along the same lines.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This patch is based on Kevin Cernekee's patch posted to the MTD mailing
list. It adds 'mtd_read_oob()' and 'mtd_write_oob()' interfaces support.
The interfaces use MEMREADOOB64/MEMWRITEOOB64 MTD ioctls if possible, and
fall-back to MEMREADOOB/MEMWRITEOOB if the 64-bit versions are not supported.
The information about ioctls support is then cashed in 'offs64_ioctls'
libmtd flag.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
This patch is base on Kevin Cernekee's patch posted to the MTD mailing
list. It adds MEMERASE64 support to the 'mtd_erase()' call. Now it
first tries to use MEMERASE64, and if that is not supported, falls
back to the old MEMERASE ioctl.
This patch also introduces an 'offs64_ioctl' flag to the libmtd
descriptor. However, we cannot initialize it in 'libmtd_open()',
because we need an MTD device node, which we do not have in
'libmtd_open()'. Thus, we firs mark this flag as "uninitialized",
and at the first invocation of 'mtd_erase()' we initialize it.
This also means that we have to pass the limbtd descriptor to
'mtd_erase()', to save the flag value. This, in turn, requires
tweaking 'mtd_erase()' users.
This is not very nice, but good enough so far.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
My fault, forgot to run git add.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|
|
Source files for libmtd, crc32, and fec are scattered throughout the
tree. Move them to a central location so they can be built into a
common "libmtd.a" library used by all mtd-utils programs.
This patch only renames/deletes files and does not change the content.
Also modify the build system and source code so that libmtd.a can be built
from a "common" location (lib/). Statically link all utilities at the top
level with libmtd.a . Minor changes to mkfs.ubifs to allow using the common
crc32 implementation.
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
|