Top Related Projects
Linux kernel source tree
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.
RT-Thread is an open source IoT Real-Time Operating System (RTOS).
Arm Mbed OS is a platform operating system designed for the internet of things
Quick Overview
LK (Little Kernel) is a lightweight, high-performance kernel designed for embedded systems and small devices. It provides a minimal operating system environment with a focus on efficiency and modularity, making it suitable for a wide range of applications from IoT devices to more complex embedded systems.
Pros
- Lightweight and efficient, ideal for resource-constrained devices
- Modular design allows for easy customization and extension
- Supports multiple architectures, including ARM, x86, and RISC-V
- Active development and community support
Cons
- Limited documentation compared to more established operating systems
- Steeper learning curve for developers new to embedded systems
- Fewer high-level features compared to full-fledged operating systems
- May require more low-level programming knowledge
Code Examples
- Initializing and starting a thread:
#include <kernel/thread.h>
static int my_thread_func(void *arg) {
// Thread logic here
return 0;
}
void start_my_thread(void) {
thread_t *t;
t = thread_create("my_thread", my_thread_func, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
thread_resume(t);
}
- Using a mutex for synchronization:
#include <kernel/mutex.h>
mutex_t my_mutex;
void init_mutex(void) {
mutex_init(&my_mutex);
}
void use_mutex(void) {
mutex_acquire(&my_mutex);
// Critical section
mutex_release(&my_mutex);
}
- Setting up a timer:
#include <kernel/timer.h>
static void timer_callback(void *arg) {
// Timer callback logic
}
void setup_timer(void) {
timer_t my_timer;
timer_initialize(&my_timer);
timer_set_oneshot(&my_timer, 1000, timer_callback, NULL);
}
Getting Started
To get started with LK:
-
Clone the repository:
git clone https://github.com/littlekernel/lk.git
-
Set up the build environment (varies by platform)
-
Configure the project for your target:
make PROJECT=<project_name>
-
Build the kernel:
make
-
Flash the resulting image to your target device (method varies by device)
For more detailed instructions, refer to the project's documentation and README files.
Competitor Comparisons
Linux kernel source tree
Pros of Linux
- Extensive hardware support and driver ecosystem
- Robust and battle-tested in production environments
- Large community and extensive documentation
Cons of Linux
- Complex codebase with a steep learning curve
- Higher resource requirements for embedded systems
- Longer boot times compared to lightweight kernels
Code Comparison
LK (Little Kernel):
void lk_main(void)
{
// Initialize the platform
platform_early_init();
// Start the kernel
lk_init();
}
Linux:
asmlinkage __visible void __init start_kernel(void)
{
char *command_line;
char *after_dashes;
set_task_stack_end_magic(&init_task);
smp_setup_processor_id();
debug_objects_early_init();
}
LK focuses on simplicity and minimal initialization, while Linux has a more complex startup process with additional setup and debugging features. LK's codebase is more accessible for embedded systems and quick prototyping, whereas Linux provides a comprehensive solution for a wide range of hardware and use cases.
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
Pros of Zephyr
- More extensive hardware support and device drivers
- Larger community and ecosystem with regular updates
- RTOS features like real-time scheduling and power management
Cons of Zephyr
- Higher complexity and steeper learning curve
- Larger codebase and memory footprint
- More configuration options may lead to increased development time
Code Comparison
LK (main.c):
#include <lk/init.h>
#include <lk/debug.h>
static void hello_init(uint level)
{
dprintf(INFO, "Hello World\n");
}
LK_INIT_HOOK(hello, hello_init, LK_INIT_LEVEL_TARGET);
Zephyr (main.c):
#include <zephyr/kernel.h>
void main(void)
{
printk("Hello World! %s\n", CONFIG_BOARD);
}
Both examples show a simple "Hello World" application, but Zephyr's approach is more straightforward for beginners. LK uses an initialization hook system, while Zephyr uses a standard main() function. Zephyr also includes built-in board configuration support.
'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.
Pros of FreeRTOS
- Widely adopted and supported by a large community
- Extensive documentation and learning resources available
- Supports a broader range of microcontrollers and architectures
Cons of FreeRTOS
- More complex and feature-rich, potentially leading to a steeper learning curve
- Larger memory footprint compared to LK
- May have more overhead for simple applications
Code Comparison
FreeRTOS task creation:
void vTaskFunction(void *pvParameters) {
for (;;) {
// Task code here
}
}
xTaskCreate(vTaskFunction, "TaskName", STACK_SIZE, NULL, TASK_PRIORITY, NULL);
LK thread creation:
static int my_thread_func(void *arg) {
for (;;) {
// Thread code here
}
return 0;
}
thread_create("my_thread", &my_thread_func, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
Both systems use similar approaches for creating tasks/threads, but FreeRTOS provides more configuration options in its creation function. LK's syntax is slightly more concise, which aligns with its minimalist design philosophy.
RT-Thread is an open source IoT Real-Time Operating System (RTOS).
Pros of RT-Thread
- More comprehensive ecosystem with package manager and IoT components
- Stronger community support and active development
- Better documentation and learning resources
Cons of RT-Thread
- Larger footprint and potentially higher resource usage
- Steeper learning curve due to more complex architecture
- Less focus on bare-metal performance compared to LK
Code Comparison
RT-Thread example:
#include <rtthread.h>
static void thread_entry(void *parameter)
{
while (1) {
rt_kprintf("Hello, RT-Thread!\n");
rt_thread_mdelay(1000);
}
}
int main(void)
{
rt_thread_t tid = rt_thread_create("test", thread_entry, RT_NULL, 1024, 25, 10);
rt_thread_startup(tid);
return 0;
}
LK example:
#include <lk/init.h>
#include <lk/debug.h>
#include <kernel/thread.h>
static int hello_thread(void *arg)
{
for (;;) {
printf("Hello, LK!\n");
thread_sleep(1000);
}
return 0;
}
static void hello_init(uint level)
{
thread_detach_and_resume(thread_create("hello", &hello_thread, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE));
}
LK_INIT_HOOK(hello, &hello_init, LK_INIT_LEVEL_THREADING);
Both examples demonstrate thread creation and basic functionality, but RT-Thread uses a more abstracted API while LK's approach is closer to bare-metal programming.
Arm Mbed OS is a platform operating system designed for the internet of things
Pros of mbed-os
- More comprehensive ecosystem with extensive hardware support
- Robust networking stack and IoT-focused features
- Active community and regular updates
Cons of mbed-os
- Larger footprint and potentially higher resource usage
- Steeper learning curve due to more complex architecture
- Less flexibility for low-level customization
Code Comparison
mbed-os example (main.cpp):
#include "mbed.h"
DigitalOut led(LED1);
int main() {
while (true) {
led = !led;
ThisThread::sleep_for(500ms);
}
}
lk example (main.c):
#include <lk/init.h>
#include <lk/debug.h>
static void lk_main(const struct lk_init_struct *unused) {
printf("Hello World\n");
}
LK_INIT_HOOK(app, lk_main, LK_INIT_LEVEL_APPLICATION);
The mbed-os example demonstrates its abstraction layer for hardware control, while the lk example shows a more bare-metal approach with direct initialization hooks.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The Little Kernel Embedded Operating System
The LK kernel is an SMP-aware kernel designed for small systems ported to a variety of platforms and cpu architectures.
See https://github.com/littlekernel/lk for the latest version.
High Level Features
- Fully-reentrant multi-threaded preemptive kernel
- Portable to many 32 and 64 bit architectures
- Support for wide variety of embedded and larger platforms
- Powerful modular build system
- Large number of utility components selectable at build time
Supported architectures
- ARM32
- Cortex-M class cores (armv6m - armv8m)
- ARMv7+ Cortex-A class cores
- ARM64
- ARMv8 and ARMv9 cores
- RISC-V 32 and 64bit bit in machine and supervisor mode
- x86-32 and x86-64
- Motorola 68000
- Microblaze
- MIPS
- OpenRISC 1000
- VAX (experimental)
TODO
To build and test for ARM64 on linux
- install or build qemu. v2.4 and above is recommended.
- install gcc for arm64 (see note 1)
- run scripts/do-qemuarm -6 (from the lk directory)
- you should see 'welcome to lk/MP'
This will get you a interactive prompt into LK which is running in qemu arm64 machine 'virt' emulation. type 'help' for commands.
Note: for ubuntu x86-64 sudo apt-get install gcc-aarch64-linux-gnu or fetch a prebuilt toolchain from https://newos.org/toolchains/aarch64-elf-14.1.0-Linux-x86_64.tar.xz
Top Related Projects
Linux kernel source tree
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.
RT-Thread is an open source IoT Real-Time Operating System (RTOS).
Arm Mbed OS is a platform operating system designed for the internet of things
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot