You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "Zepp-Hanzj (via GitHub)" <gi...@apache.org> on 2026/07/01 12:25:37 UTC

[PR] libc/crc32: add IEEE-compatible crc32_ieee for Linux/zlib interop [nuttx]

Zepp-Hanzj opened a new pull request, #19246:
URL: https://github.com/apache/nuttx/pull/19246

   ## Summary
   
   Fixes #14532
   
   The existing crc32() uses init=0 with no final XOR, which differs from the Linux/zlib standard CRC32 (init=0xFFFFFFFF, final XOR 0xFFFFFFFF). This causes interoperability issues when exchanging CRC32 values between NuttX and Linux systems (e.g., UART protocols, file integrity checks).
   
   Add two new functions following the crc8/crc16 variant naming convention:
   
   - crc32_ieee(src, len) — full CRC, Linux/zlib compatible
   - crc32_ieeepart(src, len, crcval) — incremental CRC, Linux/zlib compatible
   
   The existing crc32() and crc32part() are unchanged to avoid breaking existing callers (bbsram, sbram, etc.).
   
   ## Verification
   
   Built and tested on sim:nsh. Used known Linux zlib CRC32 test vectors.
   
   Build command:
   
     make distclean
     tools/configure.sh sim:nsh
     make -j$(nproc)
   
   Run command:
   
     printf 'hello\npoweroff\n' | timeout 30 ./nuttx 2>/dev/null
   
   Test output:
   
     NuttShell (NSH) NuttX-13.0.0-RC0
     nsh> hello
     === crc32_ieee compatibility test ===
     crc32("hello")      = 0xf032519b (old, init=0)
     crc32_ieee("hello") = 0x3610a686 (expected 0x3610a686)
       PASS
     crc32("123456789")      = 0x2dfd2d88
     crc32_ieee("123456789") = 0xcbf43926 (expected 0xcbf43926)
       PASS
     crc32("")      = 0x00000000
     crc32_ieee("") = 0x00000000 (expected 0x00000000)
       PASS
     crc32_ieeepart incremental("123456789") = 0xcbf43926 (expected 0xcbf43926)
       PASS
     crc32("hello") = 0xf032519b (should be unchanged from before)
       (old crc32 backward compatible - no reference value needed)
     === Results: 5 pass, 0 fail ===
     nsh> poweroff
   
   Test vectors verified against Linux zlib crc32():
     crc32_ieee("hello")     = 0x3610a686 — matches Linux
     crc32_ieee("123456789") = 0xcbf43926 — matches Linux
     crc32_ieee("")           = 0x00000000 — matches Linux
     crc32_ieeepart incremental — matches one-shot crc32_ieee
     crc32("hello")           = 0xf032519b — unchanged, backward compatible


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] libc/crc32: add IEEE-compatible crc32_ieee for Linux/zlib interop [nuttx]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19246:
URL: https://github.com/apache/nuttx/pull/19246#issuecomment-4854828457

   <!-- membrowse-pr-comment -->
   ## <img src="https://membrowse.com/membrowse-logo.svg" height="24" align="top"> MemBrowse Memory Report
   
   *No memory changes detected for:*
   - [arduino-mega2560](https://membrowse.com/public/apache/nuttx/target/arduino-mega2560/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [esp32-devkitc](https://membrowse.com/public/apache/nuttx/target/esp32-devkitc/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [hifive1-revb](https://membrowse.com/public/apache/nuttx/target/hifive1-revb/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [mirtoo](https://membrowse.com/public/apache/nuttx/target/mirtoo/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [qemu-armv8a](https://membrowse.com/public/apache/nuttx/target/qemu-armv8a/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [qemu-intel64](https://membrowse.com/public/apache/nuttx/target/qemu-intel64/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [rx65n-rsk2mb](https://membrowse.com/public/apache/nuttx/target/rx65n-rsk2mb/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [s698pm-dkit](https://membrowse.com/public/apache/nuttx/target/s698pm-dkit/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   - [stm32-nucleo-f103rb](https://membrowse.com/public/apache/nuttx/target/stm32-nucleo-f103rb/compare?head=d419c84e6d3f6eea42a24c28bfb2ca4d545dae31&base=76838fa1b2a5cc8aadd29725e081fbd779faa04b)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] libc/crc32: add IEEE-compatible crc32_ieee for Linux/zlib interop [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #19246:
URL: https://github.com/apache/nuttx/pull/19246#issuecomment-4862483922

   @Zepp-Hanzj please fix:
   ```
   Warning, treated as error:
   /home/runner/work/nuttx/nuttx/Documentation/implementation/crc.rst:55:Malformed table.
   Text in column margin in table line 5.
   
   ===========  ============  ==========  ==========
   Function     Init Value    Final XOR   Polynomial
   ===========  ============  ==========  ==========
   crc32()      0x00000000    None        0xEDB88320
   crc32_ieee() 0xFFFFFFFF    0xFFFFFFFF  0xEDB88320
   ===========  ============  ==========  ==========
   make: *** [Makefile:52: html] Error 2
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] libc/crc32: add IEEE-compatible crc32_ieee for Linux/zlib interop [nuttx]

Posted by "Zepp-Hanzj (via GitHub)" <gi...@apache.org>.
Zepp-Hanzj commented on PR #19246:
URL: https://github.com/apache/nuttx/pull/19246#issuecomment-4861402004

   Done! Added a CRC section under Implementation Details at `Documentation/implementation/crc.rst` covering:
   
   - The difference between `crc32()` (NuttX native, init=0) and `crc32_ieee()` (Linux/zlib compatible, init=0xFFFFFFFF + final XOR)
   - A comparison table with concrete example values
   - Incremental calculation usage
   - Other CRC32 polynomial variants
   
   Added to the toctree in `Documentation/implementation/index.rst`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] libc/crc32: add IEEE-compatible crc32_ieee for Linux/zlib interop [nuttx]

Posted by "Zepp-Hanzj (via GitHub)" <gi...@apache.org>.
Zepp-Hanzj commented on PR #19246:
URL: https://github.com/apache/nuttx/pull/19246#issuecomment-4862613515

   @xiaoxiang781216 Fixed! The RST table column separator for 'Function' was too narrow for 'crc32_ieee()'. Widened it from 11 to 14 characters.
   
   CI docs build should pass now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org