aboutsummaryrefslogtreecommitdiff
path: root/libflash/libffs.c
AgeCommit message (Collapse)AuthorFilesLines
2019-07-26SPDX-ify all skiboot codeStewart Smith1-17/+3
Use Software Package Data Exchange (SPDX) to indicate license for each file that is unique to skiboot. At the same time, ensure the (C) who and years are correct. See https://spdx.org/ Signed-off-by: Stewart Smith <stewart@linux.ibm.com> [oliver: Added a few missing files] Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2019-05-20include/mem_region-malloc: Define calloc for CCAN HeapJordan Niethe1-8/+0
We would like to be able to use dump_trace to dump multiple trace buffers at a time. The entries should be displayed in timestamp order. As each buffer is already ordered on timestamp, a k-way merge is an efficient method to sort the buffers together by timestamp. A heap can be used to implement a k-way merge. As CCAN is already included in Skiboot, use the CCAN heap. The heap uses the calloc function which is currently not defined in skiboot. Prepare for adding this heap by defining calloc. Remove local calloc definition from libffs.c. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2019-03-20libffs: Fix string truncation gcc warning.Michal Suchanek1-1/+1
Use memcpy as other libffs functions do. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libffs: Fix bad checks for partition overlapCyril Bur1-9/+20
Not all TOCs are written at zero Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09external/ffspart: Use new interfaceCyril Bur1-1/+4
This also updated the pflash tests which use ffspart to generate pnors Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Allow caller to specifiy header partitionCyril Bur1-8/+20
An FFS TOC is comprised of two parts. A small header which has a magic and very minimmal information about the TOC which will be common to all partitions, things like number of patritions, block sizes and the like. Following this small header are a series of entries. Importantly there is always an entry which encompases the TOC its self, this is usually called the 'part' partition. Currently libffs always assumes that the 'part' partition is at zero. While there is always a TOC and zero there doesn't actually have to be. PNORs may have multiple TOCs within them, therefore libffs needs to be flexible enough to allow callers to specify TOCs not at zero. The 'part' partition is otherwise a regular partition which may have flags associated with it. libffs should allow the user to set the flags for the 'part' partition. This patch achieves both by allowing the caller to specify the 'part' partition. The caller can not and libffs will provide a sensible default. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Refcount ffs entriesCyril Bur1-7/+31
Currently consumers can add an new ffs entry to multiple headers, this is fine but freeing any of the headers will cause the entry to be freed, this causes double free problems. Even if only one header is uses, the consumer of the library still has a reference to the entry, which they may well reuse at some other point. libffs will now refcount entries and only free when there are no more references. This patch also removes the pointless return value of ffs_hdr_free() Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Switch to storing header entries in an arrayCyril Bur1-63/+65
Since the libffs no longer needs to sort the entries as they get added it makes little sense to have the complexity of a linked list when an array will suffice. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Remove backup partition from TOC generation codeCyril Bur1-51/+1
It turns out this code was messy and not all that reliable. Doing it at the library level adds complexity to the library and restrictions to the caller. A simpler approach can be achived with the just instantiating multiple ffs_header structures pointing to different parts of the same file. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Remove the 'sides' from the FFS TOC generation codeCyril Bur1-75/+2
It turns out this code was messy and not all that reliable. Doing it at the library level adds complexity to the library and restrictions to the caller. A simpler approach can be achived with the just instantiating multiple ffs_header structures pointing to different parts of the same file. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Always add entries to the end of the TOCCyril Bur1-19/+1
It turns out that sorted order isn't the best idea. This removes flexibility from the caller. If the user wants their partitions in sorted order, they should insert them in sorted order. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: ffs_close() should use ffs_hdr_free()Cyril Bur1-20/+20
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libflash/libffs: Add setter for a partitions actual sizeCyril Bur1-0/+13
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-09libffs: Standardise ffs partition flagsCyril Bur1-1/+106
It seems we've developed a character respresentation for ffs partition flags. Currently only pflash really prints them so it hasn't been a problem but now ffspart wants to read them in from user input. It is important that what libffs reads and what pflash prints remain consistent, we should move the code into libffs to avoid problems. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2017-12-13pflash: Support for clean_on_ecc_error flagAdriana Kobylak1-2/+1
Add the misc flag clear_on_ecc_error to libflash/pflash. This was the only missing flag. The generator of the virtual pnor image relies on libflash/pflash to provide the partition information, so all flags are needed to build an accurate virtual pnor partition table. Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com> Reviewed-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-11-09pflash: Support for volatile flagAdriana Kobylak1-1/+3
The volatile flag was added to the pnor image to indicate partitions that are cleared during a host power off. Display this flag from the pflash command. Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-08-01libflash/libffs: Don't require 'part' size to be known by callersCyril Bur1-12/+20
Currently the FFS header/TOC generation code requires that consumers know the size of their TOC beforehand. While this may be advantageous in some circumstances if there are known limitations of other software. It should not be a requirement. Knowing the size of the FFS header/TOC partially breaks the abstraction since it would require consumers of the library to be aware of/have some idea of the on flash structure and size. Future work may introduce functions to force sizes but the default behaviour should be to calculate it behind the scenes. This patch also addresses an off by one issue in checking for TOC overflow. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-08-01libflash: Adding debugging outputCyril Bur1-1/+4
Also add usage text to pflash. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-07-19pflash option to retrieve PNOR partition flagsMichael Tritz1-3/+8
This commit extends pflash with an option to retrieve and print information for a particular partition, including the content from "pflash -i" and a verbose list of set miscellaneous flags. -i option is also updated to print a short list of flags in addition to the ECC flag, with one character per flag. A test of the new option is included in libflash/test. Signed-off-by: Michael Tritz <mtritz@us.ibm.com> Reviewed-by: Cyril Bur <cyril.bur@au1.ibm.com> [stewart@linux.vnet.ibm.com: various test fixes, enable gcov] Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-06-26libflash/libffs: Zero checksum wordsCyril Bur1-0/+16
On writing ffs entries to flash libffs doesn't zero checksum words before calculating the checksum across the entire structure. This causes an inaccurate calculation of the checksum as it may calculate a checksum on non-zero checksum bytes. This patch solves this by zeroing the entire structure which is to be written to the flash before calculating the checksum across the struct. Fixes: 602dee45 libflash/libffs: Rework libffs Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-06-26libffs: Fix ffs_lookup_part() return valueBenjamin Herrenschmidt1-4/+6
It would return success when the part wasn't found Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Michael Neuling <mikey@neuling.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-06-21libflash/libffs: Correctly update the actual size of the partitionCyril Bur1-1/+1
libffs has been updating FFS partition information in the wrong place which leads to incomplete erases and corruption. Fixes: 602dee45 libflash/libffs: Rework libffs Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-05-26libflash: Initialise entries list earlierOliver O'Halloran1-1/+1
In the bail-out path we call ffs_close() to tear down the partially initialised ffs_handle. ffs_close() expects the entries list to be initialised so we need to do that earlier to prevent a null pointer dereference. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-03-27libflash: Fix pflash -iMichael Neuling1-2/+3
pflash -i is currently broken due to this commit commit 602dee4505cd0ceb5b69f056ec403f982b585791 Author: Cyril Bur <cyril.bur@au1.ibm.com> libflash/libffs: Rework libffs It's output doesn't correctly detect the last partition and continues printing forever. This fixes it by returning null when we don't find a partition in ffs_get_part(). Signed-off-by: Michael Neuling <mikey@neuling.org> Acked-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-03-24libffs: Understand how to create FFS partition TOCs and entries.Cyril Bur1-14/+349
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-03-24libflash/libffs: Rework libffsCyril Bur1-142/+214
This patch attempts a rework of libffs to prepare it for future changes. Firstly the types are split in two: 1. Packed, big endian structures used to map exactly how the data is on flash. 2. CPU endian, sane valued, not packed structures used to manipulate FFS data. Secondly: The packed struct can use BE types so that in future tools like sparse can be run over the code to check for endian conversion bugs. Thirdly: defines of sizeof(struct ...) were removed for clarity. Finally: For ease of manipulation, the in memory FFS structures contain a linked list of entries as this will make addition and removal operations much easier. This patch should be invisible to consumers of libffs. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-11-11libflash/libffs: Fix possible NULL dereferenceCyril Bur1-0/+2
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-10-25libflash/libffs: Use blocklevel_smart_write() when updating partitionsCyril Bur1-1/+1
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-10-11libflash/blocklevel: Allow double ecc protecting a regionCyril Bur1-1/+1
Currently the policy for calling ECC protecting a range at the blocklevel layer is that the requested region be completely unprotected otherwise the call will return an error. It turns out that duplicate calls to ffs_init() with true as the last parameter (for the same blocklevel structure) will cause duplicate attempts to ecc_protect() ranges. Change the policy within blocklevel to allow duplicate protecting. In fact the new policy almost guarantees no failure (baring something odd like malloc() failing). It will detect that the range is currently already fully protected and do nothing, detect that part of the range is or is not and extend the existing range or detect that a range fits perfectly between two ranges in which case it will merge the ranges. Also adjust tests to match the new policy. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-08-25flash: Rework error paths and messages for multiple flash controllersMichael Neuling1-1/+1
The current flash code was written with only one flash chip, which is a system_flash (ie. the PNOR image), in mind. Now that we have mambo bogusdisk flash, we can have many flash chips. This is resulting in some confusing output messages. This reworks some of the error paths and warnings to make this more coherent when we have multiple flash chips. We assume everything can be a system flash, so I've removed the is_system_flash parameter from flash_register(). We'll use the first system flash we find and warn if we find another since discovery order is not a guaranteed API. Signed-off-by: Michael Neuling <mikey@neuling.org> Acked-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-08-02flash: Make size 64 bit safeMichael Neuling1-1/+3
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-07-05libflash: Add sanity checks to ffs init code.Cyril Bur1-0/+22
Quite a lot of code relies on values read from flash. These values shouldn't be totally trusted without at least basic sanity checks. Fixes coverity bug: 119719 Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-03-11libflash/libffs: Reporting seeing all 0xFF bytes during init.Cyril Bur1-0/+19
When flash controllers get deconfigured or yanked out from under these tools flash accesses tend to just return all 0xFF bytes. libffs is usually the first thing to do reads and will fail parsing its partition structures. This patch adds reporting when it fails to parse because it got all 0xFF bytes. The idea is that this will help debugging by splitting the possible reasons for a failed init into 1) flash controller issue or reading erased flash 2) flash corruption or not valid reading partition data. These two cases are nice to be able to separate as early as possible as they usually mean two quite different type of bugs. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-12libflash/libffs: Check for NULL and set return pointer in ffs_next_side()Cyril Bur1-0/+6
Currently there are two error cases that ffs_next_side() may hit and will leave the return pointer untouched. This isn't a huge problem as the caller should be checking the return value anyway but as we know, callers don't always do that. It doesn't hurt for ffs_next_side() to make it as clear as possible that it encountered a problem. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-by: Sam Mendoza-Jonas <sam@mendozajonas.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-12libflash/libffs: Rename ffs_cmp() to ffs_equal()Cyril Bur1-1/+1
Some confusion has arisen from the first consumer of ffs_cmp() in that they expected a strcmp style less than one, zero or greater than one return value. This has been addressed in this patch in two ways, by changing the return type to a boolean in order to (attempt) to alert the programmer that this is not the case and by renaming it to equal to avoid the implied comparison and imply very much a boolean outcome. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-by: Sam Mendoza-Jonas <sam@mendozajonas.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-08libffs: Add helper get ffs_handle to the "OTHER_SIDE"Cyril Bur1-1/+35
Some FFS structures will have a partition called "OTHER_SIDE", this is a pointer to another ffs TOC on which another ffs_handle can be instantiated. Currently users of libffs would have to query for the presence of this partition and then initialise a new ffs_handle themselves. As accessing the "other" side appears to be becoming a common operation this convenience function should prove useful. Furthermore, it is possible for these multiTOC flash chips to be circular, that is the "OTHER_SIDE" partition of 'secondary' TOC points back to the initial TOC. The solution is to add a comparison function capable of detecting when repeated calls to ffs_next_side() go full circle. It should be noted here that this is all the comparator function is designed to detect, it will not be able to detect two identical TOCs opened with different blocklevel_devices as this would require the ability to compare blocklevel_devices. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-08libffs: Remove unused function ffs_open_image()Cyril Bur1-82/+0
The utility of this function has been superceeded by blocklevel code and is no longer called from anywhere, it can be removed. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2016-01-08libffs: Remove struct flash_chip from struct ffs_handleCyril Bur1-4/+0
Simply isn't used anymore since libffs knows how to use the blocklevel interface. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-11-17libflash: fix resource leaks on errors in ffs_open_imageStewart Smith1-1/+5
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-19in skbioot-5.1.0 commit, accidentally somehow removed two compiler warning ↵Stewart Smith1-1/+7
fixes. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-17Add skiboot-5.1.0 release notesskiboot-5.1.0Stewart Smith1-7/+1
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-17libflash: check ffs_part_info return value in ffs_initJeremy Kerr1-1/+7
Current packaging builds (which specify -O2) fail for me, with: CC libffs.o ../../libflash/libffs.c: In function ffs_init: ../../libflash/libffs.c:149:8: error: start may be used uninitialized in this function [-Werror=maybe-uninitialized] rc = blocklevel_ecc_protect(bl, start, total_size); ^ ../../libflash/libffs.c:149:8: error: total_size may be used uninitialized in this function [-Werror=maybe-uninitialized] ../../libflash/libffs.c:148:7: error: ecc may be used uninitialized in this function [-Werror=maybe-uninitialized] if (ecc) { ^ cc1: all warnings being treated as errors This is because we're not checking for the return value of ffs_part_info, which may return with start/total_size/ecc uninitialised. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-07-10Introduce blocklevel_ecc_protect() return value checkKamalesh Babulal1-3/+9
Check for the return value from blocklevel_ecc_protect(), while registering regions of the flash and log error incase the return registration of region fails. Fixes Coverity defect#101019 Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Reviewed-By: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-23libffs: init with ecc protection at blocklevel levelCyril Bur1-2/+12
Passing a flag on libffs init will register all regions of the flash with ecc (as per the libffs partition information) as being ecc protected (or not). This saves the consumer needing to know or care about the presence of ecc. 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: start using the blocklevel interface.Cyril Bur1-25/+26
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-06-01libffs: Add the offset of the TOC to partition entry addressesCyril Bur1-1/+1
The accessor for ffs partition entries should be adding the offset of the TOC to the absolute address of the partition entries as the TOC is not necessarily at 0 within in the flash. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-By: Alistair Popple <alistair@popple.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-06-01libffs: Rename various offset variables to toc_offsetCyril Bur1-13/+13
The word offset can be ambiguous, it can be unclear what offset the variable refers to or what it is the offset of. As this library now has to deal with flash with more than one libffs TOC, it makes sense to rename all uses of 'offset' to 'toc_offset' which relate to the offset of the TOC within in the flash. Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Reviewed-By: Alistair Popple <alistair@popple.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-04libflash: Implement ffs_open_imageJoel Stanley1-4/+81
ffs_open_image is like ffs_open_flash, but it can operate on a file descriptor to a pnor image instead of a flash device. It is currently disabled in skiboot as it does not provide the read and lseek used by libffs. Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-26libflash: move ffs_flash_read into libflashJeremy Kerr1-55/+0
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>
2015-02-26libflash: Remove dependencies on skiboot.h headerJeremy Kerr1-0/+4
libflash should be compilable without the skiboot definitions. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Reviewed-By: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>