The image_check currently fails when it cannot read all magic bytes in a
single chunk. But this can happen when the data are read from a pipe. This
currently breaks the openmesh.sh upgrade script with musl because it uses
dd with a blocksize of 1 to copy the image file to the mtd process.
The read can simply be repeated until enough bytes are read for the magic
byte check. It only stops when either an error was returned or 0 bytes were
read.
Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
SVN-Revision: 48891
{
uint32_t magic;
int ret = 1;
+ int bufread;
+
+ while (buflen < sizeof(magic)) {
+ bufread = read(imagefd, buf + buflen, sizeof(magic) - buflen);
+ if (bufread < 1)
+ break;
+
+ buflen += bufread;
+ }
if (buflen < sizeof(magic)) {
- buflen += read(imagefd, buf + buflen, sizeof(magic) - buflen);
- if (buflen < sizeof(magic)) {
- fprintf(stdout, "Could not get image magic\n");
- return 0;
- }
+ fprintf(stdout, "Could not get image magic\n");
+ return 0;
}
+
magic = ((uint32_t *)buf)[0];
if (be32_to_cpu(magic) == TRX_MAGIC)