RepositoryCVNVietnam
Vinalinux-Org

Vinalinux-Org/Nothan-OS

A reference operating system for embedded platforms, with initial bring-up on Beaglebone Black (ARM Cortex-A8).

120stars
19forks
1issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: cortex-a

#1 Repository of the week

1
TINIX TRENDING·Topic: armv7

#1 Repository of the week

1
TINIX TRENDING·Topic: embedded-os

#1 Repository of the week

NothanOS — Bare-metal ARM Operating System

Bare-metal operating system + cross-compiler cho ARMv7-A, chạy trên phần cứng thật (BeagleBone Black).

Được phát triển bởi Vinalinux như một reference platform 100% tự viết — kernel, libc, userspace, compiler. Không dựa trên Linux/Unix/BSD; không fork/port upstream; không emulator. Mọi dòng code trong repo đều tự tay gõ, hiểu, chịu trách nhiệm.


Screenshots

Boot Log

Boot Log

Splash Screen

Splash Screen

Home Screen

Home Screen


Tổng Quan

Project gồm 2 components chính:

ComponentMô TảNgôn Ngữ
NothanOSBare-metal OS: bootloader, kernel, userspace shell, HDMI displayC, ARM Assembly
NothCCCross-compiler: Subset C → ARMv7-A ELF binaryPython

NothanOS — Hệ Điều Hành

Bootloader (MLO)

  • Khởi tạo hardware: clocks, watchdog, DDR3 memory, UART
  • Load kernel từ SD card (sector 2048) vào DDR3 0x80000000
  • Jump sang kernel với ARM boot parameters (r1 = MACH_TYPE)

Kernel

SubsystemChi Tiết
HAL 4 lớpkernel/ generic · arch/arm/ ARMv7 CPU · platform/bbb/ AM3358 board · drivers/ device impls
MMU3G/1G split: User VA 0x40000000 (1 MB, per-process L2 + TTBR0), Kernel VA 0xC0000000 (L1 section)
MemoryBitmap page allocator (112 MB pool), slab (kmem_cache_*), kmalloc(GFP_KERNEL), VMM (mm_struct, vm_area_struct)
Concurrencyspinlock_t (LDREX/STREX), atomic_t, wait_queue_head_t, wait_event/wake_up, blocking I/O
Exception7 types, INTC 128 IRQ, DFSR/DFAR decode, user fault → SIGSEGV (kernel sống), kernel fault → PANIC dump
SchedulerPreemptive round-robin, 10 ms tick (DMTimer2), MAX_TASKS = 5, context switch ARM asm + TTBR0 swap
Processfork/exec/wait/exit/kill, ELF loader, per-process fd table, task_struct, current
Syscalls22 syscall qua SVC, AAPCS ABI, copy_from/to_user, negative errno
VFSMulti-FS: FAT32 rootfs (subdir/unlink/rename) + devfs (/dev/tty, /dev/null) + procfs (/proc/...)
Blockblock_device abstraction, LRU buffer cache 64×512 B write-back
Driver modelLinux-style platform_device/driver, bus matching, platform_get_resource
Userspaceinit (PID 1) + shell fork+exec + 10 external coreutils + nothanlibc POSIX subset (~1.4 KLOC)
HDMI Display800×600 RGB565, TDA19988 HDMI transmitter qua I2C, LCDC framebuffer

HDMI Graphics Stack

Framebuffer API (fb.c)  ←  800×600 RGB565, font 8×16, fb_fillcircle
        ↓
LCDC Driver (AM335x)    ←  Raster mode, 40MHz pixel clock (DPLL)
        ↓
TDA19988 (I2C-controlled) ←  HDMI transmitter, TMDS output
        ↓
HDMI Output 800×600@60Hz

Boot screen sequence:

  1. Boot Log — 16 hardware init steps với [ OK ] indicators, animation 300ms/dòng
  2. Splash — "NOTHAN OS" scale-6, animated dots, ~4.5 giây
  3. Home Launcher — status bar (clock, wifi, battery), app icon grid 4×2, page dots

