Packaging precompiled kernel with OpenWrt userland?

Hi folks,

I'm trying to construct a decent userland for an IP camera I have. There doesn't seem to be much support for HiSilicon CPU's in OpenWrt, so my thinking is to reuse the vendor-supplied kernel, and build an OpenWrt userland on top of that. This would also be a great tool for other devices that I have that do not yet have working OpenWrt builds.

How difficult {is it|would it be} to replace the portion of the build scripts that want to compile Linux from source with a "copy kernel and modules from this directory" feature?

I realise that this is not exactly in line with the OpenWrt objectives, but I see it as a step in the right direction, at least. Any assistance would be appreciated.

use optware-ng (etc) or obtain device sources and add full support... the userland is not 'portable'...

( if the device had grunt... chroots / kexec / jails / docker etc. start to become viable / worth investigating )

out of curiosity... what would things do you need in this expanded userland?

It’s not a device with grunt, so virtualization, or chroot makes no sense. It also doesn’t have a lot of storage, and no real option for external storage (other than NFS, perhaps, and that is not likely to be part of the vendor kernel), so doubling up on things like libc, and other libraries is not a great idea.

Why do you say that userland is not portable? It’s easy enough to copy a precompiled busybox (for the appropriate arch) and have it work just fine. Granted, that’s a static binary, which is why I’d include the rest of the OpenWrt file system with all of its dependencies in place.

And what would I want from it? All the functionality that OpenWrt offers, as well as a great security track record!


I was thinking about it a bit more, and my conclusion was that one could configure a monolithic kernel (i.e. zero modules, with the intention of not using it at all). Then, the portion of the Makefile that incorporates the kernel into the final image could be modified to refer to the vendor kernel instead of the "just compiled one", and any vendor modules could be included in the custom filesystem. So I suspect that this could be achieved with a one-line change to the standard Makefile. If I could only figure out which line to change! :slight_smile:

Lets say you hypothetically bundle your vendor kernel+modules with a compatible openwrt rootfs...

Sure one or two static binaries may work... ( you didn't mention of stock is uLibc or musl etc.?)

How do you expect;

  • procd ( kmodloader / ubus / rpcd )
  • opkg

etc. to work? even if they didn't require any modules... they will still be expecting stuff provided by certain matched kernels...

Even if the vendor kernel is EXACTLY the same version as the openwrt release version. There will still be inconsistencies.

Either get the vendor source and port it properly... or use optware... Sure... by all means play around to your hearts content trying to "mesh" the two things together... It's an interesting learning exercise.

You will still be here in one two and three years time.

As far as I understand it, opkg is purely userspace package management (yes, it can also download/install kmod's, but it doesn't depend on any kernel functionality to do so).
procd is the OpenWrt systemd alternative which isn't documented to depend on particular kernel features (that I saw in a brief search). Neither is ubus or rpcd.
kmodloader should not be an issue if all required functionality is either built-in, or the modules are manually loaded.

I don't believe that the stock filesystem's libc, etc to be relevant at all, since I don't intend to use ANY of it other than the kernel and any modules. There may be an issue if the system call numbering has changed between the vendor kernel and the compilation of the libc/musl/whatever, but AFAIK, Linux tries really hard to maintain backwards/forwards compatibility, which renumbering of syscalls would destroy, so I see this as a low risk.

Thanks for your input. I think I'm going to try and dig into the Makefiles to find where the kernel is composed into the final image (git grep mkimage?) to see if I can just change that reference.

1 Like