Hi,

This code looks good in general just some small comments.

Hauke

On 1/13/22 11:20, kestrel1...@t-online.de wrote:
From: Daniel Kestrel <kestrel1...@t-online.de>

This patch adds creating the checksum to be able to create an
image and boot the secondary ath79 based wireless assist (WASP)
SoC with a second instance of OpenWrt for some AVM Fritzbox
devices (3390, 3490, 5490, 7490).
The utility is called avm-wasp-checksum and was originally
created by Andreas Boehler.

Signed-off-by: Daniel Kestrel <kestrel1...@t-online.de>
---
  CMakeLists.txt          |   1 +
  src/avm-wasp-checksum.c | 141 ++++++++++++++++++++++++++++++++++++++++
  2 files changed, 142 insertions(+)
  create mode 100644 src/avm-wasp-checksum.c

.....
+
+       while (!feof(in_fp)) {
+               switch (model) {
+               case MODEL_3390:
+                       read = fread(buf, sizeof(uint32_t), CHUNK_SIZE, in_fp);

fread() and fwrite() are returning a size_t and not a ssize_t.
You should probably also check for errors with ferror().

You can probably also change it like this:

                read = fread(buf, sizeof(uint32_t), CHUNK_SIZE, in_fp);
                // Error handling
                switch (model) {
                case MODEL_3390:
                        for (int i = 0; i < read; i++)
                                crc = crc ^ buf[i];
                        break;
                case MODEL_X490:
                        crc32(buf, read * sizeof(uint32_t), &crc);
                        break;
                }
                fwrite(buf, sizeof(uint32_t), read, out_fp);
                // Error handling


+                       for (int i = 0; i < read; i++)
+                               crc = crc ^ buf[i];
+                       fwrite(buf, sizeof(uint32_t), read, out_fp);
+                       break;
+               case MODEL_X490:
+                       read = fread(buf, 1, sizeof(uint32_t) * CHUNK_SIZE, 
in_fp);
+                       crc32(buf, read, &crc);
+                       fwrite(buf, 1, read, out_fp);
+                       break;
+               }
+       }
+       if (model == MODEL_X490)
+               crc = __bswap_32(crc);
+       fwrite(&crc, sizeof(uint32_t), 1, out_fp);
+       fclose(in_fp);
+       fclose(out_fp);
+       printf("Done.\n");
+       return EXIT_SUCCESS;
+}


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to