Userspace

  • init (PID 1) — respawn loop, fork+exec /bin/sh, reap zombie
  • shell (/bin/sh) — fork+exec external ELF, built-ins (cd, pwd, help, exit), redirect > < >>, auto-prepend /bin/ cho command không có /
  • Coreutils — 10 ELFs trên /bin/: ls cat echo ps kill pwd free uname rm mv (mỗi utility ~30–150 LOC, link nothanlibc)
  • nothanlibc — POSIX subset ~1.4 KLOC: string.h, stdio.h (printf family + FILE), stdlib.h (K&R free-list malloc), unistd.h, fcntl.h, ctype.h, errno.h, signal.h, sys/stat.h, sys/wait.h
  • crt0.S — argv passthrough, BSS clear, call main(argc, argv), sys_exit(rc) fallback

NothCC — Cross Compiler

Compiler viết bằng Python, compile Subset C → ARMv7-A ELF32 binary chạy trên NothanOS.

Pipeline

Source (.c) → [Lexer] → [Parser] → [Semantic] → [IR Gen] → [Codegen] → [Assembler] → [Linker] → ELF
PhaseModuleOutput
Lexerfrontend.lexerToken stream
Parserfrontend.parserAST
Semantic Analyzerfrontend.semanticAnnotated AST + Symbol Table
IR Generatormiddleend.irThree-Address Code (3AC)
Code Generatorbackend.armv7aARM Assembly (.s)
Assemblerwraps arm-linux-gnueabihf-asObject file (.o)
Linkerwraps arm-linux-gnueabihf-ldELF32 binary

Subset C Support

CategoryFeatures
Typesint (32-bit), char (8-bit), void, pointers (int*, char*), 1D arrays
Control Flowif/else, while, for, return
FunctionsDefinition, call, recursion (max 4 params via r0-r3)
OperatorsArithmetic, comparison, logical, bitwise, assignment

Hardware

ComponentSpec
BoardBeagleBone Black Rev.C
SoCTexas Instruments AM335x
CPUARM Cortex-A8 @ 800 MHz (ARMv7-A)
RAM512 MB DDR3 @ 400 MHz
StoragemicroSD card
DisplayHDMI via TDA19988 (800×600@60Hz)
ConsoleUART0 @ 115200 8N1

Yêu Cầu Hệ Thống

Phần Cứng

  • BeagleBone Black (~$60)
  • microSD card ≥ 128 MB
  • USB-to-Serial adapter (3.3V TTL) — GND, RX, TX — cho UART console
  • HDMI monitor — để xem boot screen và home launcher
  • 5V/2A power supply

Phần Mềm

OS: Ubuntu 22.04 LTS (khuyến nghị)

Dependencies:

sudo apt-get update
sudo apt-get install -y \
    gcc-arm-none-eabi binutils-arm-none-eabi \
    binutils-arm-linux-gnueabihf \
    python3 python3-pip \
    build-essential make git \
    screen minicom

Kiểm tra cài đặt thành công:

arm-none-eabi-gcc --version        # Cross-compiler cho kernel
arm-linux-gnueabihf-as --version   # Assembler cho NothCC runtime
python3 --version                  # Python cho NothCC compiler

Nếu dùng serial console, thêm user vào group dialout (cần logout/login lại):

sudo usermod -a -G dialout $USER

Cài Đặt và Build

Phần A — Cài Đặt NothanOS

Bước 1: Clone

git clone https://github.com/Vinalinux-Org/Nothan-OS.git
cd Nothan-OS

Bước 2: Build NothanOS (bootloader + kernel + userspace)

make

Output:

  • bootloader/MLO — first-stage bootloader
  • nothan-kernel/build/kernel.bin — kernel với embedded init (PID 1 payload)
  • userspace/build/apps/<app>/<app>.elf — 10 external utilities + init + shell

