Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new blog post about developing OpenWRT in QEMU with Eclipse Che #50

Merged
merged 15 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 230 additions & 0 deletions _posts/2024-05-22-developing-openwrt-in-qemu.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
---
title: Developing OpenWRT in QEMU with Eclipse Che
layout: post
author: Oleksii Orel
description: >-
Developing OpenWRT helloworld package in QEMU machine emulator and virtualizer with Eclipse Che.
categories: []
keywords: ['openwrt', 'quemu', 'gdb', 'developing ', 'workspace']
slug: /@olexii.orel/openwrt-helloworld-package
---

https://openwrt.org/[OpenWrt] is a highly extensible GNU/Linux distribution for embedded devices (typically wireless routers). OpenWrt is built from the ground up to be a full-featured, easily modifiable operating system for embedded devices. You can have all the features you need with no bloat, powered by a modern Linux kernel.

We can create and develop https://openwrt.org/docs/guide-developer/creating-a-cmake-package-in-openwrt[OpenWRT CMake packages] with Eclipse Che.

In this blog post, we will review developing OpenWRT in https://www.qemu.org/[QEMU] with Eclipse Che in 4 parts:

<<part1>>

<<part2>>

<<part3>>

<<part4>>


NOTE: In this blog post, we will use the next devfile:
[source,yaml]
olexii4 marked this conversation as resolved.
Show resolved Hide resolved
----
schemaVersion: 2.2.2
metadata:
generateName: openwrt-helloworld
attributes:
controller.devfile.io/storage-type: ephemeral
projects:
- name: openwrt-helloworld
git:
remotes:
origin: https://github.com/che-incubator/openwrt-helloworld-package.git
- name: openwrt
zip:
location: https://github.com/openwrt/openwrt/archive/refs/tags/v21.02.3.zip
components:
- name: runtime
container:
image: quay.io/che-incubator/openwrt-builder:latest
memoryLimit: 6656Mi
memoryRequest: 512Mi
cpuLimit: 10000m
cpuRequest: 1000m
mountSources: true
endpoints:
- exposure: public
name: file-server
protocol: https
targetPort: 8080
path: /bin/targets
- name: qemu
container:
image: quay.io/che-incubator/openwrt-runner:latest
memoryLimit: 1536Mi
memoryRequest: 256Mi
cpuLimit: 1500m
cpuRequest: 500m
mountSources: true
endpoints:
- exposure: public
name: luci
protocol: https
targetPort: 30080
- exposure: internal
name: ssh
protocol: tcp
targetPort: 30022
commands:
- id: installpackagedefinitions
exec:
label: Install all package definitions
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt
commandLine: scripts/feeds update -a -f && scripts/feeds install -a -f
group:
kind: build
- id: linkhelloworldpackage
exec:
label: Link helloworld package
component: runtime
workingDir: ${PROJECTS_ROOT}
commandLine: ln -sr openwrt-helloworld/package/helloworld openwrt/package/
group:
kind: build
- id: unlinkhelloworldpackage
exec:
label: Unlink helloworld package
component: runtime
workingDir: ${PROJECTS_ROOT}
commandLine: unlink /projects/openwrt/package/helloworld
group:
kind: build
- id: copyconfig
exec:
label: Copy diff-config to OpenWRT
component: runtime
workingDir: ${PROJECTS_ROOT}
commandLine: cp -f openwrt-helloworld/configs/.x86-generic.config openwrt/.config && cd openwrt && make defconfig
group:
kind: build
- id: savedifconfig
exec:
label: Save diff-config to openwrt-helloworld
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt
commandLine: scripts/diffconfig.sh > /projects/openwrt-helloworld/configs/.x86-generic.config
group:
kind: build
- id: buildhelloworldpackage
exec:
label: Build helloworld package
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt
commandLine: make package/helloworld/compile V=s CONFIG_DEBUG=y
group:
kind: build
- id: prebuiltresources
exec:
label: Add prebuilt resources
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt-helloworld
commandLine: scripts/add-prebuilt-resources.sh
group:
kind: build
- id: buildallpackages
exec:
label: Build all packages and the kernel
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt-helloworld
commandLine: scripts/build.sh
group:
kind: build
- id: qemustart
exec:
label: Running OpenWRT in a QEMU VM
component: qemu
workingDir: ${PROJECTS_ROOT}
commandLine: /usr/local/bin/prepare-and-run-vm.sh
- id: gdbsshstart
exec:
label: Start remote GDB Server
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt-helloworld
commandLine: scripts/start-gdb-server.sh
- id: gdbsshaccess
exec:
label: Remote access to OpenWRT via SSH
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt-helloworld
commandLine: scripts/start-ssh.sh
group:
kind: build
- id: serverstart
exec:
label: Start Http-Server
component: runtime
workingDir: ${PROJECTS_ROOT}/openwrt
commandLine: npx http-server -a 0.0.0.0 -p 8080 -o bin/targets
group:
kind: build
----

