summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/core.c
Commit message (Collapse)AuthorAgeFilesLines
* nand command: Print OOB informationSascha Hauer2020-11-101-0/+81
| | | | | | | | NAND mtd devices carry information how the OOB area is used. So far there is no way to visualize it, so print it along with other NAND informations. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: nand: Update to Linux-5.9Sascha Hauer2020-11-101-29/+538
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This updates the barebox NAND layer and parts of the mtd layer to Linux-5.9. This patch is huge, but the barebox NAND layer is so far away from the Linux NAND layer that a step by step update would have taken ages. Unlike Linux barebox has functions to mark a block as good. This feature has been preserved. Also barebox used to make NAND write support optional, this feature is lost during the update for the sake of better compatibility to the Linux NAND layer. This patch has been tested: - GPMI aka nand_mxs on i.MX6 - nand_imx on i.MX25 - nand_omap_gpmc on AM335x - atmel_nand on Atmel sama5d3 - nand_denali on SoCFPGA Currently untested: - nand_orion - nand_mrvl_nfc - nand_s3c24xx The nand_denali driver is tested with the update of that driver to Linux-5.9 following in the next patch. I could only test the drivers with the NAND chips found on my boards, so there's still enough room for regressions, especially given that the NAND drivers themselves are mostly not updated. With the NAND layer being up-to-date with Linux it should hopefully be easy to update drivers to their Linux counterpart as well if necessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: rename master to parentSascha Hauer2020-11-091-6/+6
| | | | | | | In Linux mtd->parent is what in barebox is mtd->master. Rename this to get closer to the Linux mtd layer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: rename class_dev to devSascha Hauer2020-11-091-19/+19
| | | | | | | | The mtds own device is named 'dev' in the Kernel whereas it's named 'class_dev' in barebox. Rename it to 'dev' for better compatilibility to the Kernel. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Use classdev->parentSascha Hauer2020-11-091-6/+4
| | | | | | | | | | Instead of mtd->parent we can use mtd->classdev.parent which points to the same device. With this we can remove the 'parent' member of struct mtd_info. This member exists in the Linux kernel as well, but is of type struct mtd_info, so this is done as preparation to re-add mtd->parent with the same type as in Linux. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add underscore prefix to mtd hooksSascha Hauer2020-11-061-18/+18
| | | | | | | In the Kernel the mtd function hooks begin with an underscore. Do the same in barebox to be better comparable to the Kernel. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Drop asynchronous erase supportSascha Hauer2020-11-061-4/+2
| | | | | | | asynchronous erase support is unused and also dropped from the Kernel, so remove it from barebox. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: Drop dev_lseek_default()Andrey Smirnov2019-01-291-1/+0
| | | | | | | | | | | | | | | | | | | | | Only the following cdevs do not declare an .lseek() operation: - Console devices in common/console.c - Firmware framework in common/firmware.c - JTAG driver in drivers/misc/jtag.c - UBI in drivers/mtd/ubi/barebox.c Of those four, first two are marked DEVFS_IS_CHARACTER_DEV and implement only .write() operation and the last two don't implement anything but .ioctl(). While there's probably no meaningful way to use lseek() against any of those devices, there doesn't seem to be any harm in allowing it either. Change devfs_lseek() to ignore absense of .lseek() callback and drop dev_lseek_default() and all references to it in the codebase. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: Fix erase area alignment for non power of 2 erasesizeLadislav Michl2019-01-151-6/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Thu, Jan 10, 2019 at 09:32:07AM +0100, Sascha Hauer wrote: > On Wed, Jan 09, 2019 at 12:28:14PM +0100, Ladislav Michl wrote: > > Devices as AT45DB161 DataFlash uses non power of two page size (528) > > while present alignment algorithm relies on erasesize being power > > of 2. > > Fix that by introducing helper functions rounding to any multiply. > > Note that logic is sligthly changed to be consistent as ending > > address is moved forward to include also last byte meant to be > > erased while previous implementation moved it backward. > > > > Signed-off-by: Ladislav Michl <ladis@linux-mips.org> > > --- > > drivers/mtd/core.c | 28 ++++++++++++++++++++++------ > > include/linux/kernel.h | 5 +++++ > > 2 files changed, 27 insertions(+), 6 deletions(-) > > Applied, thanks Hi Sascha, I was searching for paper bag, but was unable to find anything thick enouh to cover behind :-/ This version is buggy and I noticed right now when testing on another board. Corrected version follows, which is also 192 bytes shorter for my ARM target. It seems next branch at https://git.pengutronix.de/ is not yet updated, so perhaps my fault won't affect anyone. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: return EOPNOTSUPP when attempting to erase an MTD_NO_ERASE deviceMatthias Schiffer2018-11-261-0/+3
| | | | | | | | | | | | | | | | | At least some MTD_NO_ERASE devices like MRAM do not specify a sensible erase block size; instead, erasesize is equal to the whole flash size. This leads to an EINVAL return from mtd_erase_align() whenever a partial erase is attempted. At least on the MRAM I tested, a full flash erase did not return an error, but it did not have any effect on the flash either. As erase seems to be entirely unsupported on this class of devices, and it is not necessary anyways, it's better to return early with EOPNOTSUPP. This fixes envfs_save() on a partitioned MRAM. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-1/+1
| | | | | | | | Introduce dev_set_name() in order to hide implementation details of setting device's name so it'd be easier to change it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: do not attach already attached UBISascha Hauer2018-10-081-4/+1
| | | | | | | | | | | in mtd_detect we do not check if the mtd is already attached to UBI. If it is we get the error: ERROR: ubi: mtd0 is already attached to ubi0 Check before trying to attach it to avoid this message. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: Fix printing partitions in hexTeresa Remmet2018-06-071-1/+1
| | | | | | | | When printing the partition size with "0x" prefix the value has to be displayed in hex. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* rename file_operations -> cdev_operationsSascha Hauer2018-04-061-1/+1
| | | | | | | | Linux also has struct file_operations which are something different. Rename our file_operations to cdev_operations which better matches what we have. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: make parameter functions more consistentSascha Hauer2017-04-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | This patch creates a consitent set of device parameter functions. With this we have: dev_add_param_<type><access> "type" is one of: int32, uint32, int64, uint64, string, mac, ipv4, enum, bitmask The improvement here is that we now can exactly specify the width of the int type parameters and also correctly distinguish between signed and unsigned variables which means that a variable no longer ends up with INT_MAX when it's assigned -1. "access" can be empty for regular read/write parameter, "_ro" for readonly parameters which get their value from a variable pointer in the background or "_fixed" for parameters which are set to a fixed value (without a pointer in the background). Some more exotic types are not (yet) implemented, like dev_add_param_ip_ro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: use dev_add_param_stringSascha Hauer2017-04-111-11/+11
| | | | | | | dev_add_param_string allows to pass a priv * so that the device_d * argument is not needed and can be removed later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: partition: Move of_mtd_fixup to drivers/of/Sascha Hauer2017-03-301-62/+3
| | | | | | | | Move the fixup code where the parser code is already. Since the code will not only be used for mtd in the future drivers/of/ is a better place than drivers/mtd/. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: fix reading data from page that needs cleanupSascha Hauer2017-03-231-4/+3
| | | | | | | | mtd_read´() returns -EUCLEAN to indicate that a page needs cleanup. This value shouldn't be returned from the mtd read file operation since this should return the number of bytes read. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Make UBI detection more robustSascha Hauer2016-11-111-11/+24
| | | | | | | | | | | | | When we want to detect if a mtd device contains an UBI image then testing the first block is not enough since it can always happen that UBI has just erased the block before the power failed during last boot. Since UBI only ever erases one block at a time and directly writes the ec header to it afterwards, it shouldn't be necessary to scan the whole device for UBI data. Scan the first 64 blocks. The first non-empty block then must contain UBI data, if instead we find foreign data we assume that no UBI is on that mtd device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* string: Fix (v)asprintf prototypesSascha Hauer2016-04-151-5/+7
| | | | | | | | | | Our asprintf and vasprintf have different prototypes than the glibc functions. This causes trouble when we want to share barebox code with userspace code. Change the prototypes for (v)asprintf to match the glibc prototypes. Since the current (v)asprintf are convenient to use change the existing functions to b(v)asprintf. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Introduce mtd_check_patternSascha Hauer2016-03-151-0/+19
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: rename mtd_all_ff -> mtd_buf_all_ffSascha Hauer2016-03-151-1/+9
| | | | | | | To make clear this function checks a given buffer and not data on a mtd device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Introduce function to get mtd type stringSascha Hauer2016-03-151-0/+22
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add support for marking blocks as goodSascha Hauer2016-03-151-0/+16
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: mtd_[read|write|erase]: check for valid input dataSascha Hauer2016-03-041-0/+22
| | | | | | | | mtd_[read|write|erase] are input functions to the mtd subsystem, so check for valid input data here rather than relying on the drivers doing this. The checks are copied from the Kernel as of 4.5-rc5 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: check offset in mtd_block_markbadStefan Christ2016-02-231-0/+3
| | | | | | | | Check if the given offset is valid for the mtd device. Print an error message if not to inform the user in the command 'nand'. Signed-off-by: Stefan Christ <s.christ@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix erasing of devices >4GiBSascha Hauer2016-02-091-3/+3
| | | | | | | | | When a device >4GiB is erased, not only the offset can be bigger than 4GiB, but also the size. This happens with the simplest command to erase a device: erase /dev/nand0. Make the size argument a 64bit type to make this work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix mtd_op_erase for devices >4GiBSascha Hauer2016-02-091-2/+2
| | | | | | | The mtd erase file operation has a unnecessary conversion to unsigned long in the offset. Remove it to make it work with chips >4GiB. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix mtd_op_read for devices >4GiBSascha Hauer2016-02-091-3/+2
| | | | | | | The mtd read file operation has a unnecessary conversion to unsigned long in the read offset. Remove it to make it work with chips >4GiB Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Make erase_info structs 64bit where necessarySascha Hauer2016-02-091-1/+1
| | | | | | | | Make the userspace structs 64bit where necessary. Since we do not have separated kernel/userspace in barebox we can just modifiy the original structs instead of adding separate 64bit structs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: initialize *retlen in mtd_write()Sascha Hauer2015-11-231-0/+2
| | | | | | | | | | Some mtd drivers like the spi-nor driver do not assign a value to the retlen pointer but instead only add the bytes written to *retlen. Users of mtd_write expect the variable to be initialized by the mtd core though, so we have to do it in mtd_write(). The same is done in mtd_read already. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: of: put master offset into partition nameSascha Hauer2015-07-231-2/+2
| | | | | | | Partition names should be partition@<offset> with <offset> being the offset in the master mtd, and not a counting number. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: Check partitions for empty stringTeresa Remmet2015-07-201-0/+3
| | | | | | | Make setting partitions a litte bit more robust. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd'Sascha Hauer2015-07-031-0/+40
|\ | | | | | | | | Conflicts: drivers/mtd/core.c
| * mtd: detect ubi devices automaticallySascha Hauer2015-06-261-0/+40
| | | | | | | | | | | | | | Hook UBI attachment into the mtd class devices detect function. This makes it possible to attach ubi devices with 'detect nand0.root'. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mtd: Make devname argument to add_mtd_device constSascha Hauer2015-06-291-1/+1
|/ | | | | | | add_mtd_device duplicates the string where necessary, so make it const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix function prototypeSascha Hauer2015-05-151-1/+1
| | | | | | mtd_op_protect must return int instead of size_t. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2015-05-061-1/+1
|\
| * mtd: of_mtd_fixup(): fix given DT not the default oneMarc Kleine-Budde2015-05-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | We have to start searching for the mtd node starting in the given root node not the defaukt (= barebox internal) one. This means the internal DT is always fixed up. This leads to booting not fixed up DT when using external DTs. This patch fixes the problem. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mtd: partition: Fix OF partition fixupSascha Hauer2015-04-281-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To get the number of address cells and size cells we have to use the newly created partition node, not the parent device node. The parent device node returns the address/size cells of the controller node, not the partition node. On an am335x machine this fixes the device tree passed to Linux. The situation there is: ... gpmc@50000000 { ... #address-cells = <0x2>; #size-cells = <0x1>; ranges = <0x0 0x0 0x8000000 0x10000000>; ... nand@0,0 { reg = <0x0 0x0 0x0>; #address-cells = <0x1>; #size-cells = <0x1>; ... partition@7 { label = "system"; reg = <0x220000 0x7de0000>; }; }; }; and without this patch barebox passes three bytes for partition@7's reg property instead of only two which naturally confuses Linux and yields to the system partition to start at 0 with a size of 0x220000. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
* mtd: fixup device tree partitionsSascha Hauer2015-02-121-0/+64
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add a partitions parameter to mtd devicesSascha Hauer2015-02-121-1/+96
| | | | | | | | | | | | The partitions parameter allows to partition a mtd device using a standard cmdline partition description string. This way the partitions of a mtd device can be changed at once. The output of the string can be used to be passed to the kernel as cmdline partition string. The partitions can also still be changed with addpart/delpart, the partitions parameter will be updated accordingly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: forbid conflicting mtd partitionsSascha Hauer2015-02-121-3/+30
| | | | | | | | mtd partitions should not conflict with each other, so forbid this. Also add the partitions to the partitions list sorted, so that they can be easier translated into a cmdline partition string. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: nand: remove automatically created bb devicesSascha Hauer2015-02-121-0/+2
| | | | | | | | the bb devices which are created in add_mtd_device() must be removed in del_mtd_device(). Also remove deletion of the bb devices in the mtdparts-add environment file. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add partitions to listSascha Hauer2015-02-121-0/+8
| | | | | | | So that we can iterate over the existing partitions from the master mtd device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: core: add error checksSascha Hauer2015-02-121-2/+13
| | | | | | register_device and devfs_create can fail. Add error checks for these. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix allowing to erase bad blocks on partitionsSascha Hauer2015-02-101-3/+3
| | | | | | | | | Partitions are mtd devices themselves, but the 'erasebad' parameter is only set to the master mtd device. To allow to erase bad blocks on partitions test the master device instead of the partition devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: use long long dev param for sizeHerve Codina2014-06-131-1/+1
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix writesize parameter valueHerve Codina2014-06-101-1/+1
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>