summaryrefslogtreecommitdiffstats
path: root/common/ubiformat.c
Commit message (Collapse)AuthorAgeFilesLines
* ubiformat: Fix wrong error testsSascha Hauer2019-07-161-5/+4
| | | | | | | | | | | Several tests in ubiformat test for a positive error code where a negative error code is returned from the called functions. This is because the original code used tested against errno which is a positive value. One place still tests against errno, but the test should be against the return value from the last function call. Fix that aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ubiformat: handle write errors correctlySascha Hauer2019-07-161-9/+20
| | | | | | | | | | | | | | | | | | | | This is a barebox adoption of mtd-utils commit d9cbf6a ("ubiformat: handle write errors correctly"): | ubiformat: handle write errors correctly | | This issue was reported and analyzed by | Anton Olofsson <anol.martinsson@gmail.com>: | | when ubiformat encounters a write error while flashing the UBI image (which may | come from a file of from stdout), it correctly marks the faulty eraseblock as | bad and skips it. However, it also incorrectly drops the data buffer which was | supposed to be written, and reads next block of data. | | This patch fixes this issue - in case of a write error, we preserve the current | data and write it to the next eraseblock, instead of dropping it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: peb: Do not mark as bad in mtd_peb_torture()Sascha Hauer2019-07-161-6/+12
| | | | | | | | | | | Both the Kernel and mtd-utils have peb torture functions and both do not mark the block as bad automatically. Instead, the caller must mark the block as bad when -EIO is returned from the torture function. Do the same in barebox. This is necessary as the UBI code otherwise may mark a block as bad twice: Once indirectly in mtd_peb_torture() and then directly afterwards. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ubiformat: improve generation of UBI image sequenceSascha Hauer2019-07-151-2/+4
| | | | | | | | | | | | | | | | | | | | The UBI ec_hdr has an image_seq field. During attaching UBI expects that its value is the same for all eraseblocks. The value should be changed with every ubiformat and is used to detect half written images. In barebox we use a pseudo random number generated with rand() for this value. The ubiformat command calls srand(get_time_ns()) to initialize the pseudo random numbber generator. This is done in the option parser, so when ubiformat() is called directly (from fastboot for example) the pseudo random number generator is not initialized and we get the same values after every barebox restart. This patch moves the pseudo random number generator initialization to the place where the numbers are generated. Also use random32() rather than rand() to generate 32bit values rather than 15bit values (0 - RAND_MAX). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: fastboot: ubiformat: Fix bad block handlingSascha Hauer2019-01-281-12/+28
| | | | | | | When fastboot handles UBI images in sparse file format then bad blocks of the underlying mtd device are not skipped. This patch fixes this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ubiformat: print messages after checking a block is not badSascha Hauer2018-11-141-6/+6
| | | | | | | | | ubiformat prints its "flashing eraseblock x" and "formatting eraseblock x" messages before having checked that a block is actually good. This is misleading, so first check if a block is good and only if it is print a message. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ubiformat: Allow to ubiformat with a buffer givenSascha Hauer2018-02-091-19/+36
| | | | | | | So far ubiformat can only handle files. Make it possible to pass a buffer into ubiformat. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2018-01-221-4/+14
|\
| * ubiformat: Lower message printing frequencySascha Hauer2018-01-111-4/+14
| | | | | | | | | | | | | | | | | | During scanning and formatting printing the messages on a serial line has significant overhead up to the point where it takes longer to print the messages than it takes to do the work. Lower the message printing frequency to improve performance. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | ubiformat: Add ubiformat write functionSascha Hauer2018-01-111-0/+61
|/ | | | | | | | | | | | | The ubiformat C API expects an image file as argument. With upcoming Android fastboot sparse image support we can no longer provide a complete image anymore. With this patch we can write an image in multiple chunks after we've formatted a MTD device with ubiformat. ubiformat_write will skip the EC header in both the MTD device we write to and also the image we read from, so we can flash an image on a MTD device containing EC headers already. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ubiformat: use default values for ubi_ver and image_seqSascha Hauer2016-04-261-0/+6
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: ubiformat: move code to common/Sascha Hauer2016-04-261-0/+675
This is the final step to separate the ubiformat code from the command. With this the ubiformat code gains a C API. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>