aboutsummaryrefslogtreecommitdiff
path: root/libflash/libflash.c
AgeCommit message (Collapse)AuthorFilesLines
2017-11-20external/pflash: Fix erasing within a single erase blockCyril Bur1-4/+0
It is possible to erase within a single erase block. Currently the pflash code assumes that if the erase starts part way into an erase block it is because it needs to be aligned up to the boundary with the next erase block. Doing an erase smaller than a single erase block will cause underflows and looping forever on erase. Fixes: ae6cb86c2 ("external/pflash: Reinstate the progress bars") Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-08-24libflash: fix memory leak on flash_exit()Stewart Smith1-2/+5
LeakSanitizer caught this with libflash/test/test-flash.c: Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7f72546ee850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x405ff0 in flash_init libflash/test/../libflash.c:830 #2 0x408632 in main libflash/test/test-flash.c:382 #3 0x7f7253540509 in __libc_start_main (/lib64/libc.so.6+0x20509) Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-08-15libflash/libflash: Remove logicially dead code (CID 97821)Cyril Bur1-2/+0
libflash/libflash.c: line 369: chunk = 0x100 - (d & 0xff); line 370: if (chunk > 0x100) At condition chunk > 256U, the value of chunk must be between 1 and 256. Fixes CID 97821 Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-09-15libflash: add 128MB MX66L1G45G partJoel Stanley1-0/+1
Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-08-02flash: Make size 64 bit safeMichael Neuling1-6/+8
This makes the size of flash 64 bit safe so that we can have flash devices greater than 4GB. This is especially useful for mambo disks passed through to Linux. Fortunately the device tree interface and the linux device driver are 64bit safe so no changes are required there. Userspace gard and flash tools are also updated to ensure "make check" still passes. Signed-off-by: Michael Neuling <mikey@neuling.org> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-02-18libflash: Support for Micron N25Q256Ax and Winbond W25Q256BV NOR flashAdriana Kobylak1-0/+6
These 32MB chips are used in the Barreleye OpenBMC BMC. Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-15libflash/blocklevel: Add keep_alive parameterCyril Bur1-0/+4
Currently the file backend will keep a file descriptor open until the structure is destroyed. This is undesirable for daemons and long running processes that only have a very occasional need to access the file. Keeping the file open requires users of blocklevel to close and reinit their structures every time, doing is isn't disastrous but can easily be managed at the interface level. This has been done at the blocklevel_device interface so as to provide minimal changes to arch_flash_init(). At the moment there isn't a need for the actually flash driver to be able to do this, this remains unimplmented there. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-11-26libflash: Support Micron N25Q256Ax NOR flashJoel Stanley1-0/+3
This 32MB part is used for the Barreleye OpenBMC BMC. Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-11-26libflash: put message on one lineJoel Stanley1-2/+1
This way it can be grep'd for. Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-09-08libflash: Fix Coverity defect 97867Cyril Bur1-2/+2
CID 97867 (#1 of 1): Uninitialized scalar variable (UNINIT) 5. uninit_use: Using uninitialized value rc. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-28libflash: Reintroduce typesafety in lowlevel libflash callsCyril Bur1-4/+2
Previous work did away with some typesafety when adding the blocklevel_device abstraction, this has resulted in the ability to accidently call libflash low level code with a blocklevel_device which has not been initialised by the libflash backend. The end result will not be good. Best to reintroduce that low level calls be called with libflashes own structures. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-28external/common: Create common code for initialising libflash componentsCyril Bur1-0/+8
In order to access the flash on ARM (presumably code running on a BMC), the hardware is involved. In order to access the flash on POWER (presumably code running on a host), opal calls through the Linux MTD driver are involved. In order to access the flash on x86 (presumably on a developer/admin system), you can't but it would be nice to be able to manipulate data which has come from the flash or will go onto the flash. The pflash and the gard tool both can read and write to the 'flash' and with the introduction of the blocklevel interface the details of how the flash is read from and written to is sufficiently abstracted that these tools don't need to know what they're running on. What does differ is the setup, and not by too much either. This common code pulls out the setup of the flash hardware on ARM, the searching for the appropriate MTD device on power and generic blocklevel device init for all three architectures. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-28libflash: Return a pointer to internal structure.Cyril Bur1-1/+5
There are some functions (notably: erase_chip and set_4b_mode) which cannot be abstracted away by the blocklevel interface, this means that if they are really needed (by pflash for example) then at the moment a program like pflash would need to pass a blocklevel_device struct to libflash. This forces libflash to trust that it was given a blocklevel that it did init. If it didn't init it the container_of call will return junk and libflash has no way to protect its self. This method (while very useful) has destroyed type safety. As such, this commit reintroduces some typesafety back into this stack. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-07-07libflash: Add support for Macronix 128Mb flash chipsJeremy Kerr1-0/+1
Fun-sized version of the MXxxL25635F. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-23libflash/blocklevel: add blocklevel flags.Cyril Bur1-0/+1
It has become apparent that communication between blocklevel and its backend may be necessarily, at least so that the backend can inform blocklevel as to if an erase must be done before a write. An erase before flag isn't strictly necessary as erases can be performed regardless of whether they need to be or not, however, the caveat with that is that when erases don't need to be performed, this is likely due to the backend not having erase blocks and therefore it may be impossible to set a sane value for erase blocks which would be used to erase before write. This flag saves backends that don't need erases before write to have to lie about an erase block size. Reviewed-By: Alistair Popple <alistair@popple.id.au> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-23libflash/ecc: Simplify and cleanup ecc code.Cyril Bur1-13/+14
The ecc 'memcpy' style functions return success or fail in terms of the ECC enum. This doesn't really make sense, use true or false. As the result the ecc enum doesn't need to be exposed anymore, which makes more sense, not clear why it was exposed in the first place. Convert some of the ecc #defines to static inlines, shouldn't make any difference but feels safer. Fix minor stylistic and typo issues. Reviewed-By: Alistair Popple <alistair@popple.id.au> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-09libflash: Add checking at blocklevel for erase block aligned erase lengthsCyril Bur1-0/+1
Currently blocklevel_erase() will let any erase of any size get passed down to the backend. Not strictly a problem since libflash does do this check as well, however, not all future backends will. This is very much a sanity check to save from a likely mistake. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-09libflash: start using the blocklevel interface.Cyril Bur1-32/+51
Converted all the libflash calls to use the blocklevel interface, modified all callers to libflash to use the blocklevel interface. This patch should introduce next to no functional change. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-04-07address reviews for: libflash:don't use the low level interface if it ↵skiboot-5.0-rc3Cyril Bur1-10/+4
doesn't exist commit 237f9d1a51eaed260119346dfddc044395267154 Author: Cyril Bur <cyril.bur@au1.ibm.com> libflash: don't use the low level interface if it doesn't exist In the review process a less invasive version was reworked. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-04-01libflash/file: add file abstraction for libflashCyril Bur1-0/+1
The functionality provided by libflash and libffs are useful and it would be good to use them on dumps of flash or even access flash from userland through MTD devices which are presented as files. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-04-01libflash: don't use the low level interface if it doesn't existCyril Bur1-1/+9
During init libflash calls low level functions without checking. libflash states to backends that if they implement all the higher level functions the lower level functions are optional (from libflash-priv.h): If all functions of the high level interface are implemented then the low level one is optional. A controller can implement some of the high level one in which case the missing ones will be handled by libflash using the low level interface. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-26memboot: Add a memboot flash backendAlistair Popple1-0/+1
memboot uses bmc system memory instead of a real flash chip. This patch adds a flash backend for bmc system memory to allow use of the memboot tool (in external/memboot) to boot the system. Signed-off-by: Alistair Popple <alistair@popple.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-17libflash: Improved ECC interfaceCyril Bur1-2/+74
This patch is twofold. 1. Improves the low level ecc memcpy code to better specify that we're reading/writing buffers with ecc bytes. 2. Improves/creates the libflash interfaces for ecc. This patch also includes some tests Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-04libflash: Ensure temporary buffer is freedJoel Stanley1-1/+1
Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-03sparse: libflash_debug is unusedCédric Le Goater1-0/+2
Let's wrap it with __SKIBOOT__ to avoid the warning. libflash_debug is still being used by libflash in userspace, eg. pflash and opal-prd. Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Suggested-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-26libflash: move ffs_flash_read into libflashJeremy Kerr1-0/+55
We have ffs_flash_read to do optionally-ecc-ed reads of flash data. However, this isn't really related to the ffs partitioning. This change moves ffs_flash_read into libflash.c, named flash_read_corrected. The function itself isn't changed. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-10-30libflash: Update from pflash-0.8.6Benjamin Herrenschmidt1-29/+68
Improve calibration and use safer timings for commands. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-10-15libflash: Sync with pflash 0.8.3Benjamin Herrenschmidt1-26/+49
Fixes 64MB chip support, improve Macronix settings, add Micron chip support, etc... Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-07-02Initial commit of Open Source releaseBenjamin Herrenschmidt1-0/+636
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>