2014년 11월 16일 일요일

Setting Karlinux for ARM Build Environment

Introduction


I want to be a excellent linux kernel developer, so I have a plan to make my own linux kernel, karlinux. To simplify the work, the target of karlinux is only ARMv7 multicore. (If I have a time, I will extend it to ARMv8 multicore.)
My karlinux will be excuted on QEMU. QEMU is an emulator for a specific hardware, such as versatile, etc. By using QEMU, I can test my bootloader, linux kernel, and framework.
Today, I will explain how to set up environment for karlinux. I will set QEMU and print "Hello! World!" in karlinux.

Step 1: Install QEMU from source


At first, necessary package should be installed
sudo apt-get install libpixman-1-dev libglib2.0 zlib1g-dev libsdl-console-dev libncurses5-dev

I prefer to use Linaro's release, so I downloaded source code from Linaro.
wget https://launchpad.net/qemu-linaro/trunk/2014.01/+download/qemu-linaro-1.7.0-2014.01.tar.gz

Unzip the tarball, and compile it.
tar xvf qemu-linaro-1.7.0-2014.01.tar.gz

Configure and build QEMU.
cd qemu-linaro-1.7.0-2014.01
mdkir build && cd build
sudo apt-get install flex bison
../configure --prefix=$PWD/../install --target-list=arm-softmmu --enable-debug

At this point, I got a problem of DTC. So, I downloaded DTC from its git, and manually installed. Download DTC

Extract the file and move it to qemu/dtc/, and compile dtc form source using make. For new DTC, restart configuring QEMU using previous command.
../configure --prefix=$PWD/../install --target-list=arm-softmmu --enable-debug

Install the generated QEMU binaries.
make install

For the last, add the path of qemu binaries to your environment variables.
vi /home/YOUR_ACCOUNT/.bashrc

export PATH=/home/YOUR_ACCOUNT/qemue-linao/qemu-linaro-1.7.0-2014.01/install/bin:$PATH

You may need to modify the path.

Step 2: Try ARM Linux prebuilt image on QEMU


Now, I will use QEMU to emulate Versatile Exporess, ARM's reference board for its Cortex-A processor.

First grab a system image for vexpress form Linaro's release site:
wget https://releases.linaro.org/images/12.02/oneiric/nano/vexpress-a9-nano.img.gz
gzip -d vexpress-a9-nano.img.gz

Note that -nano is one of Linaro's root filesystem. See here for details.

Since QEMU requires us to specify Linux kernel and init ramdisk in launching an emulated board, extract the two files from the downloaded image.
mkdir -p ~/tmp/boot/
sudo mount -o loop,offset=$((63*512)) vexpress-a9-nano.img ~/tmp/boot

Strip u-boot's header from uInitrd.
dd if=~/tmp/boot/uInitrd of=~/tmp/initrd skip=64 bs=1

At this point, I'm ready to the emulated vexpress.

Use the following commands to start the ARM Linux inside the QEMU emulator.
qemu-system-arm -kernel ~/tmp/boot/uImage -M vexpress-a9 -cpu cortex-a9 -smp 4 -serial stdio -m 1024 -initrd ~/tmp/initrd -append 'root=/dev/mmcblk0p2 rw mem=1024M raid=noautodetect console=ttyAMA0,38400n8 rootwait vmalloc=256MB devtmpfs.mount=0' -sd vexpress-a9-nano.img

By using the command, linux window is shown up.

For test QEMU, I used vexpress a9, but my real target is vexpress a15. From the next post, I will modify the command for vexpress a15.

Enjoy your QEMU.

 

2014년 11월 8일 토요일

Use SSD as Rootfs of CT

Introduction


I had a redundant SSD, and I was worried about system size and speed of CT. So, I tried to use the SSD as rootfs. However, I don't use the SSD as rootfs any more, because their speeds are not quite different, and using SSD as extenal drive provides much more size. But, if you have small sd card, you can try it.

Step 1: Mount Current Rootfs on CT


At fisrt, mount the current rootfs. In my case, curenty rootfs is /dev/nand. It should be mounted at accessable directory, such as /tmp/src.
sudo su - root
mkdir /tmp/src
mount /dev/nandb /tmp/src

