Category Archives: Raspberry pi

Raspberry Pi notes : Emulating Jessie image with 4.1.7 kernel

To emulate Jessie image with 4.1.7 kernel in this repo, steps differ slightly compared to a lot of (and standard) wheezy emulating guides on the internet.

In order to prepare your image for the first time, you will need a linux box (or any other OS that can mount an ext4 file from a .img file.)

I’m assuming that you have,

1. Latest jessie image

2. 4.1.7 qemu-kernel for versatilepb.

Steps :

fdisk -l <image-file>. It should show output like this one :

Disk 2015-11-21-raspbian-jessie.img: 3.7 GiB, 3934257152 bytes, 7684096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xea0e7380

Device                          Boot  Start     End Sectors  Size Id Type
2015-11-21-raspbian-jessie.img1        8192  131071  122880   60M  c W95 FAT32 (LBA)
2015-11-21-raspbian-jessie.img2      131072 7684095 7553024  3.6G 83 Linux

The filesystem (.img2) starts at sector 131072, which equals 512 * 131072 = 67108864 bytes. Use this as the offset, ie. mount -v -o offset=67108864 -t ext4 your-image-file.img /path/to/mnt/

  1. mount -v -o offset=67108864 -t ext4 /path/to/mnt/
  2. cd /path/to/mnt
  3. nano ./etc/ld.so.preload
  4. Comment out every entry in it, ctrl + x –> Y to save and exit.
  5. nano ./etc/fstab
  6. Comment out entries containing /dev/mmcblk, ctrl + x –> Y to save and exit.
  7. cd ~
  8. unmount /path/to/mnt

Once done with this changes, you can emulate it on Qemu by, qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda <image-file-name.img>

Hope it helps.

Raspberry Pi notes : Emulating RPi (Raspbian wheezy) on Qemu

Emulation is a necessary aspect of embedded system development and Qemu is the right open source tool to do so for linux based SBCs.

To emulate RPi on Qemu, you will need two necessary files.

1) Rpi kernel (`git clone https://github.com/dhruvvyas90/qemu-rpi-kernel.git` or dowload this zip file)

2) Rpi rootfs (That would be second portion of official .img file) You can have a look at https://www.raspberrypi.org/downloads/

You will also need to have latest Qemu for your OS. Go to official (http://wiki.qemu.org/Download).

You can probably download Qemu by using package manager as well.

1) For ubuntu (and any debian based OSes):

`sudo apt-get install qemu`

2) For Mac OS X :

`brew install qemu`

3) For windows users :

You will have to download Qemu installer.

Once, Qemu installed and you have necessary files for emulation as mentioned above, Follow these particular steps for emulating RPi.

This particular guide shows you how to prepare image for emulating Raspbian-wheezy image. If you’re trying to emulate Jessie images, you should follow the other guide on this blog.

  1. `qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda image-file-name.img`
  2. You should get # prompt (bash) at the end of processing.
  3. `nano /etc/ld.so.preload
  4. Comment the 1st line saying /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so by putting # in front of it.
  5. Now, `nano /etc/udev/rules.d/90-qemu.rules`
  6. Add these lines.

KERNEL=="sda", SYMLINK+="mmcblk0"

KERNEL=="sda?", SYMLINK+="mmcblk0p%n"

KERNEL=="sda2", SYMLINK+="root"

  1. `sudo poweroff`
  2. Re-emulate by this command, `qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda image-file-name.img`

Key notes :

You can have maximum ram upto 256 only as there’s a bug in versatilepb which doesn’t allow to emulate more than 256 MB.

You might want to set up ssh by adding this extra flag while using Qemu-redir tcp:2222::22

Hope it helps.

Raspberry pi notes : Libmodbus on Raspberry Pi

Raspberry Pi has gained popularity in recent days and a lot of enthusiasts / hobbyist would like to implement libmodbus on RPi to host a modbus master / slave. Here is “how to install libmodbus” guide on RPi (Raspbian).

1.Installing dependancies.

`sudo apt-get install -y autoconf libtool`

2. Clone libmodbus master branch by,

`git clone https://github.com/stephane/libmodbus/`

3. Enter the directory.

`cd libmodbus`

4. `./autogen.sh && ./configure –prefix=/usr && make && sudo make install`

5. To test the libmodbus, try examples under tests folder.

To compile code, use, gcc -o filename filename.c `pkg-config –libs –cflags lidmodbus`

Additional notes :

If you’re using linux distros (other than debian based), such as Arch Linux or PiDora, you must use relevant package manger options in step #1. (like pacman or yum)

In order to use native RPi serial port for RTU mode, you MUST disable serial console by using sudo raspi-config as it conflicts with modes RTU communication.

Native serial port is listed as ttyAMA0 under /dev/ directory.

If you’re using UART to RS485 chip like 75176 or anything similar, you would like to check the libmodbus raspberry pi fork which makes use of a GPIO to enable rx-tx. (Link : https://github.com/dhruvvyas90/libmodbus)

Raspberry pi notes : Custom HDMI modes for 7″ (800×480) displays and 4.3″ / 5″ (480×272) displays

In order to make 7″ LCDs (800×480) work with RPi, follow these steps.

  1. Boot RPi
  2. sudo nano /boot/config.txt
  3. Add following lines..
  4. #increase HDMI signal strength (just a black screen if not set!)
    config_hdmi_boost=4#remove black borders
    disable_overscan=1#set specific CVT mode
    hdmi_cvt 800 480 60 6 0 0 0

    #set CVT as default
    hdmi_group=2
    hdmi_mode=87

  5. ctrl + x and ‘y’ to save the fine.
  6. sudo reboot

In order to make 4.3″ or 5″ LCDs work with RPi, (480×272), follow these steps

  1. Boot RPi.
  2. sudo nano /boot/config.txt
  3. Add following lines…
  4. config_hdmi_boost=4
    #remove black borders
    disable_overscan=1#set CVT as default
    hdmi_group=2
    hdmi_mode=87
    hdmi_timings=480 0 1 41 2 272 0 2 10 2 0 0 0 60 0 9009000 3
  5. Ctrl + x and ‘y’ to save the changes.
  6. sudo reboot

Hope it helps.

Hosting a DC hub (PtokaX) on Rpi

Hosting a DC hub can be irritating sometimes as it needs to be kept online 24×7 and also it can be resource hungry as number of users connecting to the hub increases.

image_rpi_dc

In this post, we will see how a PtokaX DC++ hub can be hosted on a Raspberry Pi (or any other SBC / PC running a Debian based OS).

In this post, I am not gonna go into detail how to connect Rpi to the network and all that stuff as I assume Rpi is already configured and running a raspbian image. I also assume that you already have hub config files and scripts ready (/cfg and /scripts folders).

Steps:

1. Installing necessary dependencies and tools.

sudo apt-get -y install make g++ zlib1g-dev liblua5.1-dev liblua5.2-dev

2. Getting PtokaX unix source

wget http://www.PtokaX.org/files/0.5.0.2-nix-src.tgz

3. Extracting tar

tar -xf 0.5.0.2-nix-src.tgz

4. Compiling source

cd PtokaX

make

After successful compilation, copy existing config files (cfg folder) and necessary lua scripts (scripts folder) to PtokaX home path.

Change necessary details like server ip address and other by modifying Settings.xml file.

After making necessary changes, start PtokaX from terminal by typing…

sudo ./PtokaX

See if it is working.

You can add it to rc.local if you want to enable it every time Rpi boots up.

(Ref: link1, link2, link3)

I hope it helps.

Drop comments in case of any problems / difficulties. I will try my best to solve.

Happy hacking.