Pages

Wednesday, August 14, 2013

New kernel for Rasberry Pi

[Prolog]

Last year, December, 2012 I received my Raspberry Pi board from RS Elements. Honestly it takes a long time, about 5 month. My order for the board was sent from July 2012. Actually I received several message from RS Elements that the order would take several months.

Anyway, this week I already finish my setup for raspberry, below picture represents my current setup.

My setup consists of below items:

  • Raspberry Pi board Rev 2.0

  • FTDI RS232 TTL, this devices for serial logging

  • Raspberry PI GPIO cable, this cable to avoid direct connection to Raspberry Pi GPIO pins

  • Female to male jumper cables to connect FTDI RS232 TTL to Raspberry GPIO pins

  • Class 10, 8 GB micro SD card with SD card housing

  • Micro usb power adapter, 5v, 700mA. (Raspberry Pi needs at least 700mA)

[Serial output configuration ]

Since I don't have TV / Monitor for raspberry pi specific use, I decide to debug and checking via serial log. To get serial log from raspberry pi you need to have FTDI RS232 TTL, and by connecting the devices' UART pin to raspberry pi UART pin.

Serial log is not always enabled by any images, anyhow Raspbian images that I used is already enable serial this serial log. But to make sure serial log is enable or not, you can check it on /boot/cmdline.txt files, the contents of that file should be like below:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

The line “console=ttyAMA0,115200 kgdboc=ttyAMA0,115200” enables serial log for kernel debug output.

In other hand, you also need to make sure that serial console is activated as well after Linux is completely boot. You can check on /etc/inittab files and make sure below line is not commented or missing

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

[Linux Kernel Compilation Preparation]

Before we go further, I would inform that we will use git extensively to download toolchains and Linux code for raspberry pi. So, it's highly recommended to install git in your Linux system.

In this post, I will reports my trial cross compiling Linux kernel for Raspberry Pi using my Slackware box. Before we go compiling, we need toolchains and as you know raspberry is on arm architecture so we need arm compiler to do this trial. You can download the toolchains from below path.

git clone https://github.com/raspberrypi/tools.git

That command will create tools-master directory which contains toolchains.

Now we have the toolchains and next we need to download Linux source for Raspberry pi, you also can download it from github using below command.

git clone https://github.com/raspberrypi/linux.git

You will find out new “linux” directory which contains Linux source code.

[Build New Kernel]

Clean Linux code using below command:

$ cd <linux code path> $ make mrproper

In this case I want to use “.config” from Raspbian image. The way I retrieve the “.config” file is like below:

  • Boot up your Raspberry using Raspbian image
  • Insert USB drive and mount it using below command

    # mount /dev/sda1 /mnt/

  • Copy Raspbian “.config” to usb, in my case I'll copy “.config” file as raspbian_config in usb drive

    # zcat /proc/config.gz > /mnt/raspbian_config

  • Also you can use <linux code path>/arch/arm/configs/bcmrpi-defconfig as your .config file
    But I have not try this one.

Copy Raspbian “.config” and use it as our linux “.config”. Insert your usb drive which contains Raspbian “.config” into you Linux system and copy it into Linux code directory as “.config”.

$sudo mount /dev/sda1 /mnt $cp /mnt/raspbian_config <linux code path>/.config

After that we need to set prefix compiler of our toolchain for compiling.

$ export CCPREFIX=<your tool-master directory>/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-

Our “.config” file can be from older version of our kernel code, so we need to sync it with our kernel by using below command. After executing the command some questions regarding new feature of new kernel will come out and need to be answered.

$ make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

And after synchronization of “.config” is done, we can go to build kernel and modules using below command.

$ make ARCH=arm CROSS_COMPILE=${CCPREFIX}

$ make ARCH=arm CROSS_COMPILE=${CCPREFIX} modules

If building process is successfully done, we need to gather all modules in one directory to make easier to control by using below command.

$ export MODULES_TEMP=~/modules

$ make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} modules install

