]> git.baikalelectronics.ru Git - uboot.git/commit
tools: omapimage: fix corner-case in byteswap path
authorPhilipp Tomsich <philipp.tomsich@theobroma-systems.com>
Mon, 4 Dec 2017 16:04:02 +0000 (17:04 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 6 Dec 2017 02:56:29 +0000 (21:56 -0500)
commit62f523734171c1da9d5ebf54d634fe9f6f0b2075
treecc2827658d7419fbe56a6a7e5341e110fae0df08
parent9365edf74bdd602e8a2cf11e30a81600363ef3cc
tools: omapimage: fix corner-case in byteswap path

Since commit 75ff0d63e094 ("common: command: tempory buffer should
have size of command line buf"), there have been consistent Travis CI
failures on my builds (interestingly not for Tom, even though building
the same commit id) due to a SEGV in building the byteswapped
omapimage:
          arm: pcm051_rev3
     make[2]: *** [MLO.byteswap] Error 139
                       ^^^ error code for a SEGV

Turns out that the word-based byte-swapping loop in omapimage.c is to
blame. With the loop condition
       while (swapped <= (sbuf->st_size / sizeof(uint32_t)))
there had been one-too-many iterations for all file sizes divisible by
the sizeof(uint32_t).  I.e. we had 1 iteration for 0 bytes (and also 1
through 3 bytes) and 2 iterations at 4 bytes... clearly overshooting
on 0 and 4 bytes.

This commit fixes the calculation of an up-rounded word-count and
makes sure to keep the zero-based loop-counter below the number of
words to be processed.

References: 75ff0d6 ("common: command: tempory buffer should have size of command line buf")
Fixes: 79b9ebb ("omapimage: Add support for byteswapped SPI images")
Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Reviewed-by: Martin Elshuber <martin.elshuber@theobroma-systems.com>
tools/omapimage.c