]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: LZ4 official Frame format for initrd compression/decompression
authorTulio A M Mendes <[email protected]>
Mon, 16 Feb 2026 22:24:18 +0000 (19:24 -0300)
committerTulio A M Mendes <[email protected]>
Mon, 16 Feb 2026 22:24:18 +0000 (19:24 -0300)
commit33bbe8963d1397eae95b6651e4754152680d18a4
tree4f7d528b0c4fbc210bee23edf70a4789a3a164c6
parent680a9f71b753c75e86d1adea42643e057abfcd46
feat: LZ4 official Frame format for initrd compression/decompression

Replace custom 'LZ4B' block wrapper with the official LZ4 Frame format
(spec: https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md).

Compressor (tools/mkinitrd.c):
- Write official frame: magic 0x184D2204, FLG/BD descriptor with
  content size and content checksum flags, xxHash-32 header checksum,
  data block, EndMark, xxHash-32 content checksum
- Fix block compressor MFLIMIT: last match must start >= 12 bytes
  before end of block (was 5, violating spec)

Decompressor (src/kernel/lz4.c):
- New lz4_decompress_frame() parses frame header, verifies header
  checksum via xxHash-32, decompresses blocks, verifies content checksum
- Existing lz4_decompress_block() unchanged (used internally)

Kernel initrd loader (src/drivers/initrd.c):
- Detect official LZ4 Frame magic (0x184D2204) first
- Keep legacy LZ4B detection as backward-compat fallback
- initrd_init() now takes size parameter for frame bounds checking

New files:
- include/xxhash32.h: standalone header-only xxHash-32 implementation

Cross-compatibility verified:
- 'lz4 -t initrd.img' validates our frame (official lz4 v1.9.4)
- 'lz4 -d initrd.img' decompresses correctly, tar lists all 12 files
- 83/83 smoke tests pass, cppcheck clean
Makefile
include/initrd.h
include/lz4.h
include/xxhash32.h [new file with mode: 0644]
src/drivers/initrd.c
src/kernel/init.c
src/kernel/lz4.c
tools/mkinitrd.c