{"id":42375399,"url":"https://github.com/kamil-kielbasa/ubi","last_synced_at":"2026-05-11T12:05:47.823Z","repository":{"id":306447692,"uuid":"1026219177","full_name":"kamil-kielbasa/ubi","owner":"kamil-kielbasa","description":"UBI (Unsorted Block Images): a wear-leveling volume manager for raw flash on Zephyr RTOS","archived":false,"fork":false,"pushed_at":"2026-04-11T19:09:31.000Z","size":6348,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-11T21:25:16.737Z","etag":null,"topics":["c","embedded","flash","nand","nor-flash","ubi","volume-manager","wear-leveling","zephyr","zephyr-rtos"],"latest_commit_sha":null,"homepage":"https://kamil-kielbasa.github.io/ubi/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kamil-kielbasa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-25T14:02:42.000Z","updated_at":"2026-04-11T19:04:11.000Z","dependencies_parsed_at":"2025-09-21T21:18:19.949Z","dependency_job_id":null,"html_url":"https://github.com/kamil-kielbasa/ubi","commit_stats":null,"previous_names":["kamil-kielbasa/ubi"],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/kamil-kielbasa/ubi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil-kielbasa%2Fubi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil-kielbasa%2Fubi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil-kielbasa%2Fubi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil-kielbasa%2Fubi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kamil-kielbasa","download_url":"https://codeload.github.com/kamil-kielbasa/ubi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil-kielbasa%2Fubi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31793225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","embedded","flash","nand","nor-flash","ubi","volume-manager","wear-leveling","zephyr","zephyr-rtos"],"created_at":"2026-01-27T20:29:14.679Z","updated_at":"2026-05-11T12:05:47.804Z","avatar_url":"https://github.com/kamil-kielbasa.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UBI on Zephyr\n\n![CI](https://github.com/kamil-kielbasa/ubi/actions/workflows/ci.yml/badge.svg)\n[![Docs](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://kamil-kielbasa.github.io/ubi/)\n[![codecov](https://codecov.io/gh/kamil-kielbasa/ubi/graph/badge.svg)](https://codecov.io/gh/kamil-kielbasa/ubi)\n![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)\n\nUBI is a lightweight **wear-leveling and logical volume management layer** for raw flash on [Zephyr RTOS](https://www.zephyrproject.org/). It sits between application-level storage logic and the physical flash device, providing logical eraseblocks, metadata redundancy, bad block handling, and crash-safe LEB-to-PEB mapping.\n\n\u003e **Release status: v1.0.0 (in preparation).** The library API and on-flash format are stabilising for v1.0.0. CI, coverage, and metrics badges above reflect the current `main` branch.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"doc/img/stack.svg\" alt=\"UBI on Zephyr stack: Application → UBI Public API → Zephyr flash_area / PSA Crypto → Physical Flash\" width=\"600\"\u003e\n\u003c/p\u003e\n\n## Key Properties\n\n| Property | Value |\n|----------|-------|\n| Logical volumes | Multiple named volumes on a single flash partition |\n| Wear-leveling | Greedy min-EC strategy across all PEBs |\n| Bad block handling | Automatic detection and isolation |\n| Metadata redundancy | Dual-bank reserved PEBs (configurable 2–4 copies) |\n| Crash recovery | Sequence-number-based conflict resolution on init |\n| Dynamic volume resize | Grow and shrink volumes at runtime |\n| Authenticated encryption | Optional AES-128-CCM backend encrypting all on-flash structures ([Secure Overview](https://kamil-kielbasa.github.io/ubi/architecture/secure_overview.html)) |\n| Filesystem | **No** — raw block-level I/O, not file-level |\n| Flash footprint | ~9.5 KB plain / ~29 KB secure (library only; PSA Crypto/mbedTLS provided by platform, not counted) |\n| Static RAM (BSS) | Depends on Kconfig (see [Configuration](https://kamil-kielbasa.github.io/ubi/guide/configuration.html#memory-sizing-guide)) |\n| Runtime RAM | Proportional to PEB count + volume count (see [Configuration](https://kamil-kielbasa.github.io/ubi/guide/configuration.html)) |\n| Thread safety | Per-device mutex; not ISR-safe |\n\n## When to Use\n\n- You need **logical volumes with wear-leveling** on raw NOR/NAND flash under Zephyr.\n- You want to store firmware images, configuration blobs, or structured binary data with raw block access.\n- You are building a higher-level storage layer and need a reliable block abstraction underneath.\n\n## When NOT to Use\n\n- You need a **ready-made filesystem** — use LittleFS or FAT instead.\n- Your flash has a built-in **FTL** (eMMC, SD cards) — UBI adds no value.\n- You only need a **key-value store** — Zephyr NVS is simpler and sufficient.\n- Your device has **no flash wear concerns** (e.g., very low write frequency on high-endurance NOR).\n\n## Quick Start\n\n```c\n#include \u003cubi.h\u003e\n#include \u003czephyr/drivers/flash.h\u003e\n#include \u003czephyr/storage/flash_map.h\u003e\n\n#define UBI_PARTITION_NAME ubi_partition\n#define UBI_PARTITION_DEVICE FIXED_PARTITION_DEVICE(UBI_PARTITION_NAME)\n\nint main(void)\n{\n    const struct device *flash_dev = UBI_PARTITION_DEVICE;\n    struct flash_pages_info page_info = { 0 };\n    flash_get_page_info_by_offs(flash_dev, 0, \u0026page_info);\n\n    struct ubi_flash_desc flash = {\n        .partition_id = FIXED_PARTITION_ID(UBI_PARTITION_NAME),\n        .erase_block_size = page_info.size,\n        .write_block_size = flash_get_write_block_size(flash_dev),\n    };\n\n    struct ubi_device *ubi = NULL;\n    ubi_device_init(\u0026flash, NULL, \u0026ubi);\n\n    struct ubi_volume_config cfg = {\n        .name = \"my_vol\",\n        .type = UBI_VOLUME_TYPE_DYNAMIC,\n        .leb_count = 4,\n    };\n    int vol_id;\n    ubi_volume_create(ubi, \u0026cfg, \u0026vol_id);\n\n    const char data[] = \"Hello, UBI!\";\n    ubi_leb_write(ubi, vol_id, 0, data, sizeof(data));\n\n    char buf[64];\n    ubi_leb_read(ubi, vol_id, 0, 0, buf, sizeof(data));\n\n    ubi_device_deinit(ubi);\n    return 0;\n}\n```\n\nError handling is omitted for brevity. All API functions return `0` on success or a negative `errno` code on failure. See [`sample/`](sample/) for a complete buildable example.\n\n## Documentation\n\nFull documentation is published at **\u003chttps://kamil-kielbasa.github.io/ubi/\u003e**. Quick links to the most-used pages:\n\n- [What is UBI?](https://kamil-kielbasa.github.io/ubi/getting_started/what_is_ubi.html) — 5-minute orientation, when (and when not) to use UBI.\n- [Quick Start](https://kamil-kielbasa.github.io/ubi/getting_started/quick_start.html) — build, run the sample, write your first volume.\n- [Cookbook](https://kamil-kielbasa.github.io/ubi/guide/cookbook.html) — STM32U5 / nRF5340 setup, A/B firmware, GC loop, key rotation, freshness store.\n- [Plain Architecture](https://kamil-kielbasa.github.io/ubi/architecture/plain_architecture.html) — on-flash layout, wear-leveling, dual-bank, recovery.\n- [Secure Architecture: Overview](https://kamil-kielbasa.github.io/ubi/architecture/secure_overview.html) — what Secure UBI does, key hierarchy, threat model, application contract.\n- [Secure UBI Workflow](https://kamil-kielbasa.github.io/ubi/guide/secure_workflow.html) — prerequisites, `crypto_cfg`, callback contracts, key rotation, event handling.\n- [Secure On-Flash Format Specification](https://kamil-kielbasa.github.io/ubi/reference/onflash_format_spec.html) — normative byte-level reference.\n- [Configuration](https://kamil-kielbasa.github.io/ubi/guide/configuration.html) · [API Reference](https://kamil-kielbasa.github.io/ubi/reference/api.html) · [Glossary](https://kamil-kielbasa.github.io/ubi/reference/glossary.html) · [Test Strategy](https://kamil-kielbasa.github.io/ubi/project/test_strategy.html) · [Contributing](https://kamil-kielbasa.github.io/ubi/project/contributing.html)\n\n## Project Quality\n\n| Metric | Value |\n|--------|-------|\n| Test suites | 33 suites, 325 tests (251 plain + 74 secure) |\n| Line coverage | 85.0% plain / 77.3% secure (target ≥ 80%) |\n| Branch coverage | 51.8% plain / 40.7% secure (target ≥ 70%) |\n| CI | GitHub Actions — build, test, coverage, cross-compile STM32U5 + nRF5340 |\n| Primary test platform | Zephyr `native_sim` with flash simulator |\n| Hardware validation | `b_u585i_iot02a` (STM32U5), `nrf5340dk` (nRF5340) cross-compilation |\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n\n## Acknowledgments\n\nThis project would not exist without the work of the Linux kernel\ncommunity, and in particular the original authors and maintainers of\nthe **Linux UBI subsystem**. The core idea — a thin layer over raw\nflash that provides logical volumes, wear-leveling, and crash-safe\nLEB-to-PEB mapping — is, to the author, simply brilliant. All credit\nfor that concept belongs to them; this project only adapts it to a\ndifferent environment.\n\nUBI on Zephyr is directly inspired by Linux UBI. For Zephyr's\nresource-constrained targets the implementation had to be substantially\nsimplified — fewer moving parts, a smaller in-RAM footprint, no\nfilesystem layer on top — but the underlying model (PEBs, LEBs,\nEC/VID headers, dual-bank reserved metadata, sequence-number\nrecovery) is the same one Linux UBI established. From the author's\nperspective this was a missing piece on Zephyr: a building block that\n**scales to large flash devices** by giving the application a\nvirtualised view of flash with wear-leveling underneath.\n\n**Secure UBI** is then the author's own addition on top of that\nfoundation. The motivation is straightforward: Zephyr lacks a\nstorage / volume-management layer that delivers all of the above\nbenefits *and* full on-disk encryption end-to-end. Secure UBI fills\nthat gap by authenticating and encrypting every on-flash structure —\ndevice header, volume headers, EC headers, VID headers, and LEB\npayloads — through the PSA Crypto API, so the same wear-leveling\nand dual-bank guarantees apply to ciphertext rather than plaintext.\n\n## Contact\n\nKamil Kielbasa — kamkie1996@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamil-kielbasa%2Fubi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkamil-kielbasa%2Fubi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamil-kielbasa%2Fubi/lists"}