Bước 3: Flash SD Card

# Tìm device SD card
lsblk   # trước khi cắm
lsblk   # sau khi cắm → device mới là SD card (vd: /dev/sdb)

Build + deploy userspace ELFs + flash MLO/kernel trong một bước:

sudo ./scripts/deploy_and_flash.sh /dev/sdX

Chỉ ghi đè MLO + kernel (không đụng FAT32 rootfs):

sudo ./scripts/flash_sdcard.sh /dev/sdX

⚠️ Kiểm tra kỹ device trước khi chạy — dd vào sai ổ sẽ phá dữ liệu.

Disk layout (RAW mode — TRM 26.1.8.5.5):

Sector 256  (128KB) — MLO (TOC + GP header + code)
Sector 512  (256KB) — MLO redundant copy
Sector 768  (384KB) — MLO redundant copy
Sector 2048 (1MB)   — kernel.bin

Bước 4: Kết Nối Serial Console

screen /dev/ttyUSB0 115200
# hoặc
minicom -D /dev/ttyUSB0 -b 115200

Nếu không thấy output, kiểm tra đã chạy sudo usermod -a -G dialout $USER và logout/login lại chưa (xem phần Dependencies).

Bước 5: Boot BeagleBone Black

  1. Cắm SD card vào BeagleBone Black
  2. Giữ nút BOOT (gần SD card slot)
  3. Cắm nguồn 5V
  4. Thả nút BOOT sau 2–3 giây

Trên UART console (rút gọn):

NothanOS Bootloader — DDR 128MB OK, loading kernel ...
[PLATFORM] AM3358 + BeagleBone Black
[DRIVER] probing omap-uart / omap-dmtimer / omap-intc / omap-hsmmc
[MM] page_alloc pool 112 MB, slab ready, kmalloc OK
[SCHED] preemptive RR 10ms, MAX_TASKS=5
[VFS] mount / fat32, /dev devfs, /proc procfs
[BOOT] init (pid 1) started from payload
[INIT] fork+exec /bin/sh

#

Trên HDMI monitor: Boot log → Splash → Home launcher

Bước 6: Dùng Shell

# ls /
bin  sbin  etc
# ls /bin
cat  echo  free  hello  kill  ls  mv  ps  pwd  rm  sh  uname
# ps
  PID  PPID  STATE     CMD
    0     0  RUNNING   idle
    1     0  INT       /sbin/init
    2     1  RUNNING   /bin/sh
# echo "hello" > /tmp/test
# cat /tmp/test
hello
# cat /proc/meminfo
# cat /proc/1/status
# kill 3

NothanOS đã sẵn sàng. Tiếp theo có thể dùng NothCC để viết và chạy chương trình C riêng.


Phần B — Compile và Chạy Chương Trình với NothCC

Bước 1: Cài đặt NothCC

bash scripts/install_compiler.sh
source ~/.bashrc

Kiểm tra:

nothcc --version
# Expected: nothcc 0.1.0

Bước 2: Compile thử chương trình test

nothcc -o test_hello compiler/tests/programs/test_hello.c

Nếu thành công sẽ tạo file test_hello (ELF32 binary):

file test_hello
# Expected: ELF 32-bit LSB executable, ARM, EABI5 ...

Bước 3: Deploy binary sang SD card

Đặt ELF vào /bin/ trên FAT32 partition đã mount (/media/$USER/NOTHAN/bin/test_hello), hoặc rebuild + deploy toàn bộ rootfs:

sudo ./scripts/deploy_and_flash.sh /dev/sdX

Boot lại BeagleBone Black (giữ nút BOOT → cắm nguồn), sau đó trên shell:

$ ls /bin
cat  echo  free  kill  ls  mv  ps  pwd  rm  sh  test_hello  uname

$ /bin/test_hello
Hello, NothanOS!

Cấu Trúc Project

