Qemu virtualization?

is there any guide for emulating openwrt in qemu that works? the one on wiki doesnt work and is very messy.

also can I use any other arm for emulation besides armvirt?
for example can I emulate the cortex-a9 or even directly my router (wrt1200ac linksys?)

https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Virtual_ARM_Linux_environment this is from mozilla and it uses cortex-a9 in qemu cmd parameters.

also if I am able to emulate (anyone of the arm-s) can I compile programs in it if I install gcc and so on? and use that instead of cross compiling? (cross-compiling with sdk is realy confusing for a beginner like me, so much so I rather learn qemu emulation and compile on a virtual machine.)

btw can I directly edit wiki without consulting with anyone? so that I can update the old and buggy info?

You can easily run OpenWrt x86 or x86_64 under qemu-kvm, for other targets the situation is more difficult (yes, malta (mips) or armvirt (ARM) exist). None of these emulate a specific device, but are (more or less) their own device (partially with emulation/ virtio specifics). You can not use emulation to test an image for a particular device, only for testing generic features (that work on x86_64 or armvirt/ malta as well).

1 Like

how about compiling on qemu instead of cross-compile?
is that too much effort and does it even work

OpenWrt will always cross-compile, you can't change that without massive changes to the buildsystem. Yes, you can build OpenWrt on 'any' architecture (sans bugs, you're likely to encounter on more exotic combinations) - including full system emulation for a different one, but that won't really change anything, aside from being considerably slower than doing it natively.

1 Like

my main issue is with compiling a program that has a readme for cross copmpling but I can make sense of it.

i have asked about it here

but I get zero answers.

I tried to use the package way of sdk but there is no simple but extensive guide for that.
wiki is written by pro developers for pro developers and a novice like me cant easily use it.

The simple answer would be, you can't do that then - unless you learn how to either package it up or how to use the SDK manually (neither is simple or done within five minutes).

is there any non-five minutes guides?

in some cases, you can use something like an alpine/stretch-ondevice-chroot to compile binaries natively... ( off device is also possible but chroot setup has more complexity )

it's slow... but for some things ( mostly arm ) ... it's a quick considerable option...

I had a similar problem at the start and the short answer is, creating a openwrt sdk compatible makefile is the quickest and safest way to get a compatible cross binary that actually runs on your device and allows you to create a PR so it can be added to official packages.

If you are lucky the project uses a normal makefile/cmake itself and does not need any special handling.
The openwrt sdk will take care of all the cross-compile stuff automatically and you just need to copy&paste a basic makefile template. Ofc some projects need special fixes and defines/exports.

PS: As example someone asked me to create a package for rrredir and this took about 15mins, since the project was compatible out of the box. https://github.com/Andy2244/openwrt-extra/blob/master/rrredir/Makefile

I am not familiar with this.
is this on my laptop (host?)
is this for debian and/or alpine?
and can I use this to create specific programs like the one I mentioned?
how does dependencied work for that.

if it is too complicated, I dont think I can do it.

I am not a developer.
I am trying to compile the program for openwrt but I am just use to copy paste from guides.

for example in that makefile you have :include $(INCLUDE_DIR)/package.mk which I dont know refers to what. where is the include_dir? and so on.
at best I have to find a simple makefile from openwrt and change that.

but the issue is I dont know what these are also

define Package/rrredir/install

$(INSTALL_DIR) $(1)/usr/bin

$(INSTALL_BIN) $(PKG_BUILD_DIR)/rrredir $(1)/usr/bin/


are they standard?

the program I am trying to compile is not really complicated to compile. but it also has a library that need to compile before it.

can you do that or help me do it?
it is this which I think it very good to have on openwrt (specially for people like me that have censorship on their internet)
https://github.com/Intika-Linux-Proxy/SNI-SSL-Proxy.git cd SNI-SSL-Proxy

btw do I need the build enviroment from git master (or 19.07 or 18) or just sdk is enough for me?
what advantage the compiling from source provides that sdk doesn't for the end developer ,not someone that is debuging the openwrt itself?

I think the difference between imagebuilder (gets pre-built binary packages and combines them for a image) and sdk ( a pre-built build enviroment that can be used to create binaries packages, i think) and the from scratch build enviroment that can be hacked to change the defaults and debug the openwrt project ,this is mostly for openwrt developers that are creating the openwrt itself and not for someone like me that is trying to just compile one single package that has standard c make file and so on.
did I get this correctly? so I dont realy need this anymore
and just need to have pre-build sdk from downloads section?