Also, we need to know where the SSD is. You can find the SSD by below commend
fdisk -l

Step 2: Format and Mount SSD


We need to format the SSD and set the SSD as ext4 to use in linux system. My SSD is /dev/sda1 found from fdisk command.
mkfs ext4 /dev/sda1

We need to mount the SSD to some accessable directory, such as /tmp/dst.
mkdir /tmp/dst
mount /dev/sda1 /tmp/dst

Step 3: Copy Rootfs From Nand to SSD


By using belowd command, you can copy all data from nand to SSD. It will take more than 10 minutes. In my case, almost 30 minutes are taken.
(cd /tmp/src; tar --backup -c *) | tar -C /tmp/dst -xv

Step 4: Set Boot Partition


When you finish the copy, you have last job. Without this, your CT will boot from nand always. You need to change boot partition by changing uEnv.txt.
mkdir /tmp/boot
mount /dev/nanda /tmp/boot
cd /tmp/boot
vi uEnv.txt

There is one line /dev/nandb. It should be changed to /dev/sda1.

We have done. Just do sync and reboot
sync
reboot

Your CT will boot by SSD. Enjoy your CT with SSD.

 

[contact-form-7 id="24" title="Karl"]

2014년 11월 6일 목요일

Fork & Execv

Below code is simple fork & execv code for system programming

The sender generate a thread to print "I run".

After sender generate the thread,

it just prints out the PID of the thread.

Receiver is the thread.

 
//Receiver

#include <stdio.h>

#define DIE(x) perror(x), exit(1)

int main(int argc, char **argv)
{
printf("I run %s\n", argv[1]);

return 0;
}


 
//Sender

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
int status;
pid_t pid;
char *argv[3];

argv[0] = "test1";
argv[1] = "boot";
argv[2] = NULL;

switch(pid=fork())
{
case -1: // Error
perror("fork");
exit(1);
break;
case 0: // child
printf("%d\n", (int)getpid());
execv("test1", argv);
exit(0);
break;
default:
while(wait(&status) != pid)
continue;
printf("%d\n", (int)getpid());
break;
}

return 0;
}

 

[contact-form-7 id="24" title="Karl"]

Enable Wi-Fi on Lubuntu 13.08

CT can connect internet via wifi or lan cable.

Lan cable is definitely easy to connect, just plug in.

However, wifi needs some works to connect.

Below step is how to connect wifi.

My step is started form installing vim editor.

If you have already installed vim,

start installation of linux-firmware.
sudo apt-get install vim

sudo apt-get install linux-firmware

sudo apt-get install wifi-rader

These are necessary packages.


For wifi, "bcmdhd" module is needed.

modprobe bcmdhd

To eanble automatically wifi at the bot time, modify /etc/modules
vi /etc/modules

add this module at the end of file
bcmdhd

Then reboot.
sudo reboot

now make configuration for wifi



ifconfig wlan0 up

iwlist wlan0 scan

By iwlist command, I can find the wifis which are near by me.

wpa_passphrase commnad make configuration fot which SSID will be used.
wpa_passphrase [SSID] [PASSWORD] >> /etc/wpa_supplicant.conf

[SSID} and  [PASSWAORD] are my wifi's.

Then, set parameter of wifi.
vi /etc/network/interfaces

type below 3 lines at the end of file.
auto wlan0

iface wlan0 inet dhcp

wpa-conf /etc/wpa_supplicant.conf

Last is set nameserver.
vi /etc/resolv.conf

add this line.
nameserver 8.8.8.8

Done.

After reboot, enjoy wifi.

 

[contact-form-7 id="24" title="Karl"]

Porting Lubuntu 13.08 to CT (NAND flash)

When I first used CT, I installed Lubuntu 13.08.

This installation was so tough for me.

At the beginning of flashing, I used Linux Mint 12.10.

It has some problems to install CT's USB driver.

Ubuntu 12.04 LTS is easiest OS, I think.

You can check your linux OS.
cat /etc/os-release

Linux kernel version can be shown by this command.
uname -a

For CT, I will use lubuntu which is a light ubuntu with HDMI display output.
wget http://dl.cubieboard.org/software/a20-cubietruck/lubuntu/ct-lubuntu-nand-v1.02/lubuntu-desktop-nand-hdmi.img.gz .
gzip -d lubuntu-desktop-nand-hdmi.img.gz .

