Posts

Linux Dynamic Debugging

Image
In Linux programming, it is very important to debug your code by adding some debug messages to your code. By using the dynamic debug feature of Linux, you can enable these debug messages per file, per function and even per line.  This post will show you how to do this with a simple kernel loadable module implementation. First, you need compile your kernel with the CONFIG_DYNAMIC_DEBUG option. It is under " Kernel hacking " menu and prompt name is " E nable dynamic printk() support " as you see on the below screenshot. Sample Code: TBD Enable/Disable dynamic debug in the sample code: TBD

Linux Debugfs implementation as a userspace interface

debugfs is a Linux file system. It is a user space interface to and from the Linux kernel. It is mounted at /sys/kernel/debug.  The kernel must be compiled with the   CONFIG_DEBUG_FS option to use this file system. It exists in the Linux kernel since version 2.6.10-rc3 [1] In the below example, you will see an example to a debugfs. A 32-bit flag is created under the /sys/kernel/debug/debugfs_ex directory called enable for read and write. debugfs_ex.c #include <linux/version.h> #include <linux/module.h> #include <linux/debugfs.h> static struct dentry * dn; /* Dentry object for debugfs directory */ static int enable; /* Enable flag for debugfs_ex module */ /* * debugfs_ex_init() */ static int __init debugfs_ex_init ( void ) { printk(KERN_INFO "debugfs_ex init \n " ); dn = debugfs_create_dir( "debugfs_ex" , NULL ); if ( ! dn) { printk(KERN_ERR "Failed to create debugfs_ex directory in debugfs \n " ); ...

A simple Stack implementation: push, pop, print_stack

In this source code, a simple stack is implemented.  A single array is used to implement 3 stacks.  Let's say we have an array with a size of 300. It consists of 3 stacks concatenated to each other. The user can add/remove elements from each stack by passing the stack number as a parameter to the push/pop functions.  Usage: push(s, 12, 1); // Pushes element 12 to the stack number 1. push(s, 2, 3); // Pushes element 42 to the stack number 3. pop(s, 3); // Pops an element from the stack number 3. Source Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define NUM_OF_STACK 3 #define STACK_SIZE 10 /* * stack data structure */ struct stack { int array[STACK_SIZE * NUM_OF_STACK]; int size[NUM_OF_STACK]; }; /* * print_stack() * Prints the stack */ void print_stack ( struct stack * s) { int i; for (i = 0 ; i < STACK_SIZE; i ++ ) { printf( "%d " , s -> array[i]...

Raspberry Pi VNC Server installation

Image
I assume that you have configured your Pi's network interface and already connected to the Internet. You also have the console access to the board through the USB to TTL serial cable . First you need to install a VNC server. We will use the tightVNC server. $ sudo apt-get install tightvncserver Then you will run the server first time to configure a password and optional view only password. $ tightvncserver Now you can start the VNC server with the below command and it will run as a background process. $ vncserver :0 -geometry 1280x800 -depth 24 -dpi 96 From a PC in the same network, you can use a VNC client and connect to your Raspberry Pi board by using its IP address and entering the password that you have configured on the board. Here is a snapshot of my Raspberry Pi desktop from my MAC book VNC client.

Raspberry Pi wireless connection

If you are booting your raspberry pi first time and connecting to the boards console through a USB to TTL serial cable , you can configure the wireless interface of your board to connect it to your home wireless router which has a WPA wireless security mode enabled. $sudo vi /etc/network/interfaces #Then edit the file as below. auto lo iface lo inet loopback iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp    wpa-scan-ssid 1    wpa-ap-scan 1    wpa-key-mgmt WPA-PSK    wpa-proto RSN WPA    wpa-pairwise CCMP TKIP    wpa-group CCMP TKIP    wpa-ssid "<YOUR WIRELESS NETWORK SSID>"    wpa-psk "<YOUR WIRELESS NETWORK PASSWORD>" iface default inet dhcp $sudo /etc/init.d/networking restart After a few seconds your wireless interface will get an IP address from your home network's DHCP server. You can see the IP address with the...

TFTP server for u-boot on Ubuntu

Install the required packages. $ sudo apt-get install xinetd tftpd-hpa tftp Create the /etc/xinetd.d/tftp file with the following content. service tftp { protocol = udp socket_type = dgram wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot -c disable = no } Create /tftpboot directory. $ sudo mkdir /tftpboot $ sudo chmod -R 777 /tftpboot $ sudo chown -R nobody /tftpboot Modify the /etc/default/tftpd-hpa file as below. # /etc/default/tftpd-hpa TFTP_USERNAME="nobody" TFTP_DIRECTORY="/tftpboot" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="--secure" Start tftp with xinetd $ sudo /etc/init.d/xinetd start Configure your server's IP address with the serverip environment variable in your u-boot configuratio...

Increase yank buffer size of your vi editor

If you think that your vi editor's yank buffer size is not enough, you can increase it with the following vi command. :set  v iminf o='1000,h This command will increase the buffer size to 1000 lines. .