Skip to content

Releases: Awesome-Embedded-Learning-Studio/CFBox

CFBox v0.3.0 — i.MX6ULL 端到端:cfbox 作为 PID 1

24 Jun 01:07

Choose a tag to compare

CFBox v0.3.0 — i.MX6ULL 端到端:cfbox 作为 PID 1

cfbox 在 NXP i.MX6ULL(armhf)上替代 BusyBox,作为 imx-forge rootfs 的 PID 1 + 工具集,撑起完整启动闭环。补齐 init/mount/mdev/umount/swapoff/reboot/poweroff 全部缺口,并新增 tail -f。

亮点

  • i.MX6ULL 端到端实测:cfbox 作为 PID 1 解析 /etc/inittab,跑 rcS(mount/mdev)冷启动建 /dev,askfirst 等回车进 console sh,关机走 umount/swapoff/reboot —— 在 imx-forge rootfs 上验证启动到 console
  • 新增 6 个 applet(117→123):mountmdevumountswapoffrebootpoweroff
  • init 扩展 askfirst:支持 busybox 格式 inittab 的 sysinit/askfirst/respawn/ctrlaltdel/shutdown
  • tail -f/-F follow 模式:fd-based follow(fstat 轮询 + 64KiB quantum + -F drain-switch + SIGINT 退出 0)
  • 串口 console 体验修复:sh cooked tty、默认 PATHls -l 属主/属组、VERASE=Ctrl-H 让退格键在串口上生效
  • 399 测试全绿(+20),零编译 warning,CI gcc-13 兼容

体积与测试对比

指标 v0.2.0 v0.3.0 变化
size-opt Release 406 KB 418 KB +12 KB
Applet 数量 117 123 +6
GTest 通过 379 399 +20
集成脚本 54 54 不变
编译 warning 0 0 不变

体积 +12 KB 来自新增 6 个系统 applet(mount/mdev/umount/swapoff/reboot/poweroff)+ init 的 inittab 解理扩展,仍在 ≤ 550 KB 预算内。Applet 基数取 git tag v0.2.0 实测注册表数(117)。

新增 Applet(6 个)

mount(-a/-t/-o,读 fstab), mdev(-s 冷启动扫 /sys), umount(-a/-r/-f), swapoff(-a), reboot, poweroff

变更详情

tail -f follow 模式(bff34e9)

  • 新增 -f/-F:fd-based follow,fstat 轮询检测增长 + 64 KiB quantum 读
  • -F:drain-switch(文件被截断/轮换时 drain 后继续)
  • SIGINT RAII guard,follow 模式下 Ctrl-C 退出码 0(不污染同进程后续 applet)

L2 rootfs 启动闭环

  • init askfirst(4b95168):解析 busybox 格式 /etc/inittab,新增 askfirst 动作 —— console getty 等回车激活,打印 Please press Enter to activate this console.
  • mount(65e1f17):mount -a(读 /etc/fstab)、-t <type>-o <opts> —— rcS 阶段 mount -a + mount -t devpts devpts /dev/pts
  • mdev(6ee0770):mdev -s 冷启动扫描 —— 扫 /sys/dev 下建设备节点(BusyBox mdev 兼容)
  • 关机集(de78018):umount -a -rswapoff -arebootpoweroff —— 补齐关机路径

串口 console 体验(8045c11 / a803b99)

  • sh:cooked tty 模式、默认 PATHVERASE=Ctrl-H(退格键在串口 console 上正确擦除)
  • ls -l:-l 长格式补属主/属组名(原仅显示数字 UID/GID)

CI / 构建兼容(d307998 / dc25a09)

  • init:消费 write() 返回值,满足 gcc-13 -Werror=unused-result
  • 显式 #include <algorithm>,满足 gcc-13 严格头包含

文档 / 展示(8c45c77 / a238d1c)

  • README 新增 i.MX6ULL 端到端实测段(启动阶段表 + 截图)+ scripts/gen_size_table.sh 体积表生成器
  • projects/imx-forge-demo:集成演示 submodule

本版本未完成(转入后续)