Now, I have the lubuntu image.

Next, Download and Install LiveSuit 3.05.

I could not find the install file address, so I just download from

http://docs.cubieboard.org/tutorials/common/livesuit_installation_guide

However, Do not trust the installation guide for linux in DOC web page.

Ths guide is for old LiveSuit version.

Follow below command.
mkdir cubie
mv LiveSuitV305_For_Linux64.zip cubie
cd cubie
unzip LiveSuitV305_For_Linux64.zip
cd LiveSuitV305_For_Linux64
chmod +x LiveSuit.run
sudo apt-get install dkms
sudo ./LiveSuit.run

That's all.

If you are using ubuntu 12.04 LTS, you don't need to use dpkg or RPM.

However, there was another problem to make connection between CT and my ubuntu which is running on VMware.

The connection between CT and VMware is unstable.

So, I needed to register usb port manually.

To fix this problem, I needed to add some parameters into vmx file.

At first, check your usb id in VMware.



This file is placed in your VM directory.

In that file, there will be two ids.

write them in somewhere.

Then, open vmx file for the virtual machine with gVim and add those ids like this.
usb.quirks.device0 = "0x1f3a:0xefe8 skip-reset"



0x1f3a and 0xefe8 are my usb ids

Finally, we have finished all setting for flashing.

Now turn CT off, and unplug CT's power.

run the Livesuit with sudo
sudo /Bin/LiveSuit/LiveSuit



While pushing FEL button, connect the cable into CT.

IF you get the error message like "Get Device Stage Failed!",

use sudo.

To turn it off, push the power button more than 10 seconds.

Then do it again.

You can see a popup asking format or not.

Press yes.

Now your CT will have and run the image which you want.

 

[contact-form-7 id="24" title="Karl"]

2014년 11월 5일 수요일

CubieTruck Introduction

Half year ago, I bought CubieTruck(CT) to use as a server.

The CT is doing many things for me.

This blog is running on the CT,

and it stores many media file.

It has low performance power,

but it is enough for personal server.

The spec of CT is below.

  • SoC: Allwinner A20


  • 2 GiB DDR3 @ 480 MHz

  • 8 GB NAND flash built-in, 1x microSD slot, 1x SATA 2.0 port (Hard Disk of 2,5").

  • 10/100/1000 RTL8211E Gigabit Ethernet

  • 2x USB Host, 1x USB OTG, 1x CIR.

  • S/PDIF, headphone and HDMI audio out, mic and line-in via extended pins

  • Wi-Fi and Bluetooth on board with PCB antenna (Broadcom BCM4329/BCM40181)

  • 54 extended pins including I²C, SPI

  • Dimensions: 11 cm × 8 cm






I will post many things about the CT.

Let's share information about CT.

 

[contact-form-7 id="24" title="Karl"]

2014년 11월 3일 월요일

WordPress with Multisite on Nginx


Source URL


What is Multisite


Basically, WordPress has one web site. If you want to have more than two web site in one machine, you need to set up Multisite. Using multisite is easy, when WordPress is in web hosting service. However, if you use your own web server, such as CubieTruck, you need to find another way. Here, I will introduce how to use multisite on CubieTruck running WordPress on Nginx. While WordPress supports sub-domain and sub-directory, but only sub-directory is explained.

Step 1: Back Up WordPress


To be care of any error, we need to prepare for it. Before starting, please back up your date.

Step 2: Disable all Plugin


Even if you make new web site, it inherits previous web site. So, please disable your all plugin.

Step 3: Modify wp-config.php file


To enabel multisite, you need to insert some code in your wp-config.php file. Open wp-config.php file, and find the line
$cd wordpress
vi wp-config.php

/*That's all, stop editing! Happy blogging. */

Above the line, insert this code.
/* Multisite */
define('WP_ALLOW_MULTISITE', true);

Step 4: Change Network Setup


Move to Dash board >> Tools >> Network Setup. Selecte Multisite and sub-directory.

Step 5: Make blogs.dir directory


Make blogs.dir dirtectory in wp-content directory.

Step 6 & 7 are depend on your system. Please check your Network Setup


Step 6: Modify wp-config.php again


Add the following code to your wp-config.php file in /wordpress and same line previous.
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'xaliver.dlinkddns.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Step 7: Make .htaccess file


Add the following to your .htaccess file in /wordpress/.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

Step 8: Login again


We have almost done. Please logout and login. If you have problem of login, please remove browser cache ans cookies.

Step 9: Make New Site and New User


Now, you can make new site, and you can assign the new site to other user.

Enjoy your new site.


 

[contact-form-7 id="24" title="Karl"]

Install LEMP(nginx, MySQL, PHP) Server in CubieTruck


Source URL


What is LEMP


LEMP is an acronym for Linux, nginx(Pronounced as Engine X), MySQL, PHP. Nginx is a web server like Apach. Nginx is similar to Apache, but better suite for Webservers where resources like memory are limited. Let us now install LEMP in out CubieTruck. My Cubice truck is running on Aruntu.

Step 1: Update & Upgrade


$ sudo apt-get update
$ sudo apt-get upgrade

Step 2: Install nginx and set configuration


Install nginx
$ sudo apt-get -y install nginx

By default, nginx serves it static content out of /usr/share/nginx/www. We need to chage it to
$ sudo mkdir ~/SSD/WordPress/www

Now it's time to create nginx virtual host(actually server blocks, in nginx term) file. In nginx, multiple sites can be hosted from a single server by creating multiple virtual hosts. Let us create a virtual host for testing our nginx installation and to use ~/SSD/WordPress/www as the root for serving its contents instead of the defualt /usr/share/nginx/www.

There are two step in creating a virtual host. First, we need to create a virtual host configuration file in /etc/nginx/sites-available folder, second we need to symlink that file to /etc/nginx/sites-enabled folder.

Before doing so, first we need to unlink the default nginx virtual host configuration from sites-enabled folder.
$ sudo service nginx stop
$ sudo unlink /etc/nginx/sites-enabled/default

Now let us create a most simple virtual host config file. For more information on nginx configuration head on to his
cd /etc/nginx/sites-available/
sudo vi mysite
server{
listen 80;
root ~/SSD/WordPress/www;
index index.html index.htm;
}

Create a symlink for the above created file in the sites-enabled folder.
$ sudo ln -s /etc/nginx/sites-available/myite /etc/nginx/sites-enabled/

Now we have created and enabled our first virtual host, to test it, let us now create a test index.html file.
$ cd ~/SSD/WordPress/www
$ vi index.html

put the below contents in it.
 "Welcome to <span class="hiddenSpellError" pre="to " data-mce-bogus="1">nginx</span>" 

"Hello World"


Start or Restart nginx to use the new virtual host.
$ sudo service nginx start

and type your ipaddress of the cubietruck in any browser which is connected to yout local network.
And you can see "Hello World".

1414423727257

Step 3: MySQL Installation


$ sudo apt-get -y installl mysql-server

During the installation of mySQL server, it will ask for a root password, provide a strong password and note it down in somewhere. We will use it in future.

1414497481196

Step 4: PHP Install


PHP-FPM which is a FastCGI interface that will allow Nginx to send requests to PHP, PHP-APC is an extension to PHP that helps accelerate PHP's performance. PHP5-MySQL is the PHP interface for MySQL database.
sudo apt-get -y install php5-fpm php-apc php5-mysql

Step 5: Configurating PHP for nginx


In this step, we need to configure PHP to work with nginx. Let us restart php5-fpm first, to make sure that APC extension is loaded.
sudo service php5-fpm restart

Now we need to modify our nginx blocks configuration file that we have created in step 2.
$ sudo vi /etc/nginx/sites-available/mysite

Change the contest as shown below
server{ 
listen 80;
root ~/SSD/WordPress/www;
index index.php index.html index.htm;

location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Now we have added index.php to the index pages and added some more lines to redirect PHP requests to PHP5-FPM. Let us now check if PHP is working properly, by creating a test.php file in the nginx root folder which is now ~/SSD/WordPress/www.
$ cd ~/SSD/WordPress/www
$ vi test.php
phpinfo();
?>
$ sudo service nginx restart

Now type your ip address of cubietruck/test.php, you can see the below page.

1414497933210

Step 6: Installing and configuring PhpMyAdmin (Optional)


PhpMyAdmin is a free and open source tool written in PHP intended to handle the administration of MySQLwith the use of a web browser. It can perform various tasks such as creating, modifying or deleting databases,tables, fields or rows; executing SQL statements; or managing users and permissions.
sudo apt-get install phpmyadmin

During the installation, phpmyadmin will ask you if you want to configure the database with dbconfig. Go ahead and choose yes.

1414502876225

Input MySQL’s database password when prompted and click ok.

1414502905130

When phpmyadmin prompts you to choose a server (either apache or lighttpd) hit tab, and select neither one.
Now to make phpMyAdmin to work with nginx we need to modify the server blocks that we have created earlier.
$ sudo vi /etc/nginx/sites-available/mysite
server{
listen 80;
root ~/SSD/WordPress/www;
index index.php index.html index.htm;

location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}

Now put your ip address/phpmyadmin, it will load the phpMyAdmin page. It will ask for user name and password. Provide “root” as username and give the mysql password to login.

If you have json problem, open /etx/php5/mods-available/json.ini and uncomment priority=20 and reboot.

1414844603025


 

[contact-form-7 id="24" title="Karl"]

Install and Configure WordPress in CubieTruck


Source URL


What is WordPress


WordPress is web software you can user to create a beautiful website or blog. We like to say that WordPress is both free and priceless at the same time. The core software is built by hundresg of community volunteers, and when you're ready for more there are thousands of pulugins and themes available to transform your site into almost anything you can imagin.

Step 1: Download and Extract WordPress


Replace example with what ever directly name you want
sudo mkdir example
cd ~/SSD/WordPress/
wget http://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz

Step 2: Create the Database and User


Login to phpmyadmin interface with your username and password. (This is the same password that you created during the MySQL installation)

1414904493210

Now nagifate to the database section and create a database named "wordpress", Type wordpress in the Create new database filed and user the default collation option and click create.

1414904606478

Now you will have a database created with a name wordpress. Just click the check Users next to the Status. In the next page, click Add a new User as shown below.

1414904779034

Now enter "wordpress" as the username, select local in the host drop down box and enter a strong password. Just select the Grant option under Administration tab checked and click Go.

1414904969511

Step 3: Set up wp-config.php


Return to where you extracted the WordPress package in Step 1, copy the file wp-config-sample.php to wp-config.php, and open it in a text editor.
cd ~/SSD/WordPress/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo vi wp-config.php

Under MySQL settings change the below fields to appropriate ones that you created in step 2.
// *** MySQL settings - You can get this info from your web host ** ///** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'YOUR_PASSWORD');

Save and close the file

Step 4: Changing the Access Privileges


Now in order for wordpress to access the files that are in the webserver, we need to provide proper access permissions to the wordpress folder. Be default nginx web server work with www-data user. So we need to provide full access permissions to www-data user for the wordpress folder.
sudo chown -R www-data:www-data ~/SSD/WordPress/wordpress/

Step 5: Changing the nginx Config file


Now we are almost done with installing wordpress. One last thing to do before we move on to the wordpress interface is, changing the nginx server block, to work with wordpress. It is rather easy.
Just copy the same "mysite" file and modify it like the below one else just use the below one and modify it according to your requirement.
cd /etc/nginx/sites-available
sudo cp mysite home
sudo vi home

and put the below contents
server{
listen 80;
server_name home;

access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;

root ~/SSD/WordPress/wordpress;
index index.php;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ .php$ {
try_files $uri =404;

fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

save and close the file.

Now we need to unlink previous mysite file and link home file to the site-enabled folder.
sudo unling /etc/nginx/sites-enabled/mysite
sudo ln -s /etc/nginx/sites-available/home /etc/nginx/sites-enabled/home

Restarting nginx
sudo service nginx restart

Step 6: Logging into WordPress


Now head on to your favorite browser and type your_ip. You can see the page similar to the one below.

1414917531952

 

Enter a title for your webpage in the Site Title Field.
Enter username and password in their corresponding field.
Enter your email id and hit install WordPress.

After this you can login to your WordPress Dashboard with the username and password that you have create now.

1414917621727

Now you have installed full fledged WordPress.

Congraturations!


 

[contact-form-7 id="24" title="Karl"]