summaryrefslogtreecommitdiffstats
path: root/common/imx-bbu-nand-fcb.c
Commit message (Collapse)AuthorAgeFilesLines
* imx-bbu-nand-fcb: Remove unused variable partition_sizeAlexander Shiyan2019-01-031-3/+1
| | | | | Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Check the required space a bit earlierAlexander Shiyan2019-01-031-2/+6
| | | | | | | | | | If the partition size is too small for imx_bbu_nand_update(), this can lead to an infinite loop in the imx_bbu_firmware_fcb_start_page() function, because imx_bbu_firmware_max_blocks() returns zero. Fix this by place imx_bbu_firmware_max_blocks() a bit early. Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand: Make locally used functions staticSascha Hauer2018-11-121-2/+2
| | | | | | To avoid missing prototypes warning. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Workaround ROM checking fingerprint before correcting bitflipsSascha Hauer2018-09-251-0/+11
| | | | | | | | | | | | | The FCB block is protected with a ECC code which can correct 1bit errors and detect 2bit errors. This works fine for all fields except the fingerprint marker (Containing "FCB") and the version field. Here the ROM chooses to check the correct value of the fields *before* running the ECC correction. Thus a FCB is not used by the ROM anymore when it has a bitflip in the fingerprint or version. For us this means we have to rewrite the FCB in this case, so reject the faulty FCB in read_fcb_hamming_13_8() which triggers a rewrite during the check operation. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Workaround ROM not being able to handle bad blocks properlySascha Hauer2018-09-251-7/+38
| | | | | | | | | When reading a firmware image the ROM only checks for a bad block when advancing the read position, but not if the initial block is good. Hence we cannot directly point to the first firmware block, but must instead point to the first *good* firmware block. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Improve error messageSascha Hauer2018-09-251-1/+1
| | | | | | | When printing that a FCB is not readable it's interesting to know which one is not readable. Print the block number in the message. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: fix build on MX28 onlyLucas Stach2017-11-211-3/+15
| | | | | | | | | This code may be compiled without ARCH_IMX6 present, so it must not depend on any functions provided by the architecture support. Fixes: a2618c215bff (imx-bbu-nand-fcb: add support for imx6ul) Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: read_firmware_all(): Spell "Secondary firmware" with a ↵Marc Kleine-Budde2017-09-261-1/+1
| | | | | | | | | | capital "S" "Primary firmware" is writte with a capital "P" so adjust "Secondary firmware" to use a capital "S". Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: add support for imx6ullChristian Hemp2017-05-221-3/+3
| | | | | | | The i.MX 6ull secures the fcb with bch 40. This is identical to i.MX 6ul. Signed-off-by: Christian Hemp <c.hemp@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: add support for imx6ulJan Remmet2017-05-051-3/+142
| | | | | | | | | | | | imx6ul secure the fcb with bch 40. The imx-kobs tool use a own modified bch lib. They reverse the bit order of the data and the ecc. To use the bch lib in barebox the bytes in the data buffers must be reversed. The data layout on nand is bit aligned. But with 40 bits this is not an issue for imx6ul now. Signed-off-by: Jan Remmet <J.Remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: split up read_fcbJan Remmet2017-01-101-36/+47
| | | | | | | There are other ecc modes for the fcb out there. Signed-off-by: Jan Remmet <j.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: avoid double free of dbbt_entriesLucas Stach2016-07-071-1/+0
| | | | | | | The error path properly frees them already. Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: don't drop error return codeLucas Stach2016-07-071-2/+2
| | | | | | | | | bit_to_flip might be negative if any uncorrectable bitflips occured. Use int instead of unsigned type in order to properly propagate the error. Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: add missing newline characterStefan Christ2016-05-191-2/+2
| | | | | Signed-off-by: Stefan Christ <s.christ@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: move crc specific stuff to crc.hSascha Hauer2016-04-151-0/+1
| | | | | | | We have a crc.h, so move our crc function prototypes there to further cleanup common.h. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Print error message when out of pebsSascha Hauer2016-04-081-1/+3
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Make robust against power cutsSascha Hauer2016-04-081-31/+341
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes the update to Nand robust against power failures. With this we make sure that during every step of the update at least one of the two images on Nand is readable and valid. Also this patch makes it possible to refresh/repair the boot images on Nand. This may become necessary when a previous update has been interrupted due to a power cut, or when the number of bitflips is near to the number we can correct. This is also done in a way that allow power cuts at every step. We assume the following layout in the Nand flash: fwmaxsize = (n_blocks - 4) / 2 block 0 ---------------------- | FCB/DBBT 0 | 1 ---------------------- | FCB/DBBT 1 | 2 ---------------------- | FCB/DBBT 2 | 3 ---------------------- | FCB/DBBT 3 | 4 ---------------------- | Firmware slot 0 | 4 + fwmaxsize ---------------------- | Firmware slot 1 | ---------------------- When the layout found on the device differs from the above the update won't be robust, but nevertheless works. Since the layout is changed to the above during the update, the next update will be robust. Here's the strategy we use to implement a robust update: The FCBs contain pointers to the firmware slots in the Firmware1_startingPage and Firmware2_startingPage fields. Note that Firmware1_startingPage doesn't necessarily point to slot 0. We exchange the pointers during update to atomically switch between the old and the new firmware. - We read the first valid FCB and the firmware slots. - We check which firmware slot is currently used by the ROM: - if no FCB is found or its layout differs from the above layout, continue without robust update - if only one firmware slot is readable, the ROM uses it - if both slots are readable, the ROM will use slot 0 - Step 1: erase/update the slot currently unused by the ROM - Step 2: Update FCBs/DBBTs, thereby letting Firmware1_startingPage point to the slot we just updated. From this moment on the new firmware will be used and running a refresh/repair after a power failure after this step will complete the update. - Step 3: erase/update the other firmwre slot - Step 4: Eventually write FCBs/DBBTs again. This may become necessary when step 3 revealed new bad blocks. Refreshing the firmware which is needed when when blocks become unreadable due to read disturbance works the same way, only that the new firmware is the same as the old firmware and that it will only be written when reading from the device returns -EUCLEAN indicating that a block needs to be rewritten. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Print error when writing blocks failsSascha Hauer2016-04-081-1/+3
| | | | | | | When writing to a block fails the update handler fails relatively silent. Print an error message in this case. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: When writing firmware return new bad blocksSascha Hauer2016-04-081-2/+3
| | | | | | | | | | Positive return values of imx_bbu_write_firmware() so far indicate the last block that has been written to. This value is unused, so return values > 0 to indicate if there are new bad blocks. This information can be used in the next step to know if the DBBT has to be rewritten. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Only write FCBs/DBBTs when necessarySascha Hauer2016-04-081-0/+230
| | | | | | | | Instead of writing the FCBs/DBBTs on every update write them only if they have changed or if a block needs cleanup (returns -EUCLEAN) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: erase on demandSascha Hauer2016-04-081-33/+14
| | | | | | | | Instead of erasing the whole partition on update entry, erase the areas separately when we actually want to write them. This is done as a step towards robust update. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: factor out a fcb write functionSascha Hauer2016-04-081-86/+172
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Use mtd-peb API to write firmwareSascha Hauer2016-04-081-9/+35
| | | | | | | | With this patch we verify the firmware written to the NAND and thus can react on write failures. We torture the block and if it went bad we mark it as bad. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: factor out layout functionsSascha Hauer2016-04-081-20/+46
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Remove double write of first fcbSascha Hauer2016-03-041-4/+0
| | | | | | | The first FCB page was written twice. One time is enough, drop the second write. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: optimize check for bad block loopSascha Hauer2016-03-041-2/+2
| | | | | | | | The argument passed to dbbt_data_create() contains the number of blocks, not the last block. This means we can exit the loop with '<' instead of '<=' Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Split space for firmware in two equal regionsSascha Hauer2015-06-121-15/+33
| | | | | | | | | | | We used to write the second firmware right after the first firmware. However, splitting the available space into two equal regions has advantages: When we update barebox the next time the generated FCB/DBBT blocks will be the same as with the last update, so in case of power failure it is more likely that we have valid data in one of the FCB/DBBT areas. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Erase whole partitionSascha Hauer2015-06-121-3/+1
| | | | | | | | Now that we use a partition for the bootloader instead of the whole NAND device we can erase it completely instead of hardcoded 2MB. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Let DBBT start at page 1Sascha Hauer2015-06-121-10/+11
| | | | | | | | | | We used to put the FCB in the first two NAND blocks and the DBBT in the third and fourth block. It's much more space efficient to put the FCB and DBBT together into the same eraseblock in different pages. This way we can store four FCBs and four DBBTs instead of two only. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: make available for i.MX28 aswellSascha Hauer2015-06-121-22/+151
| | | | | | | | The code can be used with slight modifications on i.MX28 aswell. Add a i.MX28 registration function and move the differences to function callbacks. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Use barebox partition instead of whole deviceSascha Hauer2015-06-121-2/+2
| | | | | | | | | | We used to use nand0 device for storing barebox and made the assumption that there is enough space at the beginning of the first device. Instead, use the barebox partition directly. This requires that the partition where barebox should be stored is named 'barebox', that is the case for all boards currently. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* imx-bbu-nand-fcb: Fix debug messagesSascha Hauer2015-06-121-2/+2
| | | | | | We should print the block number before increasing it, not afterwards. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM: i.MX6: bbu nand: Move to common placeSascha Hauer2015-06-121-0/+491
The code can be used on i.MX28 aswell, so move it to a common place. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>