summaryrefslogtreecommitdiffstats
path: root/pnor_partition.cpp
Commit message (Collapse)AuthorAgeFilesLines
* pnor_partition: Handle requests exceeding partition's actual sizeAndrew Jeffery2018-04-041-26/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Partitions with patch files whose size was less than the partition size in the ToC could not be completely read by the host. For example when scanning over the entire PNOR on the host with `cat /dev/mtd0 > /dev/null` the host would lock up. A trace from mboxd under these circumstances shows: [ 1519832857.966501396] Received MBOX command: 4 [ 1519832857.966695620] Host requested flash @ 0x02a44000 [ 1519832857.968642020] Window @ 0x730ce000 for size 0x00024000 maps flash offset 0x02a44000 [ 1519832857.968808728] Writing MBOX response: 1 [ 1519832858.222090630] Received MBOX command: 4 [ 1519832858.222284692] Host requested flash @ 0x02a68000 [ 1519832858.223964544] Window @ 0x73cce000 for size 0x00009000 maps flash offset 0x02a68000 [ 1519832858.224136142] Writing MBOX response: 1 [ 1519832858.435944292] Received MBOX command: 4 [ 1519832858.436138394] Host requested flash @ 0x02a71000 [ 1519832858.437026725] Window @ 0x734ce000 for size 0x00007000 maps flash offset 0x02a71000 [ 1519832858.437195251] Writing MBOX response: 1 [ 1519832858.646768070] Received MBOX command: 4 [ 1519832858.646968637] Host requested flash @ 0x02a78000 [ 1519832858.647567228] Window @ 0x768ce000 for size 0x00001000 maps flash offset 0x02a78000 [ 1519832858.647731755] Writing MBOX response: 1 [ 1519832858.848288015] Received MBOX command: 4 [ 1519832858.848489188] Host requested flash @ 0x02a79000 [ 1519832858.849006404] Window @ 0x758ce000 for size 0x00000000 maps flash offset 0x02a79000 [ 1519832858.849168870] Writing MBOX response: 1 [ 1519832859.048631708] Received MBOX command: 4 [ 1519832859.048827305] Host requested flash @ 0x02a79000 [ 1519832859.049343956] Window @ 0x756ce000 for size 0x00000000 maps flash offset 0x02a79000 [ 1519832859.049503553] Writing MBOX response: 1 [ 1519832859.248950916] Received MBOX command: 4 [ 1519832859.249142069] Host requested flash @ 0x02a79000 [ 1519832859.249649871] Window @ 0x741ce000 for size 0x00000000 maps flash offset 0x02a79000 Of significance are the last three CREATE_READ_WINDOW requests, where the request succeeds but mboxd reports back a zero-sized window to the host. The host immediately considers itself done with the window, and requests a new window offset from the previous by size, which is zero. Thus it re-requests the same offset, and receives the same zero-sized window in return. As a result, firmware gets stuck in an unterminated loop, stealing the core from Linux, which promptly starts reporting a constant stream of RCU stall warnings among the rest of the failures. Everyone is miserable. The offset in question maps to a partition but not to a valid offset in the file backing that partition. Resize the backing file to meet the maximum access address within the limits of the partition size defined in the ToC. By doing so, we are able to map as much of the partition as necessary. However, we're not done. Whilst we no longer crash the host, we still don't successfully complete the operation the host requested. From Petitboot: / # cat /dev/mtd0 > /dev/null [ 501.061616288,3] MBOX-FLASH: Bad response code from BMC 2 [ 501.150405995,3] MBOX-FLASH: Error waiting for BMC cat: read error: Input/output error / # echo $? 1 / # And the corresponding mboxd trace on the BMC: [ 1519966031.652036815] Received MBOX command: 4 [ 1519966031.652272613] Host requested flash @ 0x03f1a000 [ 1519966031.652411603] Tried to open read window past flash limit [ 1519966031.652500088] Couldn't create window mapping for offset 0x03f1a000 [ 1519966031.652607966] Error handling mbox cmd: 4 [ 1519966031.652661421] Writing MBOX response: 2 [ 1519966031.652762229] Error handling MBOX event The read failure will be fixed in a follow-up patch. Change-Id: Iffdfb8af6f739df5e6d9c171b584a7244bdb7099 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* pnor_partition: Refactor to enforce stronger boundaries for abstractionsAndrew Jeffery2018-04-041-133/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The RORequest and RWRequest classes did not provide a clear abstraction over the operation of populating a window or partition associated with a CREATE_{READ,WRITE}_WINDOW request. The role of the classes was to find the partition for the provided offset, locate and then open its backing file. However, the file-descriptor for the backing file was exposed outside of the class, as was the FFS partition struct, both of which were managed _internal_ to the class. Thus the classes provided no encapsulation of state and awkwardly split the tasks of managing and utilising the resources between the callee and caller. This commit inverts the behaviour in a fulfil() method handles the mechanics of locating, opening, manipulating and closing the backing file, requiring nothing of the caller. The pnor_partition reference is managed entirely inside the Request class, derived from the offset passed to the constructor. Unifying the mechanics into fulfil() results in a decent reduction in lines of code at the expense of some cyclomatic complexity. fulfil() is publicly exposed via read() and write() wrappers on the class, and the RORequest and RWRequest classes are removed as a result. Change-Id: Ie587ed31f1a6db97bcb490dbcc2e27ece0b1f82c Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* misc: Replace license blurb with kernel-style SPDX markersAndrew Jeffery2018-03-241-18/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was roughly achieved by the following shell script: $ git ls-files | grep '\.[ch]p*$' | while read F; do EXT=${F##*.}; cat spdx.$EXT <(sed '/^\/\*$/,/^ \*\/$/d' $F) > ${F}.tmp; mv ${F}.tmp $F; done With the following context: $ cat spdx.c // SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2018 IBM Corp. $ cat spdx.h /* SPDX-License-Identifier: Apache-2.0 */ /* Copyright (C) 2018 IBM Corp. */ $ ls -l spdx.* -rw-r--r-- 1 andrew andrew 71 Feb 27 12:02 spdx.c lrwxrwxrwx 1 andrew andrew 6 Feb 27 12:02 spdx.cpp -> spdx.c -rw-r--r-- 1 andrew andrew 77 Feb 27 12:02 spdx.h lrwxrwxrwx 1 andrew andrew 6 Feb 27 12:02 spdx.hpp -> spdx.h The `sed` invocation catches a lot of function documentation, so the hunks were manually added to avoid removing information that we want to keep. Change-Id: I63e49ca2593aa0db0568c7a63bfdead388642e76 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* misc: Add license blurb to unlicensed filesAndrew Jeffery2018-03-241-0/+18
| | | | | | | | | | | | | | | This was roughly achieved with: $ git ls-files | grep '.[ch]p*$' | while read F; do head -n 1 $F | fgrep -v '/*' > /dev/null && echo $F; done | while read L; do cat apache $L > ${L}.tmp; mv ${L}.tmp ${L}; done Some fixups performed by hand to eliminate modifications to files that were hit which should not have been. Change-Id: I9fa5af4644687d8b595a6cf70d6f7575a767d11a Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* pnor_partition{,_table}: Conform to logging requirementsAndrew Jeffery2018-03-241-39/+30
| | | | | | | See the Rules section of README.md for justification. Change-Id: Ib5ac059b498abc152269e926fc750cb83cd75d6c Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* Format C++ files according to OpenBMC style guideAndrew Jeffery2018-03-191-36/+31
| | | | | | | We don't touch the C yet as upstream hasn't got such a change in place. Change-Id: Ie6cab4bf99df520bb6655b9b00ae31e762e3c57b Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
* Fix up InternalFailure to include metadataMarri Devender Rao2017-11-171-0/+30
| | | | | | | | | Scope is to add missing logs for InternalFailure errors Resolves openbmc/openbmc#2552, openbmc/openbmc#2568 Change-Id: Ic94b9d768e32b4d7be2b9b6746c1b675f15e3b1e Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
* vpnor: Add patch locationAdriana Kobylak2017-08-021-0/+8
| | | | | | | | | | | | | Look for the requested partition in the designated patch location (/usr/local/share/pnor/). If the partition is not found there, continue with the existing logic of looking in the other partition directories. This allows users to use patches in the virtual pnor implementation. Resolves openbmc/openbmc#1551 Change-Id: I7f27dfc9cd69a3f8ab88cb6fa77b2c1096e32841 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
* vpnor: fix partition file path passed to open()Deepak Kodihalli2017-07-171-3/+1
| | | | | Change-Id: I712699b6a5200115759eadc64a10d0b61b3d9d6f Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
* Read the partition file from the vpnor.Ratan Gupta2017-06-291-1/+1
| | | | | | | | | This fix reads the file from the partition, Memory map to it and then copy the asked memory area to the reserved memory area. Change-Id: I4b2987e628bc4820edfeb1b0a81e5d1cbb8e7cf1 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
* Read/write window property defines FFS partition file location.Ratan Gupta2017-06-291-0/+187
The BMC loads the PNOR partitions in a read-only volume. So after that there are following two cases: Read: Tries to open the file in read only mode from the partition(READONLY/READWRITE/PRESERVED), Partition Table tells the partition type depends on the offset. if file is not there in the mapped partition then tries to open the file from the read only partition. Write: Tries to open the file in write mode from the partition(READWRITE/PRESERVED), if file is not there in the mapped partition then mailbox daemon will copy the requested partition to the read-write volume to make changes to it. Change-Id: Ic0ef882380b56536ac55feae3ec563de95fdd4a6 Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
OpenPOWER on IntegriCloud