]> 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)
commit161b41b2d60ad383169ff03d7b094f3e13dea2db
tree880e700e6f02ba27d0f889747ee58d97738e1005
parentfd8418531d8be238f2d55d54daf4a325d5725818
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