Nothan-OS/
├── nothan-kernel/
│   ├── bootloader/          ← MLO (SRAM @ 0x402F0400)
│   ├── arch/arm/            ← entry.S, MMU asm, context switch, exception vectors
│   │   └── mach-omap2/      ← AM3358 board: memory map, IRQ, platform device table
│   ├── init/                ← main.c, payload.S, do_initcalls
│   ├── kernel/              ← core kernel: sched, locking, irq, time, printk
│   ├── drivers/             ← HW drivers + subsystem cores:
│   │   ├── tty/             (serial_core.c, serial/omap_serial.c)
│   │   ├── irqchip/         (irq-omap-intc.c)
│   │   ├── clocksource/     (timer-omap-dm.c)
│   │   ├── mmc/             (core/core.c, core/mmc_block.c, host/omap_hsmmc.c)
│   │   ├── i2c/             (i2c-core.c, busses/i2c-omap.c)
│   │   ├── gpu/drm/         (tilcdc, tda998x)
│   │   ├── video/fbdev/     (fbmem.c, fbcon.c)
│   │   ├── watchdog/        (omap_wdt.c)
│   │   ├── base/            (device.c, platform.c)
│   │   └── char/            (char_dev.c)
│   ├── fs/                  ← VFS, FAT32, devfs, procfs
│   ├── mm/                  ← page_alloc, slab, vmm
│   ├── block/               ← block layer, buffer_cache
│   ├── lib/                 ← string, format, fonts
│   ├── include/nothan/       ← subsystem headers
│   ├── userspace/
│   │   ├── apps/            ← init, shell, 10 coreutils + hello
│   │   ├── lib/             ← crt0.S, syscall wrappers
│   │   └── nothanlibc/       ← POSIX subset (~1.4 KLOC hand-written)
│   └── Documentation/       ← tài liệu kỹ thuật
│
├── compiler/
│   ├── toolchain/
│   │   ├── frontend/        ← Lexer, Parser, Semantic Analyzer
│   │   ├── middleend/ir/    ← IR Generator (3AC)
│   │   ├── backend/armv7a/  ← Code Generator, Register Allocator
│   │   └── runtime/         ← crt0.S, syscalls.S, divmod.S, app.ld
│   └── Documentation/       ← 5 tài liệu kỹ thuật
│
├── reference/               ← AM335x TRM, ARM arch, coding/comment/commit style, driver guide
│   ├── am335x/              ← Register map, peripheral config, clock/power (TRM reference)
│   ├── arm-arch/            ← ARM instruction set, exception handling, assembly
│   ├── hardware-beagleboneblack/ ← BBB schematic, P8/P9 pinout
│   ├── drivers/             ← Per-driver docs (SD card, FAT32, ...)
│   ├── coding-style.md      ← Naming convention, file layout, hard rules
│   ├── comment-style.md     ← Comment policy: when yes, when no
│   ├── commit-style.md      ← Commit format, type taxonomy, scope
│   ├── driver-development-guide.md ← 5-step driver writing process + template
│   └── project_context.md   ← Project status, WIP, conventions overview
│
├── scripts/
│   ├── setup-environment.sh
│   ├── install_compiler.sh
│   ├── deploy_and_flash.sh    ← Build + deploy rootfs + flash MLO/kernel
│   └── flash_sdcard.sh        ← Quick update MLO + kernel only
│
├── CLAUDE.md                ← AI enforcer: hard rules, debug workflow, code-gen protocol
├── Makefile
└── README.md

Project Status

