For a lot of the stuff I'm interested in doing, having an Arduino that is totally stand-alone would be a big benefit. The Yun should fit the bill, as the Linux side is a reasonably powerful MIPS processor. Unfortuantly there's no C compiler... The only way to compile C for it was to cross-compile. That would be OK-ish, but setting up a build environment is a real pain.
I've said a few times that it shouldn't be so hard to build a compiler, but last week Frederico called me on it, if I wanted it, I should pitch in and do it.
The link explains how to build it, and what problems I hit. Basically it was all reasonably straight forwards, but with a lot of minor hassles and glitches. In addition to instructions for "rolling your own", there's also a link where you can download the pre-built files.
I've only done basic testing on it, and I'm sure there will be glitches: however it compiles C programs natively on the Yun. Cross compiling is still the best option if you're doing heavy builds, but for light use this is far easier.
Thank you Ian
Please consider joining effort/support with noblepepper that volunteered in porting your instructions into an openwrt makefile, so that gcc becomes an installable package
I've now used the native gcc to build a couple of packages... Seems to be working pretty nice.
I hooked up an old 4Gb SSD I had and used that (remounted async, ext4) to give me some working space, and it really helps with i/o performance over the SD card - but maybe thats cause I've got a cheap SD card.
Building some packages I came across a couple of niggles which I had to work round:
The Yun tar is part of busy box, and recent tar archives (gnu tar?) break it. So we'll need to install a new tar, but that breaks because busy box grep isn't powerful enough... you could install gnu grep 2.9 but that uses a "new" tar archive....
Gnu grep 2.0 downloads/untars and compiles fine.
Gnu Tar 1.27.1 needs new grep. Even when you remove "/bin/grep" it still gets picked up as its part of busy box, to configure you need to use:
./configure GREP=/usr/local/bin/grep
Most configure scripts will probably need this.
Now you've got a real tar, you can go back and upgrade grep to the latest version if you want to, but there doesn't seem a lot of point...
Bzip2 is needed for a few builds. It compiles and runs in the standard environment without incident.
I started from Ian's blog and almost have it where I can make an ipkg. When I get the pull request ready for the main repostory, I'll put a link here, it will be for the VERY BRAVE.
Native GCC for up stream OS-Openwrt exists for ages, might be 4~5 years. PACKAGE_gcc and PACKAGE_build-essential is only for x86 platform since hardware limit.
but situation greatly changed since newer router has much powerful hardware.
Just tried and the package become selectable. I still wonder how I could have missed it
Anyway I also had to remove the @NO_STRIP filter. Anyone has a clue about why I should avoid stripping gcc binaries?
I tried the makefile as is and the download of the source tarball failed, it was looking for a linaro release which doesn't seem to be available at the URL's provided. I changed the release to a simple 4.6.2 and it doesn't like my autoconf version.
OK, not me fat fingering something. I have a working GCC, but have struggled trying to get openwrt to make a package. With this as an example I think I can get a ipkg.
I guess not, at least not for me each TARGET and Openwrt release I have to manually modify Makefile.
Use "STRIP:" at buildroot./Makefile.
noblepepper:
Did this compile for you?
I tried the makefile as is and the download of the source tarball failed, it was looking for a linaro release which doesn't seem to be available at the URL's provided. I changed the release to a simple 4.6.2 and it doesn't like my autoconf version.
!!!!????
I flip coin, "4.6.3" is luck number for current Yun OS.
I am a big fan for "Native GCC for Yun", but not for GCC running at Yun. It is for GCC running powerful MIPS CPU or High speed MIPS emulator. compile Yun OS took me 4 hours then compile GCC took 30 mins, opkg install GCC into it took few mins, but compile some C code could take 10+ hours. No way it is too much. I rather account finger than use computer. ( I only did it at old Yun's OS)
sonnyyu:
compile some C code could take 10+ hours. No way it is too much. I rather account finger than use computer. ( I only did it at old Yun's OS)
I'm not sure what you're trying to compile on the Yun, but I've compiled a bunch of stuff and performance was OK. The only things that are going to take anywhere near 10 hours are something like gcc, or the OS distro. For compiling huge packages it obviously makes sense to cross compile but for example when I needed a "real" grep it took only a few minutes to compile and install gnugrep. Then again I'm old enough to remember when a 400Hz Mips WAS a high end machine.
For a typical user, cross compiling is a near non-starter: just setting a Debian VM is enough work! Building the openWRT distro on that is a pain (and it regularly fails!). As you noted you spent hours getting to the stage of STARTING to compile your project. Also a lot of packages aren't set up to cross compile nicely.
I'm not sure what you're trying to compile on the Yun, but I've compiled a bunch of stuff and performance was OK. The only things that are going to take anywhere near 10 hours are something like gcc, or the OS distro.
Opencv, It took almost same time as gcc at cross compile, at cross compile Opencv could be compiled on some hardware target but not all. Native GCC in high speed MIPS CPU could help. The list could go on and on.
For compiling huge packages it obviously makes sense to cross compile but for example when I needed a "real" grep it took only a few minutes to compile and install gnugrep.
agree
Then again I'm old enough to remember when a 400MHz Mips WAS a high end machine.
My first computer ( in kits format and I soldered it together when I was kids)
Sinclair ZX81
CPU Z80 at 3.25 MHz
Memory 1 kB (64 kB max. 56 kB usable)
but now there are multiple cores MIPS based computer could run a couple of GHz with a lot of memory.
very environmental green, could run without big heat sink or fan.
For a typical user, cross compiling is a near non-starter: just setting a Debian VM is enough work! Building the openWRT distro on that is a pain (and it regularly fails!).
I start with openvz since it performance near type 0 hypervisor, but back to bear metal + ghost for 10% gain. Now plan to migrate to Xen for Amazon Web Services.
sonnyyu:
...
The Atheros AR9331 (Hornet) is a Wi-Fi System-On-Chip (WiSOC), typically used in AccessPoints and router platforms. It is based on MIPS @400MHz 32 bits CPU with no floating point support, has 64 MB DDR2 RAM and 16 MB Flash Memory.
...
One of sample Web Services: Amazon Web Services (cr1.8xlarge) has 32 vCPU (32 of 1.7 GHz Xeon processor 64 bits CPU) and 244 GB RAM plus 2 x 120 SSD driver.
...
VirtualBox is type 2 hypervisor will be suffer more than type 1 hypervisor.
As you noted you spent hours getting to the stage of STARTING to compile your project.
4~5 hours to compile complete OS on bear metal 8 cores/16GB RAM/120GB SSD, then 30 mins for gcc and 28 mins for opencv. both could failed and offen will be failed. hit enter key and pray.
Also a lot of packages aren't set up to cross compile nicely.
True, but after careful tune up, I manage keep it at single digit. I do get ~4000 packages from trunk.
Cross-compiling for the Yun I use the OpenWRT toolchain. It works rather well. Just set up your environment variables, configure for the mips target and your working.
Native GCC on the Yun is really only for playing around or if you an amazing amount of patience. I got it working just because I thought I could.
I was able to compile a native mips avr-gcc toolchain for the Yun. I'm testing that out with Arduino Makefile. It's working well. It's not as slow as I was expecting and is very usable. I have my whole avr-tools setup as a nfs mount to the Yun and am satisfied with it. I was going to make it a package, but having it separate from the main root filesystem is much easier and to me cleaner.
As far as qemu virtual mips there are some decent choices. You can use the malta snapshot from OpenWRT trunk (Index of /snapshots/trunk/malta/). It's specifically for running in qemu .
There's also the yocto project (https://www.yoctoproject.org/)that is rather easy to setup by reading the documentation.
arbor:
...
Native GCC on the Yun is really only for playing around or if you an amazing amount of patience. I got it working just because I thought I could.
I was able to compile a native mips avr-gcc toolchain for the Yun. I'm testing that out with Arduino Makefile. It's working well. It's not as slow as I was expecting and is very usable. I have my whole avr-tools setup as a nfs mount to the Yun and am satisfied with it. I was going to make it a package, but having it separate from the main root filesystem is much easier and to me cleaner.
...
arbor:
...
As far as qemu virtual mips there are some decent choices. You can use the malta snapshot from OpenWRT trunk (Index of /snapshots/trunk/malta/). It's specifically for running in qemu .
...
I found few catch about malta;-
Index of /snapshots/trunk/malta/ is for little-endian image, AR9331 is big-endian, I manage to compile big-endian image as well as GCC for it, but Yun's OS is attitude_adjustment and so no go here.
I have finally gotten a Makefile that produces an install-able, working gcc package. You can get the package here Dropbox - File Deleted - Simplify your life It is big, over 60mB and there are probably some issues that still need to be taken care of so please try it and let me know if it works for you.
@federico - one of the last things I found was that if you let openwrt strip the files compiling on the Yun chokes at the linking stage because it can't find symbols it needs.
root@Arduino:~# gcc -fno-use-linker-plugin -msoft-float hello.c -o hello
hello.c: In function 'main':
hello.c:5:5: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
root@Arduino:~#
run the executable:
root@Arduino:~# ./hello
hello world
root@Arduino:~#
Yes it is slow:
time gcc -fno-use-linker-plugin -msoft-float hello.c -o hello
hello.c: In function 'main':
hello.c:5:5: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
real 0m 0.53s
user 0m 0.34s
sys 0m 0.10s
I need to clean up the makefile and then I'll put in a pull request to the yun repository so it can be built by anyone who wants to.