@reza see Help with custom package compilation

The basic template for a package makefile is the same for all packages. Things like $(INCLUDE_DIR) are set by the build system. The include statement reads in “boilerplate” definitions. They are generally in openwrt/include/ and below.

The install steps set the general place on the root file system where things will be installed, then the specific files to be installed. Package dependencies are use to “require” libraries and the like to be built and installed.

The SDK is sort of like 3/4 of the full build system, prebuilt. It is “frozen in time”. I only use the full build system as it is more flexible and equally simple or complex to use, depending on your point of view.

#     armhf(native ipq806x) w usboverlay !500MB!
opkg update
opkg install debootstrap coreutils-chroot
mkdir /stretch
debootstrap --no-check-gpg --arch=armhf --variant=minbase stretch /stretch http://ftp.us.debian.org/debian
cp /tmp/resolv.conf.auto /stretch/etc/resolv.conf
chroot /stretch apt install -y --allow-unauthenticated curl build-essential git dh-autoreconf
chroot /stretch apt install -y --allow-unauthenticated --no-install-recommends ifupdown iproute2 isc-dhcp-client netbase

cat << EOF > /stretch/snimake.sh
git clone https://github.com/Intika-Linux-Proxy/SNI-SSL-Proxy.git
cd SNI-SSL-Proxy
curl -s -L https://github.com/sustrik/libmill/archive/master.tar.gz | tar -zxf -
mv libmill-master libmill
cd libmill
./configure --enable-shared=false
make libmill.la
cd ../
autoreconf -if
export CFLAGS=-march=native
export CPPFLAGS=-I/SNI-SSL-Proxy/libmill
export LDFLAGS=-L/SNI-SSL-Proxy/libmill/.libs
./configure --host=arm-unknown-linux-gnueabihf \
    --prefix=/usr --sysconfdir=/etc

chmod +x /stretch/snimake.sh
chroot /stretch /snimake.sh
chmod +x /stretch/SNI-SSL-Proxy/src/sniproxy 
chroot /stretch /SNI-SSL-Proxy/src/sniproxy --help

I remember from before that installing compilers and so on needed more space that I had.
do I have to use ext-root or this works with small spaces ? (not really small 1200ac linksys but I remember gcc and libs needed way more)

I will try it today and see what happens.

UPDATE: I saw at the top in commented section this :
# armhf(native ipq806x) w usboverlay !500MB!

so I need the usboverlay?
I am familiar with ext-root but because it messes with firmware update and my router has more space I didn't use that on my new router.
so now I have to use that for this?
how about the way that someone described for installing packages in ram (or other specified space) temporarily?

You need extroot for this, as noted i have also created the package for openwrt sdk. See your other thread.

which part exactly needs the ext-root ?
I have a usb attached but as a storage.
can I change /stretch to /mnt/usb/stretch and not need an actual ext-root?

P.S. thank you for the package. I will try to test it too. but I also want to test the procedure you explained here.

btw when you compiled libmill did you get an error? because it has an incampatibality with newer gcc compilers.

or did you not encounter that.

also is strech a debian versioning name? ( if i remember correctly)
using a newer version of debian would work too?
and this creates a chroot complete with all the libraries and so I can use it almost like a complete linux environment for some tasks (like this compiling that I asked here?)
I have used chroot only for fixing errors by booting from cd and chrooting so I am not good at concepts behind it.

and again.. thank you for great answer you provided here.

thanks you. I am testing it right now.

I am sorry that was for wulfy23
but thanks again both of you.

I get this
chroot: failed to run command ‘/snimake.sh’: Exec format error

ls -al snimake.sh
-rwxr-xr-x 1 root root 490 Aug 15 00:14 snimake.sh

I just chrooted directly and used the commands inside chroot.

BTW how can I change it to musl based so I can copy it out of chroot and use it ?
right now it uses /lib/ld-linux-armhf.so.3 inside chroot but I need it to work with /lib/ld-musl-armhf.so

also I am not familiar with chroot that much. if I use it to run an app does it use more ram and so on? can I use another user other than root in chroot, and so on?