## PART 1: Quick start with prebuild recourses [[part1]]

Prebuilt resources could be applied for a quick start with Eclipse Che. We could do it by running the next tasks from the devfile:

1. `Add prebuilt resources`

NOTE: After adding prebuilt resources, we should see the `openwrt-*.img.gz` file in the `output` directory. Prebuilt resources were added to the runtime image during the last successful GitHub image build action.

image::/assets/img/developing-openwrt/add-prebuilt-resources.png[Add prebuilt resources]
{nbsp} +

## PART 2: (optinal)Build all packages and the kernel [[part2]]
olexii4 marked this conversation as resolved.
Show resolved Hide resolved

After creating a new workspace from https://github.com/che-incubator/openwrt-helloworld-package.git[openwrt-helloworld-package], we need to copy https://github.com/che-incubator/openwrt-helloworld-package/blob/main/configs/.x86-generic.config[`.config`] file, install all package definitions and build all packages and the kernel. We can do it by running the following tasks from the devfile:

1. `Copy diff-config to OpenWRT`
2. `Install all package definitions`
3. `Build all packages and the kernel`

NOTE: The build process may take a while. After the build is complete, we can see the `openwrt-*.img.gz` file in the `output` directory.
olexii4 marked this conversation as resolved.
Show resolved Hide resolved

image::/assets/img/developing-openwrt/build-all-packages-and-the-kernel.png[Build all packages and the kernel, 100%]
{nbsp} +

## PART 3: Run OpenWRT in QEMU [[part3]]

After adding prebuilt resources or building all packages and the kernel, OpenWRT could be run in the QEMU VM by running the following tasks from the devfile:

1. `Running OpenWRT in a QEMU VM`

After running the task, we see the OpenWRT booting in the QEMU machine emulator and virtualizer.

image::/assets/img/developing-openwrt/running-openwrt-in-qemu-vm.png[Running OpenWRT in a QEMU VM]
{nbsp} +

We can access the OpenWRT console by running the task `Remote access to OpenWRT via SSH` and start the helloworld package by running:

[source, bash]
----
helloworld
----

image::/assets/img/developing-openwrt/run-helloworld.png[Run helloworld package]
{nbsp} +

## PART 4: Debugging helloworld package [[part4]]

After starting OpenWRT in a QEMU VM, we need to run a remote gdbserver for debugging. We can do it by running the task `Start remote GDB Server` from the devfile.

image::/assets/img/developing-openwrt/start-remote-gdbserver.png[Start remote gdbserver]
{nbsp} +

Then, we can debug the helloworld package with IDE:

image::/assets/img/developing-openwrt/remote-debugging.png[Start remote gdbserver]
{nbsp} +

NOTE: The task `Start remote GDB Server` should be run before each new debug session.


Thank you for reading. I hope you found this article helpful.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading