Go Down

Topic: Example of Native GCC for Yun (Read 11709 times) previous topic - next topic

sonnyyu

Say Hello to MIPS Assembly Language at Yun

Code: [Select]
nano hello.s

Code: [Select]
# File: hello.s -- Say Hello to MIPS Assembly Language Programmer
# Author: falcon <wuzhangjin@gmail.com>, 2009/01/17
# Ref:
#    [*] http://www.tldp.org/HOWTO/Assembly-HOWTO/mips.html
#    [*] MIPS Assembly Language Programmer's Guide
#    [*] See MIPS Run Linux(second version)
# Compile:
#       $ gcc -o hello hello.s
#       or
#       $ as -o hello.o hello.s
#       $ ld -e main -o hello hello.o

    .text
    .globl main
main:

    .set noreorder
    .cpload $gp       # setup the pointer to global data
    .set reorder
                      # print sth. via sys_write
    li $a0, 1         # print to standard ouput
    la $a1, stradr    # set the string address
    lw $a2, strlen    # set the string length
    li $v0, 4004      # index of sys_write:
                      # __NR_write in /usr/include/asm/unistd.h
    syscall           # causes a system call trap.

                      # exit via sys_exit
    move $a0, $0      # exit status as 0
    li $v0, 4001      # index of sys_exit
                      # __NR_exit in /usr/include/asm/unistd.h
    syscall

    .rdata
stradr: .asciiz "hello, world!\n"
strlen: .word . - stradr  # current address - the string address
# end



Code: [Select]
root@Arduino:/mnt/sda1# gcc -o hello hello.s
root@Arduino:/mnt/sda1# ./hello
hello, world!

sonnyyu

Help compile C (sshpass) application:

http://forum.arduino.cc/index.php?topic=253943.msg1799995#msg1799995

Code: [Select]
opkg update
opkg install tar


wget http://pkgs.fedoraproject.org/repo/pkgs/sshpass/sshpass-1.05.tar.gz/c52d65fdee0712af6f77eb2b60974ac7/sshpass-1.05.tar.gz

tar -zxvf sshpass-1.05.tar.gz

cd sshpass-1.05

./configure
make
make install

sonnyyu

#2
Sep 13, 2014, 06:56 am Last Edit: Sep 15, 2014, 01:47 am by sonnyyu Reason: 1
Help Compile/Installing Python Modules:

Two type Python Modules; The first type is the pure Python one will be easily install by

Code: [Select]
pip install #modulename

or even simply copy/download python files into proper location.

http://forum.arduino.cc/index.php?topic=266283.0


The second type is C-API which is needed compile, gcc will help.

Sample  Install crcmod:

Install python_devel

Code: [Select]
cd /usr/include/python2.7
wget -O  python_devel.tar.gz https://www.dropbox.com/s/z49hrigv3umaaj8/python_devel.tar.gz?dl=0 --no-check-certificate
tar -zxvf python_devel.tar.gz
rm python_devel.tar.gz


Download crcmod

Code: [Select]
cd /mnt/sda1
wget https://pypi.python.org/packages/source/c/crcmod/crcmod-1.7.tar.gz --no-check-certificate
tar -zxvf  crcmod-1.7.tar.gz
cd crcmod-1.7
python setup.py build


Code: [Select]
gcc -fno-strict-aliasing -Os -pipe \
-mips32r2 -mtune=mips32r2 -fno-caller-saves  \
-Wno-error=unused-but-set-variable -msoft-float -DNDEBUG -Os \
-fPIC -I/usr/include/python2.7 \
-c python2/src/_crcfunext.c -o build/temp.linux-mips-2.7/python2/src/_crcfunext.o

gcc -pthread -shared build/temp.linux-mips-2.7/python2/src/_crcfunext.o \
-L/usr/lib  -o build/lib.linux-mips-2.7/crcmod/_crcfunext.so



Code: [Select]
python setup.py install

sonnyyu

Install driver, library, application for Yun.

The freetds-dev  is open source library for Sybase  and Microsoft SQL server.

Code: [Select]
wget ftp://ftp.freetds.org/pub/freetds/current/freetds-dev.0.92.812.tar.gz
tar -zxvf freetds-dev.0.92.812.tar.gz


Code: [Select]
cd  freetds-dev.0.92.812


Code: [Select]
./configure
make
make install


Here you need take very long coffee break at stage "make"!

Testing connect to MS SQL Server

Code: [Select]
tsql -H192.168.0.111 -p 1433  -U sa -P password
locale is "C"
locale charset is "ASCII"
using default charset "ISO-8859-1"
1> use AdventureWorks2008
2> go
1> SELECT * FROM Person.Address where AddressID=1
2> go
AddressID       AddressLine1    AddressLine2    City    StateProvinceID PostalCode      SpatialLocation rowguid ModifiedDate
1       1970 Napa Ct.   NULL    Bothell 79      98011   e6100000010cae8bfc28bce4474067a89189898a5ec0    9AADCB0D-36CF-483F-84D8-585C2D4EC6E9    Jan  4 1998 12:00:00:000AM
(1 row affected)


Now Yun is able to directly talk to Sybase  and Microsoft SQL server.





sonnyyu


ardiri

one thing to note - try avoiding doing stuff in the main file system on the Yun; remember it is flash memory and has a limit of how many writes it can handle before going kaput. best to use a mounted SD card (i formatted mine with ext3 file system) and/or the /tmp directory which is mapped to a RAM drive i believe. so many cool things you can do with the Linux side of the Yun :P

sonnyyu

Compile and install Lua Module(C API)

Install lua_devel:

Code: [Select]
cd /usr/local/include
wget -O lua_devel.tar.gz https://www.dropbox.com/s/66zxd9gvdf7lvib/lua_devel.tar.gz?dl=0 --no-check-certificate
tar -xzf lua_devel.tar.gz
rm lua_devel.tar.gz


Download and compile lua-cjson:

Code: [Select]
cd /mnt/sda1/
wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
tar -xzf lua-cjson-2.1.0.tar.gz
cd /mnt/sda1/lua-cjson-2.1.0


Code: [Select]
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o lua_cjson.o lua_cjson.c
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o strbuf.o strbuf.c
gcc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o fpconv.o fpconv.c
gcc  -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o


Install lua-cjson:

Code: [Select]
cp cjson.so /usr/lib/lua/

Testing lua-cjson:

Code: [Select]
cd /mnt/sda1/
nano arduino.lua


Code: [Select]
#!/usr/bin/lua
-------simple data-------
local tab ={}
tab["arduino"] = "arduino.cc"
--encode json -------
local cjson = require "cjson"
local jsonData = cjson.encode(tab)

print(jsonData)
-- print result:  {"arduino":"arduino.cc"}

--decode json -------
local data = cjson.decode(jsonData)

print(data.arduino)
-- print result:  arduino.cc


Code: [Select]
root@Arduino:/mnt/sda1# chmod 755 arduino.lua
root@Arduino:/mnt/sda1# ./arduino.lua
{"arduino":"arduino.cc"}
arduino.cc


lua-cjson (C-API)  V.S.  pure lua  json module performance boost 1000% to 2000%!




sonnyyu

C++ compile:

Code: [Select]
nano hello.cpp

Code: [Select]
// 'Hello World!' program
#include <iostream>
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}


Code: [Select]
g++  hello.cpp -o hello

Code: [Select]
root@Arduino:/mnt/sda1# ./hello
./hello: can't load library 'libstdc++.so.6'


if I recompile it with static link

Code: [Select]
g++  hello.cpp -o hello  -static

Every thing is working, but obviously that is not I want.

After google ,

Code: [Select]
opkg update
opkg install libstdcpp



Code: [Select]
g++  hello.cpp -o hello

Code: [Select]
root@Arduino:/mnt/sda1# ./hello
Hello World!


sonnyyu

GNU utilities:

"file" Utility - Determine File Type:

Code: [Select]
opkg update
opkg install file


Code: [Select]
root@Arduino:/mnt/sda1# file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs),
with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped




sonnyyu

#9
Sep 15, 2014, 03:28 am Last Edit: Sep 15, 2014, 03:41 am by sonnyyu Reason: 1
The Grep from BusyBox is not complete:

Download latest Grep here(For testing purpose only):

Code: [Select]
wget -O grep_2.14-1_ar71xx.ipk https://www.dropbox.com/s/a9zuwmh3mipj7jt/grep_2.14-1_ar71xx.ipk?dl=0 --no-check-certificate

opkg install grep_2.14-1_ar71xx.ipk


sonnyyu

GNU utilities:

The utility "nm" lists symbol table of object files.

Code: [Select]
root@Arduino:/mnt/sda1# nm hello
00400180 r _DYNAMIC
00410ca0 A _GLOBAL_OFFSET_TABLE_
00400a70 t _GLOBAL__sub_D_main
00400a38 t _GLOBAL__sub_I_main
...

sonnyyu

GNU Binary Utilities - objdump:
objdump - display information from object files.


Code: [Select]
opkg update
opkg install objdump


sonnyyu


Code: [Select]
option fstype        ext3

for application which do a lot of read use ext4,  for a lot of write use ext2.  no go for ext3.


ext4 has speed advantage at reading , ext2 has speed advantage at writing.  select base on which one you are looking after.

sonnyyu

#13
Oct 18, 2014, 08:52 am Last Edit: Oct 18, 2014, 09:08 am by sonnyyu Reason: 1
Compile  barcode  program:

Code: [Select]
nano /mnt/sda1/barcode.c

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>


#define KEY_PRESS 1
#define KEY_KEEPING_PRESSED 2
int main (int argc, char *argv[])
{
struct input_event ev[64];
int fd, rd,size = sizeof (struct input_event);
char name[256] = "Unknown",i;
char *device = NULL;
char decode_scancode[]={0,0,1,2,3,4,5,6,7,8,9,0};
if (argv[1] == NULL){
printf("Please enter path to device\n");
return 1;
}
if ((getuid ()) != 0)
printf ("You must be as root for correct work!\n");
if (argc > 1)
device = argv[1];
if ((fd = open (device, O_RDONLY)) == -1){
printf ("Open error of device %s\n", device);
return 1;
}
ioctl (fd, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : %s (%s)\n", device, name);
while (1){
if ((rd = read (fd, ev, size * 64)) < size){
perror ("Read error");
return 1;
}
for (i=0; i< ((int)(rd/size)); i++) {
if (ev[i].type == EV_KEY) {
if ((ev[i].value == KEY_PRESS) || (ev[i].value == KEY_KEEPING_PRESSED)) {
if (ev[i].code < 12) {
printf ("%d", (decode_scancode[ev[i].code]));
}
else if (ev[i].code == 28) {
printf ("\n");
}
}
}
}
}
return 0;
}


Code: [Select]
gcc -o barcode barcode.c

barcode excutable for Yun:

https://www.dropbox.com/s/1a2860gei4ugiqk/barcode?dl=0

sonnyyu

#14
Oct 19, 2014, 10:06 am Last Edit: Oct 19, 2014, 10:10 am by sonnyyu Reason: 1
set up arbitrary-baud at Linux:

Code: [Select]
nano arbitrary-baud.c

Code: [Select]
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/termios.h>

int ioctl(int d, int request, ...);

int main(int argc, char *argv[])
{
 struct termios2 t;
 int fd,baud;

 if (argc != 3)
   {
     fprintf(stderr,"usage: %s <device> <baud>\n", argv[0]);
     return 1;
   }

 fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);

 if (fd == -1)
     {
       fprintf(stderr, "error opening %s: %s", argv[1], strerror(errno));
       return 2;
     }

 baud = atoi(argv[2]);

 if (ioctl(fd, TCGETS2, &t))
   {
     perror("TCGETS2");
     return 3;
   }

 t.c_cflag &= ~CBAUD;
 t.c_cflag |= BOTHER;
 t.c_ispeed = baud;
 t.c_ospeed = baud;

 if (ioctl(fd, TCSETS2, &t))
   {
     perror("TCSETS2");
     return 4;
   }

 if (ioctl(fd, TCGETS2, &t))
   {
     perror("TCGETS2");
     return 5;
   }

 printf("actual speed reported %d\n", t.c_ospeed);
 return 0;
}


Code: [Select]
gcc -o arbitrary-baud arbitrary-baud.c

download  Yun excutable here:

https://www.dropbox.com/s/6sm82bhxpj8voor/arbitrary-baud?dl=0

Go Up