Then, we can find our new kernel in: “<linux_code_path>/arch/boot/Image” and modules in “<linux_code_path>/modules/”. The next step is copying kernel and new modules into current raspberry rootfs in SD Card by using below command.

$ sudo mount /dev/sda1 /mnt (in assumption your sd card is on /dev/sda1)

$ cp <linux code path>/arch/boot/Image /mnt/boot/kernel.img

$ cp $MODULES_TEMP/* /mnt/lib/*

After that insert your SD Card into your Rasberry and reboot, if booting process is done successfully it means new kernel and modules is no problem.

References:

http://elinux.org/RPi_Hub

http://elinux.org/Rpi_kernel_compilation

Saturday, February 11, 2012

Ways to convert several DOS files into UNIX file

Usually I use the same vim scripts in Windows and Linux. Sometimes I copy the scripts from Windows to Linux and they still in dos format. Therefore when the scripts executed some errors come out because of the difference between Windows' and Linux's carriage line format.

Below is my way to convert several dos files into unix file

Using dos2unix

Using dos2unix tool is the simplest way, I just run below command $ find ~/.vim -name "*.vim" -print0 | xargs -0 dos2unix

Using fromdos

To use fromdos tool I need to make a bash script like below: #!/bin/sh list=`find ~/.vim -name "*.vim" -print` for files in $list; do fromdos < $files > $files-x mv $files-x $files done

Saturday, February 12, 2011

Changing Time Zone in Slackware 13.1

Travelling to different countries makes you experience different timezone, it can some hours ahead or after of your country timezone. Sometimes I experience this!, at the first time I was ignoring the time difference in my laptop. But this time not.

So below is the steps to change your timezone configuration in Slackware 13.1, you should do these steps as root.

  1. Change time zone links in /etc: "/etc/localtime-copied-from" to your current timezone in /usr/share/zoneinfo/xxx/xxx (xxx is depends on your timezone area)
    # ln -sf /usr/share/zoneinfo/xxx/xxx /etc/localtime-copied-from
  2. Replace your "/etc/localtime" with your current "/etc/localtime-copied-from"
    # cp -rf /usr/share/zoneinfo/xxx/xxx /etc/localtime
  3. Update your time using ntp server (pool.ntp.org)
  4. # ntpdate pool.ntp.org
    # hwclock -w

Isn't it simple? In my opinion this's simple, but sometime we can't do the simplest thing.


Tuesday, August 17, 2010

Vim 7.3 Released

On 16 August 2010, I had received an email from Vim google mailing list, this mail announce that Vim 7.3 was released to public finally. You can check below quote for release note by Bram Moolenaar.


Hello Vim users,

Announcing:  Vim (Vi IMproved) version 7.3

This is a minor release of Vim.  It consists of Vim 7.2 plus all
patches, updated runtime files and some more, see below.  It has been
two years since the 7.2 release, thus it's not that "minor".  But not
"major" either.  Something in between, don't know how to call that.

The most notable additions since 7.2:
- Persistent undo and undo for reload
- Blowfish encryption, encryption of the swap file
- Conceal text
- Lua interface
- Python 3 interface

Once you have installed Vim 7.3 you can find all the details about the
changes since Vim 7.2 with:
        :help version-7.3

Gratitude
---------

If you like Vim, this is the way to say thanks:
http://iccf-holland.org/clinic.html

Where to get it
---------------

The best way to obtain the latest Vim 7.3 is using Mercurial.
Summary:
        hg clone https://vim.googlecode.com/hg/ vim
        cd vim/src
        hg update vim73
        make
More information here: http://www.vim.org/mercurial.php

All downloadable files can be found below this directory:
        ftp://ftp.vim.org/pub/vim/

Direct link to the MS-Windows self-installing executable:
        ftp://ftp.vim.org/pub/vim/pc/gvim73.exe

Information about which files to download for what system:
        http://www.vim.org/download.php

A list of mirror sites can be found here:
        http://www.vim.org/mirrors.php

UNIX:
unix/vim-7.3.tar.bz2           sources + runtime files, bzip2 compressed

MS-WINDOWS one-size-fits-all:
pc/gvim73.exe                  installer for GUI and console executables,
                               includes all runtime files, many features

VARIOUS:
doc/vim73html.zip              help files converted to HTML

MS-WINDOWS separate files:
pc/vim73rt.zip                 runtime files
pc/gvim73.zip                  GUI binary for Windows 95/98/NT/2000/XP
pc/gvim73ole.zip               GUI binary with OLE support
pc/gvim73_s.zip                GUI binary for Windows 3.1 (untested)
pc/vim73d32.zip                console version for MS-DOS/Windows 95/98
pc/vim73w32.zip                console version for Windows NT/2000/XP
pc/vim73src.zip                sources for PC (with CR-LF)

DIFFS TO PREVIOUS RELEASE:
unix/vim-7.2-7.3.diff.gz               sources + runtime files
unstable/unix/vim-7.3f-7.3.diff.gz     sources + runtime files

Omitted in this version are:
- Extra and lang archives, these are now included in the main source
  and runtime archives.
- The 16-bit DOS, OS/2 and Amiga versions, these are obsolete.

Mailing lists
-------------

For user questions you can turn to the Vim mailing list.  There are a
lot of tips, scripts and solutions.  You can ask your Vim questions, but
only if you subscribe.  See http://www.vim.org/maillist.php#vim

If you want to help Vim development, discuss new features or get the
latest patches, subscribe to the vim-dev mailing list.  See
http://www.vim.org/maillist.php#vim-dev

Subject specific lists:
Multi-byte issues: http://www.vim.org/maillist.php#vim-multibyte
Macintosh issues:  http://www.vim.org/maillist.php#vim-mac

Before you ask a question you should search the archives, someone may
already have given the answer.

Reporting bugs
--------------

Send them to ...@vim.org>.  Please describe the problem precisely.
All the time spent on answering mail is subtracted from the time that is
spent on improving Vim!  Always give a reproducible example and try to
find out which settings or other things influence the appearance of the
bug.  Try starting without your own vimrc file: "vim -u NONE".  Try
different machines if possible.  See ":help bugs" in Vim.  Send me a
patch if you can!

Happy Vimming!

--
Q: Should I clean my house or work on Vim?
A: Whatever contains more bugs.

 /// Bram Moolenaar -- B...@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Thursday, August 5, 2010

Bad Evince Font in Slackware

When I install evince on my Slackware, sometimes I encounter a strange problem which is the font is not display correctly or looks weird, as like the picture below:


You can see that there are fonts look too bold and inconvenient to read. After diving in google, I found that the problem comes from the Nimbus font in slackware package. To check and fix it you can follow instructions below:
  • Check fonts in pdf file
  • $ pdffonts file.pdf
    name                                 type      emb sub uni object ID
    ------------------------------------ --------- --- --- --- ---------
    Times-Italic                         Type 1    no  no  no       5  0
    Times-Roman                          Type 1    no  no  no       7  0
    Times-Bold                           Type 1    no  no  no      13  0
    Courier-Bold                         Type 1    no  no  no      18  0
    XOEOHB+CMSY10                        Type 1    yes yes no      21  0
    Courier                              Type 1    no  no  no      23  0
    RXRCVR+CMSY7                         Type 1    yes yes no      26  0
    CRMLEZ+NimbusRomNo9L-Regu-Slant_167  Type 1    yes yes no      32  0
    
  • Check"Times" compatible font
  • $ fc-match "times"
    n021004l.pfb: "Nimbus Roman No9 L" "Medium"
    
  • Find n021004l.pfb location
  • $ su
    password:
    # find / -name "n021004l.pfb" -print
    /usr/share/fonts/Type1/n021004l.pfb
    /usr/share/libwmf/fonts/n021004l.pfb
    
  • Download new n021004l.pfb
  • As I get from searching in google, the problem is n021004l.pfb in Slackware package is not updated yet, so we need to replace it with the new one. In this case I'll replace it with the Fedora 13 URW fonts package. You can download the package from http://koji.fedoraproject.org/koji/buildinfo?buildID=138570
    
    
  • Extract the rpm package
  • # rpm2cpio urw-fonts-2.4-9.fc13.noarch.rpm | cpio -idmv 
  • Copy fonts file and reboot
  • # cd usr/share/fonts/default/Type1
    # cp n021004l.pfb /usr/share/fonts/Type1/n021004l.pfb
    # reboot 

After reboot then I check evince display, and the result is like below. There we can see that the font looks better and convenient than before.


I hope this tutorial is helpful.

Monday, July 26, 2010

Get apk from phone

When I do flashing my Samsung Spica for the first time, I lost all of my application. It means I need to download it all again from market and costs my credit. Therefore I need to get my apk from phone, and backup it all to my PC.

After doing some tests and trials based on a clue from my friend. I finally find a way to backup all of applications by downloading all installed apk from the phone, and it's really simple.

Before going further, we need to install android SDK:

  • Download android sdk from here 
  • Extract android sdk zip file to C:\
  • Add this "C:\android-sdk-windows\tools" to windows path in environment variable

And then to allow you accessing /data/app directory, you must have root permission therefore wee need to root the device. You can follow instructions in here to root your device here, but please be careful because it can bricks your device.

When you download applications from market, the system will store the apk files in /Data/app. Base on this information we can pull all of downloaded apk from phone to PC by using adb pull command.

adb pull /data/app "your destination directory"

And you can find all of your downloaded apk in "your destination directory".

Monday, July 19, 2010

PDCurses for MinGW32

As I know MinGW doesn't come with graphic control library, it isn't like borland or turbo which brings conio.h. But you can use curses library for alternative. If you use Linux you can find ncurses library, but if you're windows user you can use PDcurses.

In this tutorial I'll explain how to install PDcurses for MinGW32 compiler in MS Windows. The first things you need are Installed MinGW32 compiler and PDcurses source. You can download MinGW from here and PDcurses from here.

Set up MinGW32
  1. Install MinGW32, don't forget to install 'MinGW make' also (if you don't want to install MSys), in this case I'll install MinGW in C:\MinGW
  2. Set environment path for MinGW bin directory
    • Go to control panel
    • Click System
    • Choose Advanced tab and click "Environment Variables" button
    • Add PATH variable for user, if you have one you can skip this
    • Select PATH variable and Edit
    • In "variable value" text box, add C:\MinGW\bin, and don't forget to use ';' (semicolon) as delimiter
  3. If you didn't install MSys so you need to rename mingw32-make.exe become make.exe
  4. CD C:\MinGW\bin
    RENAME mingw32-make.exe make.exe

Install PDcurses
  1. I assume you have downloaded PDCurses source successfully, in this case I have downloaded PDCurses-3.4.tar.gz
  2. Unpack it by using winrar to C:\ and you will have C:\PDCurses-3.4 directory
  3. Compile win32 PDcurses with DLL
  4. CD C:\PDCurses-3.4\win32
    make -f gccwin32.mak DLL=Y

  5. Copy pdcurses.dll to C:\MinGW\bin
  6. COPY pdcurses.dll C:\MinGW\bin
  7. Copy pdcurses.a to be C:\MinGW\lib\libpdcurses.a
  8. COPY pdcurses.a C:\MinGW\lib\libpdcurses.a
  9. Copy pdcurses header file to C:\MinGW\lib\include
  10. CD ..
    COPY *.h C:\MinGW\include

Test PDcurses
  1. Create test.c
  2. #include <curses.h> int main()
    {
        initscr();
        printw("Hello World !!!\n");
        refresh();
        system("pause");
        endwin();
        return 0;
    }

  3. Compile test.c and check if there is any error
  4. gcc test.c -o test -lpdcurses
  5. Test executable file. If you can see "hello world" it means everything goes well
  6. test.exe

I hope this tutorial will be helpful for who need it.