Jump to content

Recommended Posts

Posted

Hi does any one know or have a working setup for compiling you on c code for openwrt?

For the last 6 days I have trawled through google, found loads, tried them an none of them work.
surely somebody has a working set up I can duplicate!

regards
kerravon

 

Posted (edited)

For OpenWRT you can theoretically use gcc, like you would on any other linux version.
If your goal is to compile C-code to run on a openwrt-distro. I would recommend that you start by downloading the correct SDK for your OpenWRT version (and CPU), and also check out these links below:

https://wiki.openwrt.org/doc/devel/crosscompile
https://wiki.openwrt.org/doc/howto/obtain.firmware.sdk

Edited by Zylla
Posted

ran several of the sdk installation including toolchain installatiom compile fo x86 perfect but when tryto use mip_gcc compiler  (forgot the exact name now) always get command not found. I don't want to build ipk t the moment just executables that I will scp into the mr3020, wr703n and eventually the pineapple.Sorry for delay in answering just finished another tutorial which doesn't seem to work.

Posted

To install GCC on your Pineapple Nano you need to issue:

opkg update
opkg install gcc --dest sd

If you have a Tetra, just remove "--dest sd" from that command. (gcc and its dependencies takes up some megabytes of space)

Regarding the SDK you can download the correct OpenWRT SDK (which you can use to cross-compile binaries for the latest Pineapple on your desktop) here:
https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2

I'm going to have to refer to the links i posted above about using the SDK/Toolchain, because it's to much information for me to go in depth with in just a single post.
But you should be able to get started cross-compiling after reading them thoroughly.

If you just need to compile a few bytes of code without much dependencies, just download gcc on your pineapple and test it.
Be warned. If you're trying to compile stuff that are "heavy"/big on your Pineapple with gcc, you most likely will need to compile alot of dependencies as well.
And not everyone compiles as easy on the Pineapple as on your desktop. (Different cpu architecture)

Posted
16 hours ago, kbeflo said:

@Zylla, on-topic is shellinabox compilable on the Pineapple? I was hoping to use shellinabox found on github and hope to use it on the Pineapple https://github.com/OnionIoT/OpenWRT-Packages/tree/master/shellinabox.

I can try to compile it a bit later today if you want (a bit busy at the moment).
But by just glancing over it fast i would say that it should compile just fine. :)

Posted
16 hours ago, kerravon said:

ran several of the sdk installation including toolchain installatiom compile fo x86 perfect but when tryto use mip_gcc compiler  (forgot the exact name now) always get command not found. I don't want to build ipk t the moment just executables that I will scp into the mr3020, wr703n and eventually the pineapple.Sorry for delay in answering just finished another tutorial which doesn't seem to work.

If you read though the cross-compile section you will find some info about adding the toolchain dir to your PATH variable, and also the STAGING_DIR variable.
Then you can launch the gcc compiler, or Makefile through the terminal inside the folder of the stuff you're trying to compile.
 

mips-openwrt-linux-uclibc-gcc -o output_binary csample.c
CC=mips-openwrt-linux-uclibc-gcc LD=mips-openwrt-linux-ld make
./configure --build=x86_64-unknown-linux-gnu  --host=mips-openwrt-linux-uclibc

^ Some sample commands you can use inside your project-folder after having setup your PATH variable correctly. (On your linux-desktop)
This will not create a IPK, but simply compile your code for a different cpu-architecture.

Posted

when typing mips-openwrt-linux-gcc -o hello.c -o hello in all of the ones ive tried
so far say mips-openwrt-linux-gcc  command not found.

although it is there and if I run file mips-openwrt-linux-gcc

it tells me al about the executable file.

I can compile in normal gcc without problem

NB installing comiler to nano is not something I want to do as I am looking at writing
code for a number of mips devices.

Posted (edited)
47 minutes ago, kerravon said:

when typing mips-openwrt-linux-gcc -o hello.c -o hello in all of the ones ive tried
so far say mips-openwrt-linux-gcc  command not found.

although it is there and if I run file mips-openwrt-linux-gcc

it tells me al about the executable file.

I can compile in normal gcc without problem

NB installing comiler to nano is not something I want to do as I am looking at writing
code for a number of mips devices.

Try typing "which mips-openwrt-linux-gcc" and then using the whole path it gives you? Also, should not be "-o hello.c -o hello" but "hello.c -o hello"?

/some/path/mips-openwrt-linux-gcc hello.c -o hello

where /some/path/ is what was in the results from the which command. Also, do you need to install all the libraries for the mips compiler, and can't you use gcc with switches to tell it to compile for the specific target system? I've had issue sin 64 bit links trying to make files for 32 bit systems when i didn't have rights to compile on the 32 bit box. I had to install specific libraries for the x86 version and pass the switches to tell it to make the program for 32 bit, not 64 when compiling. I imagine for a router there would be similar equivalents.

Another question. Is there a native compiler for openwrt in their repo? You'd have to look in the one specific for your device - http://downloads.openwrt.org/snapshots/trunk/