v0.2.0 规划的 Phase 2 第一批其余项仍在进行中:cp -atest POSIX、ls -R/--color(详见 document/ai/PLAN.md)。


完整变更记录:v0.2.0...v0.3.0


English Version

CFBox v0.3.0 — End-to-end on the i.MX6ULL: cfbox as PID 1

cfbox replaces BusyBox on the NXP i.MX6ULL (armhf), serving as PID 1 + toolset for the imx-forge rootfs and driving the full boot loop. This release closes every gap (init/mount/mdev/umount/swapoff/reboot/poweroff) and adds tail -f.

Highlights

  • i.MX6ULL end-to-end:cfbox as PID 1 parses /etc/inittab, runs rcS (mount/mdev) to cold-populate /dev, waits for Enter via askfirst to drop into a console sh, and shuts down through umount/swapoff/reboot — verified booting to console on the imx-forge rootfs
  • 6 new applets (117→123): mount, mdev, umount, swapoff, reboot, poweroff
  • init gains askfirst: BusyBox-format inittab with sysinit/askfirst/respawn/ctrlaltdel/shutdown
  • tail -f/-F follow: fd-based follow (fstat polling + 64 KiB quantum + -F drain-switch + SIGINT exits 0)
  • Serial console polish: sh cooked tty, default PATH, ls -l owner/group names, VERASE=Ctrl-H so backspace works on serial
  • 399 tests passing (+20), zero warnings, CI gcc-13 compatible

Size & Tests

Metric v0.2.0 v0.3.0 Change
size-opt Release 406 KB 418 KB +12 KB
Applet count 117 123 +6
GTest passing 379 399 +20
Integration scripts 54 54 Unchanged
Compiler warnings 0 0 Unchanged

The +12 KB comes from 6 new system applets + init's inittab parsing — still within the ≤ 550 KB budget. The v0.2.0 baseline is the actual git-tag registry count (117).

New Applets (6)

mount (-a/-t/-o, reads fstab), mdev (-s coldplug scan /sys), umount (-a/-r/-f), swapoff (-a), reboot, poweroff

Changes

tail -f follow mode (bff34e9)

  • Added -f/-F: fd-based follow via fstat growth polling + 64 KiB quantum reads
  • -F: drain-switch (drain and continue on truncation/rotation)
  • SIGINT RAII guard — Ctrl-C exits 0 in follow mode without polluting later applets in the same process

L2 rootfs boot loop

  • init askfirst (4b95168): parses BusyBox-format /etc/inittab; new askfirst action waits for Enter and prints Please press Enter to activate this console.
  • mount (65e1f17): mount -a (reads /etc/fstab), -t <type>, -o <opts>mount -a + mount -t devpts devpts /dev/pts during rcS
  • mdev (6ee0770): mdev -s coldplug — scans /sys to populate /dev (BusyBox mdev compatible)
  • Shutdown (de78018): umount -a -r, swapoff -a, reboot, poweroff

Serial console polish (8045c11 / a803b99)

  • sh: cooked tty, default PATH, VERASE=Ctrl-H (backspace erases correctly on serial)
  • ls -l: long format now shows owner/group names (previously numeric UID/GID only)

CI / build compatibility (d307998 / dc25a09)

  • init: consume write() return value for gcc-13 -Werror=unused-result
  • Explicit #include <algorithm> for gcc-13 strict include checking

Docs / showcase (8c45c77 / a238d1c)

  • README gains an i.MX6ULL end-to-end section (boot-stage table + screenshots) + scripts/gen_size_table.sh generator
  • projects/imx-forge-demo: integration demo submodule

Not in This Release (carried forward)

The remaining Phase 2 batch-1 items are still in progress: cp -a, test POSIX, ls -R/--color (see document/ai/PLAN.md).


Full Changelog: v0.2.0...v0.3.0

CFBox v0.2.0 — 优化与更新

27 May 03:50
a96ec85

Choose a tag to compare

CFBox v0.2.0 — 优化与更新

代码质量全面优化:二进制体积减少 14%,消除 iostream 运行时依赖,修复潜在 abort 风险。