ComponentTrạng TháiTài Liệu
Bootloader (MLO)✅ Shipped01-boot-and-bringup.md
Platform Layer (4-layer HAL)✅ Shippedplatform/bbb/
Memory (page_alloc + slab + kmalloc + VMM + L2)✅ Shipped03-memory-and-mmu.md
Concurrency (spinlock + atomic + wait_queue + sleep)✅ Shippedkernel/src/kernel/sync/
Interrupt + Exception Handling✅ Shipped04-interrupt-and-exception.md
Preemptive Scheduler✅ Shipped05-task-and-scheduler.md
Process Model (fork/exec/wait/kill/SIGSEGV)✅ Shippedkernel/src/kernel/proc/
Syscalls (22, AAPCS + errno)✅ Shipped06-syscall-mechanism.md
VFS + FAT32 + devfs + procfs + block + bcache✅ Shipped99-system-overview.md
Linux-style Driver Model (platform_device/driver)✅ Shippedkernel/src/kernel/driver/
nothanlibc (POSIX subset ~1.4 KLOC)✅ Shippeduserspace/nothanlibc/
Userspace (init + shell + 10 coreutils)✅ Shipped08-userspace-application.md
Selftest harness✅ Shippedkernel/src/kernel/test/selftest.c
HDMI Display (800×600) + Boot Screen✅ Shippedkernel/src/ui/boot_screen.c
Networking (CPSW + UDP/ICMP/ARP)⏳ Deferred to phase 2—
Compiler Frontend / IR / Backend / Runtime✅ Shippedarchitecture.md

Tài Liệu

NothanOS (Documentation/)

FileNội Dung
01-boot-and-bringup.mdROM → MLO → entry.S, MMU Phase A
02-kernel-initialization.mdkernel_main() step-by-step
03-memory-and-mmu.mdPage table, address translation
04-interrupt-and-exception.mdINTC, IRQ flow, exception handlers
05-task-and-scheduler.mdContext switch, round-robin
06-syscall-mechanism.mdSVC ABI, pointer validation
08-userspace-application.mdcrt0.S, linker script, shell
99-system-overview.mdBig picture, flows, memory map

Hardware Reference (reference/)

FileNội Dung
coding-style.mdNaming convention, file layout, coding hard rules
comment-style.mdComment policy, 5 allowed cases, anti-patterns
commit-style.mdCommit format, type taxonomy, scope selection
driver-development-guide.md5-step driver writing process, template, initcall levels
project_context.mdProject status, WIP, conventions overview
am335x/index.mdAM335x TRM register map, peripheral config, clock/power
arm-arch/index.mdARM instruction set, exception handling, assembly
hardware-beagleboneblack/index.mdBBB schematic, P8/P9 pinout

Compiler (compiler/Documentation/)

FileNội Dung
architecture.md7-phase pipeline, module organization
usage_guide.mdInstall, options, examples
subset_c_spec.mdNgôn ngữ Subset C specification
ir_format.mdThree-Address Code IR format
codegen_strategy.mdRegister allocation, ARM mapping

Nguyên Tắc Thiết Kế

PrincipleVí Dụ
100% hand-writtenKhông fork/port Linux/musl/BusyBox/lwIP. Mọi dòng tự viết.
Linux-inspired API shapetask_struct, platform_driver, spinlock_t, wait_event, kmalloc(GFP_KERNEL) — pattern Linux, code NothanOS
Userspace-driven kernelMỗi feature kernel phải có consumer trong userspace/demo. Không consumer → defer.
Simplicity over featuresMAX_TASKS = 5, single priority, bitmap page allocator, no COW fork
Correctness over performanceFlush toàn bộ TLB, no nested interrupts, -O2 không aggressive
Explicit over implicitExplicit MMU setup, copy_from/to_user cho mọi con trỏ user
Real hardware, no emulationMọi DoD pass trên BeagleBone Black thật, không QEMU

Troubleshooting

Boot fails (không thấy output UART):

  • Verify SD card đã flash đúng: sudo ./scripts/deploy_and_flash.sh /dev/sdX
  • Check serial connection: GND-GND, RX-TX, TX-RX, đúng 3.3V TTL
  • Verify baudrate 115200 8N1

Không có HDMI output:

  • HDMI cần pixel clock từ LCDC trước khi TDA19988 khởi động — kiểm tra thứ tự init
  • Monitor phải support 800×600@60Hz