Example, I see a gcc ipk here for this specific router - http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages/ but you'd have to look in the trunk above to find the one for your specific router, and then install and compile on the router, no? 

If on the router, maybe try opkg list, see if your version lists anything for gcc.

This has me curious now, as I just realized you can install openwrt in a virtual machine, essentially setting up a wifi router with a few wireless nics attached to a VM. I knew you could do it with other router software, but just dawned on me you can do this with openwrt. I may have to try this now.

Edited by digip
Posted
47 minutes ago, digip said:

Try typing "which mips-openwrt-linux-gcc" and then using the whole path it gives you? Also, should not be "-o hello.c -o hello" but "hello.c -o hello"?

This has me curious now, as I just realized you can install openwrt in a virtual machine, essentially setting up a wifi router with a few wireless nics attached to a VM. I knew you could do it with other router software, but just dawned on me you can do this with openwrt. I may have to try this now.

Yes you can.
I have both OpenWRT and the new "LEDE" version running in VMware (using the x86_64 arch.)
I'm not emulating mips, though you can do that using QEMU.

Btw "Kerravon": I just noticed your gcc command is not correct. You're supplying the "-o" (output) argument two times.
Also, please show me your PATH variable and your STAGING_DIR variable.
Also, i need the folder path to where you extracted the OpenWRT-SDK.

Posted
52 minutes ago, digip said:

Another question. Is there a native compiler for openwrt in their repo? You'd have to look in the one specific for your device - http://downloads.openwrt.org/snapshots/trunk/

Yes.
https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/packages/gcc_4.8.3-1_ar71xx.ipk
gcc for Chaos Calmer 15.05. This one is for the ar71xx (mips)
There are lots of other archs. and openwrt-versions supported.

Posted

from all the tutorials I read, when you run make menuconfig ste your device

then run make V=s it I supposed to build all files and the tool chain for that device
an the compilers are in the staging_dir/toolchain/bin directory

is this not correct.

Yes I have an openwrtVM, but havet done much with it in a while.

Posted
make menuconfig
make V=s

This is used when you're using the SDK to build packages, and even entire firmware-images.
Not if you're just using the toolchain to compile a simple c-file.

If i'm going to help you more, i'm going to have to know exactly what you wrote when you set your two variables.
Because it looks like it's not set correctly.:wacko:
If it was, it should have recognized the command: "mips-openwrt-linux-uclibc-gcc"

Posted

For example. here are my two variables:
 

export PATH=$PATH:/home/zylla/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/

export STAGING_DIR=/home/zylla/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir

 

Posted

 

Debian and install the required tools:

sudo apt-get update

sudo apt-get install build-essential

sudo apt-get install subversion

sudo apt-get install git-core

sudo apt-get install patch

sudo apt-get install bzip2

sudo apt-get install flex

sudo apt-get install bison

sudo apt-get install autoconf

sudo apt-get install gettext

sudo apt-get install unzip

sudo apt-get install libncurses5-dev

sudo apt-get install ncurses-term

sudo apt-get install zlib1g-dev

sudo apt-get install gawk

sudo apt-get install libz-dev

sudo apt-get install libssl-dev

 

download the OpenWrt source from git repo:

cd /home/developer/work/

git clone git://git.openwrt.org/openwrt.git openwrtsource

cd openwrtsource

Update OpenWrt Packages:

./scripts/feeds update -a

./scripts/feeds install -a

Prepare to build OpenWrt:

make defconfig

make prereq

make menuconfig

export the required STAGING_DIR var

export STAGING_DIR=/home/developer/work/openwrtsource/staging_dir/

# call GCC to cross-compile the .c file

/home/developer/work/openwrtsource/staging_dir/toolchain-mips_34kc_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc hello.c -o hello

/home/developer/work/openwrtsource/staging_dir/toolchain-mips_34kc_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc hello.c -o hello  comes back command not found

Posted

You are trying to build OpenWRT.
You are NOT downloading a specific SDK to compile binaries for that exact version of OpenWRT, which i thought you wanted to do.

If you wanted to cross-compile stuff for you WiFi Pineapple TETRA/NANO, you would download and extract this file:
https://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2

Posted

After extracting that file, you will find the toolchain dir under staging_dir.
You need to export STAGING_DIR and PATH as i showed you above.

Posted

ok will give that ago will start with blank vm. what distro are you using?

 

Posted
Just now, kerravon said:

ok will give that ago will start with blank vm. what distro are you using?

 

I'm running Kali Rolling 2016.2 (x64) - with kernel 4.9.0.

Posted
Just now, kbeflo said:

Got it. This was compiled from the github link I gave right? Thanks again Zylla. 

Yes. I used an exact copy of the Makefile and "patch-files" on my SDK.

Posted

still getting command not found

user@ubuntuvm:~ OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin$ mips-openwrt-linux-uclibc-gcc –o test test.c

mips-openwrt-linux-uclibc-gcc: command not found

  path variables

export PATH=$PATH:/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/

 

export STAGING_DIR=/home/user/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...