亮点

  • 体积缩减 14%:size-opt Release 从 473 KB 降至 406 KB
  • 彻底消除 iostream 依赖:全量移除 <fstream> / <sstream> / <iostream>,零 fstream 符号残留
  • std::stoi 全部替换为 std::strtol:避免 -fno-exceptionsstoi 解析失败时直接 abort()
  • 353 测试全绿,零编译 warning,ASan 零泄漏

体积对比

指标 v0.1.0 v0.2.0 变化
size-opt Release 473 KB 406 KB -67 KB (-14%)
fstream 符号 0 彻底消除
std::stoi 调用 多处 0 全部替换
GTest 通过 353 353 不变
编译 warning 0 0 不变
Applet 数量 115 115 不变

新增 Applet(6 个)

chgrp, chmod, chown, clear, mountpoint, which

变更详情

Phase 1 — 零风险编译选项与基础设施

  • 全局启用 -fno-exceptions -fno-rtti
  • 新增 -Wformat-signedness -Wstrict-aliasing 编译警告
  • 修复 install.cpp 唯一 try/catchstrtoul + errno
  • 修复多处 %d / %u 格式不匹配(unsigned 值配 %d

Phase 2 — 明确 Bug 修复

  • dmesg.cpp:FILE* 泄漏 → io::unique_file RAII
  • init.hpp:信号标志 boolvolatile sig_atomic_t

Phase 3 — std::string / string_view 清理

  • 消除多处循环内不必要的 std::string{string_view} 构造
  • 涉及:term.hpp, grep.cpp, io.hpp, test.cpp, mkdir.cpp, ls.cpp

Phase 4 — 统一错误报告宏

  • 定义 CFBOX_ERR(cmd, fmt, ...) / CFBOX_ERR_V(cmd, fmt, ...)
  • 102 个 applet 全量迁移 fprintf(stderr, "cfbox xxx: ...") → 宏

Phase 5 — fs_util 扩展

  • fs_util.hpp 新增 chown() / lchown() / for_each_entry()
  • 重构 chown.cpp, chgrp.cpp, chmod.cpp 使用新 API,消除重复递归遍历代码

Phase 6 — iostream 清理

  • hexdump.cpp, more.cpp:移除未使用的 <fstream>
  • rev.cppistreamFILE* + fgets
  • pmap.cppifstream / istringstreamFILE* + fgets + sscanf
  • sysctl.cppifstream / ofstreamFILE* + fgets / fprintf
  • proc.hpp:8 处 ifstream / istringstream / ostringstream 全部转为 <cstdio>
  • io.hppread_all() 修复 /proc 虚拟文件 ftell 返回 0 的问题

Phase 7 — stoi 安全化 + I/O 审计

  • cut.cpp:5 处 std::stoistd::strtol
  • fuser.cppstd::stoistd::strtol
  • D3 I/O 审计:现有 read_all() 调用者均需全量数据,无需流式化

新增基础设施

组件 说明
CFBOX_ERR / CFBOX_ERR_V 统一错误输出宏(Phase 4)
fs::chown() / fs::lchown() chown 系统调用封装(Phase 5)
fs::for_each_entry() 递归/非递归目录遍历模板(Phase 5)

本轮额外完成

  • Phase 9:测试覆盖补全 — 为 cat, echo, head, tail, wc 补 GTest 单元测试(+26 测试,379 全绿)
  • CI ccache 加速 — GitHub Actions 全部构建作业配置 ccache + 缓存

完整变更记录v0.1.0...v0.2.0


English Version

CFBox v0.2.0 — Optimization & Updates

Comprehensive code quality optimization: 14% binary size reduction, iostream runtime dependency eliminated, potential abort risks fixed.

Highlights

  • 14% size reduction: size-opt Release shrinks from 473 KB to 406 KB
  • iostream dependency fully removed: all <fstream> / <sstream> / <iostream> eliminated, zero fstream symbols remaining
  • All std::stoi replaced with std::strtol: prevents abort() on parse failure under -fno-exceptions
  • 353 tests passing, zero compiler warnings, ASan zero leaks

Size Comparison

Metric v0.1.0 v0.2.0 Change
size-opt Release 473 KB 406 KB -67 KB (-14%)
fstream symbols Yes 0 Eliminated
std::stoi calls Multiple 0 All replaced
GTest passing 353 353 Unchanged
Compiler warnings 0 0 Unchanged
Applet count 115 115 Unchanged

Additionally Completed in This Release

  • Phase 9: Test coverage — GTest tests for cat, echo, head, tail, wc (+26 tests, 379 all passing)
  • CI ccache — ccache + cache configured for all GitHub Actions build jobs

New Applets (6)

chgrp, chmod, chown, clear, mountpoint, which

Changes

Phase 1 — Compiler Flags & Infrastructure

  • Globally enabled -fno-exceptions -fno-rtti
  • Added -Wformat-signedness -Wstrict-aliasing warning flags
  • Fixed sole try/catch in install.cppstrtoul + errno
  • Fixed multiple %d / %u format mismatches

Phase 2 — Bug Fixes

  • dmesg.cpp: FILE* leak → io::unique_file RAII
  • init.hpp: signal flags boolvolatile sig_atomic_t

Phase 3 — std::string / string_view Cleanup

  • Eliminated unnecessary std::string{string_view} constructions in hot paths
  • Files: term.hpp, grep.cpp, io.hpp, test.cpp, mkdir.cpp, ls.cpp

Phase 4 — Unified Error Reporting Macros

  • Defined CFBOX_ERR(cmd, fmt, ...) / CFBOX_ERR_V(cmd, fmt, ...) macros
  • Migrated all 102 applets from fprintf(stderr, "cfbox xxx: ...") to macros

Phase 5 — fs_util Extensions

  • Added chown() / lchown() / for_each_entry() to fs_util.hpp
  • Refactored chown.cpp, chgrp.cpp, chmod.cpp to use new APIs

Phase 6 — iostream Cleanup

  • Removed unused <fstream> from hexdump.cpp, more.cpp
  • Converted rev.cpp, pmap.cpp, sysctl.cpp from ifstream/ofstream to FILE* + <cstdio>
  • Converted all 8 ifstream/istringstream/ostringstream usages in proc.hpp to <cstdio>
  • Fixed io::read_all() for /proc virtual files (ftell returns 0)

Phase 7 — stoi Safety & I/O Audit

  • Replaced std::stoi with std::strtol in cut.cpp (5 sites) and fuser.cpp
  • I/O audit: all read_all() callers require full data; no safe streaming conversions found

New Infrastructure

Component Description
CFBOX_ERR / CFBOX_ERR_V Unified error output macros (Phase 4)
fs::chown() / fs::lchown() chown syscall wrappers (Phase 5)
fs::for_each_entry() Recursive/non-recursive directory traversal template (Phase 5)

Full Changelog: v0.1.0...v0.2.0


下一步:Phase 2 — 核心命令深化(v0.3.0 规划)

将现有命令功能深度从 ~30% 提升到 ~70%,按运维频率分批推进。

第一批(v0.3.0)

命令 关键补充 优先级
tail -f follow 模式(inotify/polling) P0
cp -a archive 模式(保留权限/链接/时间戳/递归) P0
test 全面 POSIX:-a/-o/字符串比较/文件类型/-nt/-ot P0
ls -R 递归 + --color 彩色输出 P1

第二批(v0.4.0)

命令 关键补充
grep -A/-B/-C 上下文行、--include/--exclude
tar -z gzip、-v verbose、-C 目录切换
sed -i 原地编辑、多命令 -e
sort -k 按列排序、-n 数值排序、-u 去重

第三批(v0.5.0)

命令 关键补充
find 布尔表达式(-and/-or/!)、-type f/-name
sh case/heredoc/函数/return
ps -aux/-ef、线程显示
df/du -h 人类可读、-T 文件系统类型

V0.1.0 Release

08 May 04:46
780cf9f

Choose a tag to compare

CFBox v0.1.0 — 首个正式发布

C++23 BusyBox 替代品。109 个 applet,零外部运行时依赖,可作为 PID 1 运行。

亮点

  • 109 个 applet,覆盖 shell、coreutils、findutils、文本处理、归档压缩、进程管理和 init 系统
  • 完整 POSIX Shell——管道、重定向、控制流、变量/命令展开、glob、15 个内建命令
  • 完整 AWK 解释器——模式匹配、关联数组、printf、用户自定义函数、正则
  • Init 系统——inittab 解析、运行级别管理、服务监控与 respawn、优雅关机;已在 QEMU aarch64 上以 PID 1 验证
  • 零外部运行时依赖——自研 deflate/inflate 替代 zlib,单文件静态链接
  • 446 KB size-opt Release 构建(visibility hidden + section GC + strip)
  • 331 单元测试 + 54 集成测试,全部通过,ASan 零泄漏

Applet 列表

Shell

sh — 交互式 POSIX shell(词法/语法/执行器,7 个模块 ~2400 行)

Coreutils(60 个)

basename, cat, chgrp, chmod, chown, cksum, comm, cp, cut, date, df, dirname, du, echo, env, expand, expr, factor, false, fold, hostid, hostname, id, install, link, ln, logname, ls, md5sum, mkdir, mkfifo, mknod, mktemp, mv, nl, nproc, od, paste, printenv, printf, pwd, readlink, realpath, rm, rmdir, seq, shuf, sleep, sort, split, stat, sum, sync, tac, tee, test, touch, tr, true, truncate, tsort, tty, uname, unlink, usleep, wc, who, whoami, yes

文本处理

awk, diff, patch, ed, grep, sed

归档与压缩

tar, cpio, ar, unzip, gzip, gunzip

findutils

find, xargs

procps(15 个)

ps, kill, free, uptime, top, watch, pgrep, pkill, pidof, sysctl, pwdx, pstree, pmap, fuser, iostat

util-linux

dmesg, hexdump, more, rev, cal, renice

Init

init

基础设施

组件 说明
args.hpp GNU 风格长选项解析器
help.hpp 统一 --help / --version 输出
term.hpp ANSI 彩色输出(尊重 NO_COLOR
utf8.hpp Unicode 感知的字符计数与宽度
stream.hpp 流式行读取器(for_each_line
checksum.hpp CRC-32、MD5、BSD/SysV sum
compress.hpp 轻量 deflate/inflate(替代 zlib)
terminal.hpp Raw mode RAII、光标控制、备用屏幕缓冲
tui.hpp 全屏 TUI 框架(ScreenBuffer、SIGWINCH)
proc.hpp 集中式 /proc 解析器
fs_util.hpp 扩展文件系统工具
error.hpp std::expected 错误处理(CFBOX_TRY

性能优化

  • Myers O(ND) diff 算法——替代 O(mn) LCS
  • POSIX regex_t——替代 std::regex(grep/sed 加速)
  • 流式 I/O——grep/cat/wc 可处理无限输入
  • 预计算排序 key——避免比较器中重复内存分配
  • 全局 reserve()——diff/ls/timeout/unzip/find 等场景预分配
  • 72 个函数添加 noexcept / [[nodiscard]] / constexpr 标注
  • RAII 封装——unique_filescoped_regexunique_pipe(ASan 验证零泄漏)

构建与 CI

  • CMake 支持 per-applet CFBOX_ENABLE_<APPLET> 开关及预设 profile(embedded / desktop / minimal / full
  • CI 覆盖原生构建、交叉编译(armhf、aarch64)和 QEMU 启动测试
  • 体积优化:cmake -DCMAKE_BUILD_TYPE=Release -DCFBOX_SIZE_OPT=ON

已验证平台

  • x86_64(原生)
  • aarch64(QEMU,含 PID 1 init 启动)
  • armhf(QEMU)

下一步计划

  • Phase 5:vi 可视化编辑器
  • Phase 6:网络工具 + 登录管理 + 系统日志
  • Phase 7:剩余 applet + 全面 POSIX 合规验证

完整变更记录https://github.com/Awesome-Embedded-Learning-Studio/cfbox/commits/v0.1.0


English Version

CFBox v0.1.0 — First Release

C++23 BusyBox alternative. 109 applets, zero external runtime dependencies, runs as PID 1.

Highlights

  • 109 applets across shell, coreutils, findutils, text processing, archiving, compression, process management, and init
  • Full POSIX Shell — pipes, redirections, control flow, variable/command expansion, glob, 15 builtins
  • Complete AWK interpreter — patterns, associative arrays, printf, user functions, regex
  • Init system — inittab parser, runlevel management, service monitoring with respawn, clean shutdown; verified on QEMU aarch64 as PID 1
  • Zero external runtime deps — custom deflate/inflate replaces zlib; static-linked single binary
  • 446 KB size-optimized Release build (visibility hidden + section GC + strip)
  • 331 unit tests + 54 integration tests, all passing, ASan zero leaks

Applets

Shell

sh — interactive POSIX shell (lexer/parser/executor, 7 modules, ~2400 LOC)

Coreutils (60)

basename, cat, chgrp, chmod, chown, cksum, comm, cp, cut, date, df, dirname, du, echo, env, expand, expr, factor, false, fold, hostid, hostname, id, install, link, ln, logname, ls, md5sum, mkdir, mkfifo, mknod, mktemp, mv, nl, nproc, od, paste, printenv, printf, pwd, readlink, realpath, rm, rmdir, seq, shuf, sleep, sort, split, stat, sum, sync, tac, tee, test, touch, tr, true, truncate, tsort, tty, uname, unlink, usleep, wc, who, whoami, yes

Text Processing

awk, diff, patch, ed, grep, sed

Archiving & Compression

tar, cpio, ar, unzip, gzip, gunzip

findutils

find, xargs

procps (15)

ps, kill, free, uptime, top, watch, pgrep, pkill, pidof, sysctl, pwdx, pstree, pmap, fuser, iostat

util-linux

dmesg, hexdump, more, rev, cal, renice

Init

init

Infrastructure

Component Description
args.hpp GNU-style long option parser
help.hpp Unified --help / --version for all applets
term.hpp ANSI color output (respects NO_COLOR)
utf8.hpp Unicode-aware character counting & width
stream.hpp Streaming line reader (for_each_line)
checksum.hpp CRC-32, MD5, BSD/SysV sum
compress.hpp Lightweight deflate/inflate (replaces zlib)
terminal.hpp Raw mode RAII, cursor control, alternate screen
tui.hpp Full-screen TUI framework (ScreenBuffer, SIGWINCH)
proc.hpp Centralized /proc parser
fs_util.hpp Extended filesystem utilities
error.hpp std::expected error handling (CFBOX_TRY)

Optimizations

  • Myers O(ND) diff — replaced O(mn) LCS algorithm
  • POSIX regex_t — replaced std::regex in grep/sed
  • Streaming I/O — grep/cat/wc process unbounded input without buffering
  • Pre-computed sort keys — avoids repeated allocations in comparator
  • Global reserve() — diff, ls, timeout, unzip, find pre-allocate known sizes
  • 72 functions annotated with noexcept / [[nodiscard]] / constexpr
  • RAII wrappersunique_file, scoped_regex, unique_pipe (ASan-verified zero leak)

Build & CI

  • CMake with per-applet CFBOX_ENABLE_<APPLET> toggles and preset profiles (embedded / desktop / minimal / full)
  • CI covers native build, cross-compilation (armhf, aarch64), and QEMU boot tests
  • Size-optimized profile: cmake -DCMAKE_BUILD_TYPE=Release -DCFBOX_SIZE_OPT=ON

Tested On

  • x86_64 (native)
  • aarch64 (QEMU, including PID 1 init)
  • armhf (QEMU)

What's Next

  • Phase 5: vi visual editor
  • Phase 6: Networking + login management + syslog
  • Phase 7: Remaining applets + full POSIX compliance verification

Full Changelog: https://github.com/Awesome-Embedded-Learning-Studio/cfbox/commits/v0.1.0