Data Abort / MMU Fault:

  • Exception handler dump r0–r12, SPSR, DFSR, DFAR — log đủ để trace
  • User-mode fault → process bị SIGSEGV, kernel sống. Kernel-mode fault → PANIC dump
  • Nếu MMU fault ngay sau mmu_init(): check L1/L2 page table trong kernel/src/kernel/mmu/mmu.c

Build fails:

  • Verify arm-none-eabi-gcc đã install: arm-none-eabi-gcc --version
  • Dùng make -C nothan-kernel để build — Makefile tự xử lý build order (userspace trước kernel)

NothCC compiler error:

  • Kiểm tra feature có trong Subset C: xem subset_c_spec.md
  • ++/-- không hỗ trợ — dùng i = i + 1

FAQ

Tại sao không dùng Linux hoặc RTOS có sẵn? NothanOS nhắm sovereignty tuyệt đối — 100% tự viết từ zero (kernel, libc, userspace, compiler) để chủ sở hữu từng dòng code. Target market: defense/industrial embedded VN cần owned stack thay vì Yocto/Buildroot Linux.

Có phải là Unix/Linux clone không? Không. API shape (naming, struct layout, syscall convention) theo pattern Linux để dev biết Linux đọc code dễ, nhưng codebase độc lập — không fork, không port, không borrow dòng nào từ Linux/musl/BusyBox/lwIP upstream.

Tại sao BeagleBone Black? Giá ~$60, AM335x được document công khai qua TRM, không cần proprietary tools, ARMv7-A real hardware. Port sang SoC khác chỉ cần viết platform/<new>/ + driver — kernel không đổi dòng nào (4-layer HAL).

Tại sao ARMv7-A thay vì ARMv8/RISC-V? ARMv7-A đơn giản hơn (32-bit, 1 exception level) nhưng vẫn đại diện cho production embedded systems.

NothCC có thể compile chương trình phức tạp không? NothCC hỗ trợ Subset C — đủ cho algorithms, data structures, và I/O qua syscalls. Không có struct, malloc, standard library. NothCC CHỈ dùng cho end-user C program — kernel + libc + userspace của NothanOS build bằng arm-none-eabi-gcc.

Có network stack không? Phase 1 (hiện tại): chưa. Phase 2: hand-written CPSW driver + UDP/ICMP/ARP (no TCP).


License

This project is licensed under the MIT License.

Developed by Vinalinux.

Similar Projects

Discover other similar projects and AI models.

RepositoryC
reactos/reactos

A free Windows-compatible Operating System

18.6k
Nov 28, 2026
RepositoryC
vvaltchev/tilck

A Tiny Linux-Compatible Kernel

3.1k
Nov 26, 2026
RepositoryC
Awesome-HarmonyOS/HarmonyOS

A curated list of awesome things related to HarmonyOS. 华为鸿蒙操作系统。

20.0k
Jul 19, 2024
RepositoryC
s-matyukevich/raspberry-pi-os

Learning operating system development using Linux kernel and Raspberry Pi

14.0k
Mar 29, 2024
RepositoryC
RT-Thread/rt-thread

RT-Thread is an open source IoT Real-Time Operating System (RTOS). https://rt-thread.github.io/rt-thread/

12.4k
Nov 29, 2026
RepositoryC
unikraft/unikraft

A next-generation cloud native kernel designed to unlock best-in-class performance, security primitives and efficiency savings.

4.0k
Nov 30, 2026
RepositoryC++
SerenityOS/serenity

The Serenity Operating System 🐞

34.0k
Nov 28, 2026
RepositoryTypeScript
compiler-explorer/compiler-explorer

Run compilers interactively from your web browser and interact with the assembly

19.2k
Nov 30, 2026
RepositoryHTML
phil-opp/blog_os

Writing an OS in Rust

17.9k
Oct 28, 2026