Making Custom Linux Image

1. Use gparted to shrink the partition as much as possible (optionally use sfill / zerofree beforehand, which may not help)

sudo gparted

2.Use fdisk to check the end position

sudo fdisk -l /dev/sdb

Disk out.img: 1.5 GiB, 1605369856 bytes, 3135488 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: 0x562fb1a7

Device Boot Start End Sectors Size Id Type
out.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
out.img2 137216 3135487 2998272 1.4G 83 Linux

3. use dd with sparse parameter, to transfer all the content in both filesystems

sudo dd if=/dev/sdb of=/home/airo-ubuntu/out.img conv=sparse bs=512 count=$[3135487 + 1]

4. use fisk again to check integrity

fdisk -lu out.img

Disk out.img: 1.5 GiB, 1605369856 bytes, 3135488 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: 0x562fb1a7

Device Boot Start End Sectors Size Id Type
out.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
out.img2 137216 3135487 2998272 1.4G 83 Linux

UART Port Usage on Raspberry Pi

UART Brief

TxD = BCM pin 14
RxD = BCM pin 15

Default inputs

 

Preventing Linux from claiming the UART port

raspi-config

Run sudo raspi-config and check if it has the option advanced options -> serial. If it has, set it to disabled and you’re done.

http://wiringpi.com/reference/serial-library/

 

Enable uart in /boot/config.txt

In order to avoid manual step 5 and some issues that might occur with port ttyAMA0 not being found (/dev/ttyAMA0 being absent) you can set enable_uart=1 in /boot/config.txt, which seems to bring back /dev/ttyAMA0 and ports 15+16 are now in ALT0 state after reboot.

Good read: http://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3

 

#include <stdio.h>
#include <wiringPi.h>
#include <wiringSerial.h>
#include <errno.h>
#include <string.h>
#include <signal.h>

// 1. Please make sure /boot/config.txt has "enable_uart=1" set, this is to use the alternative UART, since main UART is used by Bluetooth by default
// 2. raspi-config should have serial option disabled
// 3. "gpio readall" should show ALT5 option for TX and RX

int main ()
{
 printf ("UART Test Programe\n") ;

 int fd;



 printf ("Pin mode Set\n") ;


 if ( (fd = serialOpen("/dev/serial0",9600)) < 0 )
 {
 fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno));
 return 1;
 }


 if ( wiringPiSetupGpio() == -1 )
 {
 fprintf (stdout, "Unable to start wiringPi: %s\n", strerror(errno));
 return -1;
 }

 printf("I SURVIVED11\n");
 

 int counter = 0;
 while(1)
 {
 serialPrintf(fd,"Hi=%5d\n",counter);
 counter++;
 delay(1000);
 }

}

 

GPIO in Rpi

 

 

> pigs mg (gpio number)

GPIO:22-27:  mode 0 – INPUT (means no one uses them)

GPIO48-53:  mode 4 – ALT0 (not documented, probably means SD0, ALT3 is SD1)

GPIO34-39: mode 7 – ALT3 (SD1 function, probably means Wifi BCM chip)

INPUT  0
OUTPUT 1
ALT0   4
ALT1   5
ALT2   6
ALT3   7
ALT4   3
ALT5   2

Installing Kelnel Object (v4l2loopback)

To mount .ko file using modprobe, one must have linux kernel headers:

/usr/src/linux-headers-x.x.xx+

ready.

Wrong Way to Install

Do not try to install, linux-headers-generic. It will gives the wrong kernel version.

Right Way to Install

> sudo apt install raspberrypi-kernel-headers

Do use

> uname -a
and
> sudo apt-cache policy []

to check the version of the kernel.

To find the corresponding kernel version of each raspberrypi-kernel-headers package, we can cross check with the github Makefile details, for example it is 4.4.38 in the link:

https://github.com/raspberrypi/linux/blob/raspberrypi-kernel_1.20161215-1/Makefile

DKMS Process

After headers are installed, they should be reflected as below:

screenshot-at-2017-02-27-18-50-43

Afterwards, install the kernel module (v4l2loopback) by simply:

> sudo apt-get install v4l2loopback-dkms

If successful, the following should be shown:

screenshot-at-2017-02-27-18-48-04

Finally, modprobe as usual and it should work now.

Gstreamer UDP H264 Streaming

Version Gstreamer 1.10.3

Transmister (Rpi 3)

sudo ionice -c 1 -n 0 nice -20 \
 /opt/gst-installed/bin/gst-launch-1.0 -e v4l2src num-buffers=8000 io-mode=1 blocksize=512 \
 ! video/x-raw, format=GRAY16_LE, width=640, height=512 , framerate=7/1 ! tee name=t ! queue \
 ! videorate ! videoconvert! video/x-raw, format=GRAY16_BE, framerate=1/1 ! pngenc \
 ! multifilesink async=1 location=${RECORD_DIR}/tau2pipe_${TIMESUBFIX}/tau_%05d.png t. ! queue \
 ! videoconvert ! video/x-raw, format=I420, width=640, height=512, framerate=7/1 \
 ! omxh264enc control-rate=variable target-bitrate=2500000 ! rtph264pay config-interval=3 pt=96 \
 ! udpsink port=(####) host=(***).local sync=false

 

Receiver (Windows)

Streaming onto Screen

gst-launch-1.0 -e -v udpsrc port=1235 ! application/x-rtp, payload=96 ! rtpjitterbuffer latency=300 ! rtph264depay ! avdec_h264 ! autovideosink

Streaming and Saving as FLV video

gst-launch-1.0 -v udpsrc port=1235 ! application/x-rtp, payload=96 ! rtpjitterbuffer drop-on-latency=true latency=200 ! rtph264depay  ! video/x-h264 , framerate=7/1 ! avdec_h264 ! video/x-raw , format=I420 , framerate=7/1 ! tee name=t ! queue ! autovideosink sync=false t. ! queue ! video/x-raw , format=I420 , framerate=7/1 ! avenc_flv ! flvmux ! filesink location=%FILELOC%\\Desktop\\Tau2Stream.flv sync=false