summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/core.c
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* mtd: nand: create bb devices automaticallySascha Hauer2014-04-281-0/+3
| | | | | | | | When a mtd device can have bad blocks we want to create a bb device, so do this automatically. This allows us to drop bb device creation from the environment. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Update internal API to support 64-bit device sizeDmitry Lavnikevich2014-03-121-1/+1
| | | | | | | | | | | | | | | | | | | MTD internal API presently uses 32-bit values to represent device size. This patch updates them to 64-bits but leaves the external API unchanged. In general, changing from 32-bit to 64-bit values cause little or no changes to the majority of the code with the following exceptions: - printk message formats; - division and modulus of 64-bit values (mtd_div_by_wb, mtd_div_by_eb may be used in some of such cases). Was tested on phyFLEX i.MX6. Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com> Signed-off-by: Grigory Milev <g.milev@sam-solutions.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: register mtd partitions as real mtd devicesSascha Hauer2014-02-261-1/+1
| | | | | | | | So far mtd partitions were mtd devices, but these were not registered. This patch changes this. mtd partitions are now registered like real mtd devices. This makes them part of the device hierarchy. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Only call of_parse_partitions when the mtd has a parentSascha Hauer2014-02-261-1/+3
| | | | | | | mtd->parent is optional so we can't derefence mtd->parent->device_node without checking mtd->parent. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: erase_info may be modified in mtd_eraseSascha Hauer2014-02-261-5/+9
| | | | | | | erase_info may be modified by the mtd partition code, so set the address each time we call mtd_erase. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add subpagesize to mtd_info_userSascha Hauer2013-12-201-0/+1
| | | | | | | | | ubiformat needs the subpagesize to work correctly. The kernel uses sysfs to pass the subpagesize, but in barebox we have the possibility to extend struct mtd_info_user. Add a corresponding field and use it in ubiformat. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: fix mtd_read return valueSascha Hauer2013-12-201-1/+14
| | | | | | | | mtd->read returns the number of bitflips as positive numbers. Instead of returning these numbers Return -EUCLEAN when the bitflip threshold has been reached, 0 otherwise. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: fix wrong return values in cdev readSascha Hauer2013-12-201-5/+4
| | | | | | | | mtd->read returns the number of bitflips as positive numbers. Instead of returning these numbers Return -EUCLEAN when the bitflip threshold has been reached, 0 otherwise. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Add missing includesSascha Hauer2013-11-081-0/+1
| | | | | | | | A lot of files rely on include/driver.h including include/of.h (and this including include/errno.h. include the files explicitly so we can eventually get rid of including of.h from driver.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Pass device_id to add_mtd_deviceSascha Hauer2013-10-291-3/+7
| | | | | | | | | Right now we do not support persistent names for mtd devices. The base name can be passed to add_mtd_device, but this is always appended with a dynamic number. With this patch add_mtd_device takes a device_id argument which can be used to create a mtd device with an exact name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/of'Sascha Hauer2013-08-051-0/+1
|\ | | | | | | | | | | Conflicts: arch/arm/boards/freescale-mx53-loco/board.c drivers/of/Makefile
| * mtd: Add devicetree partition parsingSascha Hauer2013-07-181-0/+1
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mtd: introduce mtd_read_oob and mtd_write_oobSascha Hauer2013-07-221-0/+21
|/ | | | | | Directly copied from the Kernel as of 3.11-rc1 Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd'Sascha Hauer2013-07-011-0/+48
|\
| * mtd: Align erase_op to eraseblock boundariesSascha Hauer2013-06-061-0/+48
| | | | | | | | | | | | | | | | | | | | Our erase command used to align to eraseblocks when necessary. This worked well until recently when the m25p80, mtd_dataflash and cfi flash were added / converted to mtd. This patch aligns the input to the erase fileoperation to eraseblock boundaries. Also tested with non uniform flashes with multiple eraseregions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mtd: Fix size_t printf format specifierSascha Hauer2013-06-211-1/+1
|/ | | | | | use 0x%08zx for size_t instead of 0x%08x Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: call mtd_erase with complete area if possibleSascha Hauer2013-05-271-0/+6
| | | | | | | | | | If a device does not have bad blocks loop over the eraseblocks in the driver instead of the core. This allows the mtd_dataflash driver to erase blocks instead of pages to gain more speed during erasing. Also the mtd_dataflash driver modifies the erase_info struct which causes the outer loop in the core to never end. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Use dev_add_param_int_ro where possibleSascha Hauer2013-04-111-9/+4
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Add parameter to allow erasing bad blocksSascha Hauer2013-03-041-1/+5
| | | | | | | | | | | | While erasing bad blocks is a potentially dangerous operation it is sometimes needed during development or when some foreign code has touched the flash. This patch adds a device parameter 'erasebad' to allow erasing bad blocks. Since this is not wanted during production this is behind a Kconfig option. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>