Archives for April, 2010

28
Apr

Command to Reduce File Size of Installed Kernel Modules

I mentioned the objcopy command earlier, but I had recently put it into effect myself by shaving off quite a bit of bulk from Linux kernel modules targeted towards an embedded system and I wanted to share my steps and commands with you.

  1. Step 1: Compile your kernel and install the modules
  2. make; make modules_install
  3. Step 2: Change to the directory in which you installed your kernel modules
  4. cd /lib/modules/2.6.24.4/kernel/drivers
  5. Step 3: Run the following command which will find all files ending in .ko and pipe it to run the objcopy command (note, the following shows an example of using cross compile tools targeted towards ARM)
  6. find . -type f -name '*.ko' | xargs -n 1 /myfiles/tscrosstool/crosstool-linux-arm-uclibc-3.4.6/arm-uclibc-3.4.6/bin/arm-linux-objcopy --strip-unneeded
    

That’s it. You’ll notice that your kernel module sizes are now very small compared to what they used to be, and this allows you to squeeze in more features in your embedded system and possibly leave even more free space for your programs or files.

27
Apr

A Great, Simple, Quick Serial Port Test Program for Linux

For any of you out there who would like to learn about serial programming or are in need of a simple serial program for testing, I would recommend checking out the one from “Captains Universe” here:
http://www.captain.at/howto-simple-serial-port-test-example.php

It’s easy to understand, modify, and compile and I think it’s a valuable tool in any programmers or embedded Linux users arsenal.

26
Apr

Delete Lines Matching a Pattern or Line Number with ‘sed’

I had a unique situation where I wanted to remove a line that contained “PRINT” in a batch of HTML pages. To do it quickly, I used the sed command:

sed -i '/PRINT/d' *.htm

The -i option tells sed to edit the file in place so I wouldn’t have to play pipe games. The '/PRINT/d' argument tells sed to look for the text PRINT and then delete the line that contains it. Keep in mind that this will work on the entire document, not only the first item it finds. So, be sure this is what you want. Test the waters first, especially if you’re working with a batch job where this is going to edit many files at once.

Another possibility was to delete only the particular line number that this pattern occurred on:

# First, use grep to find the line it occurs on
grep -n "PRINT" *.html
# Then, use sed to delete that particular line (ie. line 16)
sed -i '16 d'

There are a lot more sed tricks here, so be sure to check it out.

23
Apr

Shell Script While Loop to Wait for a File to Appear or Else Timeout

The following shell script snippit will continually check and wait for the presence of a file until it is found, or until it reaches a timeout period, which in this case, is about 10 seconds, whichever come first.

#/bin/sh

x=0
while [ "$x" -lt 100 -a ! -e /path/to/the/file_name ]; do
        x=$((x+1))
        sleep .1
done

This can be helpful to prevent a race condition in a script if you’re say, mounting a filesystem from an external device. You could take it a step further and print useful messages as well:

#/bin/sh
$FILE="/path/to/the/file_name"
x=0
while [ "$x" -lt 100 -a ! -e $FILE ]; do
   x=$((x+1))
   sleep .1
done
if [ -e $FILE ]
then
   echo "Found: $FILE"
else
   echo "File $FILE not found within time limit!"
fi

Another, maybe more elegant, solution is to use the wait command:

wait [pid]...

Wait for your background process whose process ID is pid and report its termination status. If pid is omitted, all your shell’s currently active background processes are waited for and the return code will be 0. The wait utility accepts a job identifier, when Job Control is enabled (jsh), and the argument, jobid, is preceded by a percent sign (%).

If pid is not an active process ID, the wait utility will return immediately and the return code will be 0.

22
Apr

Time Tracking and Profiling Your Program with gprof

Until today, I had only heard of the time program to track how much time a program took to execute entirely. This is useful to see if there are any optimizations that can be made to make the program run quicker, but it doesn’t help troubleshoot or debug a program very easily since it only tracks the entry and exit of the program being ran. Another utility that allows you to track time in a more detailed manner is called gprof. Here’s a quote from the CS department of Utah School of Computing (link) explaining it in more detail:

Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing. This information can show you which pieces of your program are slower than you expected, and might be candidates for rewriting to make your program execute faster. It can also tell you which functions are being called more or less often than you expected. This may help you spot bugs that had otherwise been unnoticed.

Be sure to check out the man pages and other many guides out there that explain how to use it (no need for me to reinvent the wheel).

21
Apr

Set Linux Terminal Console Column Width

A quick trick I learned today was how to set the column width for a terminal console with stty. This way, the shell acts a bit more normal.

stty cols 80

A snippit from the stty man page reveals some more information and tricks:

* cols N
	      tell the kernel that the terminal has N columns
* rows N
	      tell the kernel that the terminal has N rows
* size print the number of rows and columns according to the kernel

I didn’t realize how useful this program was! Certainly worth taking a deeper look into if your always consoled into your embedded Linux system.

20
Apr

A Script to Make Use of the “About Me” System Preference Utility

The Linux distributions, such as Fedora or Ubuntu who ship the Gnome desktop environment, include a utility in the “System -> Preferences” menu called “About Me”. This fun little utility allows you to enter in all of your personal and/or work information and also allows you to pick a cute avatar icon which is shown when you login. Beyond setting an avatar icon, I haven’t found much use in it or seen any benefits that it provides. I remember reading a post about it on the Ubuntu forums a while back which asked people if they use it. The response was that nobody used it except to set their login icon. While thinking about this, I figured I would recommend a use for the “About Me” utility: setup a signature script for Evolution. Please feel free to use this as your own starting point. I included some of the basics of what I may want in a signature, but if you need more, it’s not hard to add it. The following script parses out the information from the binary file that’s created within the hidden .evolution home folder and displays the information. You can even choose between “work” or “home” information shown. Enjoy! Oh, and I’d love to hear how else the “About Me” utility can be used, so drop a comment below…

#!/bin/sh

## SELECT TYPE OF SIGNATURE
TYPE=WORK
#TYPE=HOME

## SETUP $ABOUT FILE AND FULLNAME
ABOUT="$HOME/.evolution/addressbook/local/system/addressbook.db"
FULLNAME=`finger `whoami` | grep "Name:" | cut -d : -f 3 | sed 's/^.//'`

## PARSING $ABOUT FILE
ORG=`grep -a "ORG:" $ABOUT | cut -d : -f 2 | cut -d ";" -f 1`
ORG_WITH_DEPART=`grep -a "ORG:" $ABOUT | cut -d : -f 2`
TITLE=`grep -a "TITLE" $ABOUT | cut -d : -f 2`
ROLE=`grep -a "ROLE" $ABOUT | cut -d : -f 2`
MANAGER=`grep -a "X-EVOLUTION-MANAGER" $ABOUT | cut -d : -f 2`
ASSISTANT=`grep -a "X-EVOLUTION-ASSISTANT" $ABOUT | cut -d : -f 2`
EMAIL=`grep -a "EMAIL;TYPE=$TYPE" $ABOUT | cut -d : -f 2`
JABBER_IM=`grep -a "X-JABBER;TYPE=HOME" $ABOUT | cut -d : -f 2`
#FIXME: A grep for "URL" matches two URLs (Blog and Homepage)
WEBSITES=`grep -a "URL:http" $ABOUT | cut -d : -f 2,3`
PHONE=`grep -a "TEL;TYPE=$TYPE,VOICE" $ABOUT | cut -d : -f 2`
CELLPHONE=`grep -a "TEL;TYPE=CELL" $ABOUT | cut -d : -f 2`
STREET=`grep -a "ADR;TYPE=$TYPE:" $ABOUT | cut -d ";" -f 4`
CITY=`grep -a "ADR;TYPE=$TYPE:" $ABOUT | cut -d ";" -f 5`
STATE=`grep -a "ADR;TYPE=$TYPE:" $ABOUT | cut -d ";" -f 6`
ZIP=`grep -a "ADR;TYPE=$TYPE:" $ABOUT | cut -d ";" -f 7`

## BEGIN SIGNATURE
# Evolution expects signature in HTML format, so surround block with
# <p>aragraph markings and all newlines need <br />
echo " <br /><p>"
echo "Best Regards, <br />"
echo "<br />"
echo "$FULLNAME <br />"
echo "$TITLE <br />"
echo "$ROLE <br />"
echo "$MANAGER <br />"
echo "$ASSISTANT <br />"
echo "$ORG <br />"
echo "$EMAIL <br />"
echo "$JABBER_IM <br />"
echo "$WEBSITES <br />"
echo "$STREET <br />"
echo "$CITY, $STATE $ZIP <br />"
echo "$PHONE <br />"
echo "$CELLPHONE <br />"
echo "</p>"

What you’ll see after saving this to a script, giving it executable rights (chmod +x about_me_sig), and then running it:


Best Regards,

My Full Name
My Title
My Role
My Manager
My Assistant
My Organization
My Email
My Jabber
My Website
My Street Name
My City, My State, My ZIP
My Phone
My Cellphone

If you don’t know how to integrate this with Evolution, please see my other step-by-step guide here:
Generate Random Quotes with a Shell Script [Part 3/3: Integrate with Evolution Email].

Also, you could take it a step further and install the fortune program to give a random quote as well.

Another thought was to use the above script to populate the .plan file which is shown when your username is invoked with the finger command. For this, you would need to setup the script a bit differently and experiment with newlines and what-not as well as setup a cron job to make sure that it’s updated regularly for when you update the “About Me” information. To test it out, simply run the commands below (the above script has been named “about_me_sig”):

./about_me_sig > .plan
finger `whoami`

Have fun!

19
Apr

Fedora 13 Goddard on MacBook Aluminum 5,1 [Guide]

Update: May 25, 2010 — I was able to take some time to verify the following steps to installing Fedora 13 Final on MacBook Aluminum 5,1. Enjoy!

This is my guide to getting Fedora 13 Goddard running on a MacBook Aluminium 5,1 (I believe this should work on more recent generations as well because the only difference was the addition of the SD card slot and Firewire port). As with Fedora 12, there were many things that worked out of the box. I have created this guide to help others get Fedora 13 installed on their MacBook Aluminum.
[Read more →]

16
Apr

Fedora 13 Beta on MacBook Aluminum 5,1 Coming Monday….

Update: I have written it and scheduled it for Monday. It’ll show up here for those of you who are impatient.

Hello All,

I just wanted to let you know that I’m skipping a day so I can start working on getting a semi-formal review for how Fedora 13 runs on the MacBook Aluminum for Monday. See ya’ll then!

-Derek

PS. For those of you wanting to play along, you’ll need to add the following line to the end of the bootup options (press Tab on the main boot screen):
updates=http://people.fedoraproject.org/~jwrdegoede/updates-572488
(via bugzilla.redhat.com)

15
Apr

The First Linux Announcement from Linus Torvalds

Here’s the very first announcement from Linux Torvalds revealing an operating system called Linux that won’t be “big and professional like gnu” (see the mailing list thread here):

From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Message-ID: <1991Aug25.205708.9541@klaava.Helsinki.FI>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki

Hello everybody out there using minix -

I’m doing a (free) operating system (just a hobby, won’t be big and
professional like gnu) for 386(486) AT clones. This has been brewing
since april, and is starting to get ready. I’d like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system (due to practical reasons)
among other things).

I’ve currently ported bash(1.08) and gcc(1.40), and things seem to work.
This implies that I’ll get something practical within a few months, and
I’d like to know what features most people would want. Any suggestions
are welcome, but I won’t promise I’ll implement them :-)

Linus (torvalds@kruuna.helsinki.fi)

PS. Yes – it’s free of any minix code, and it has a multi-threaded fs.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks, as that’s all I have :-( .

It’s strange to think that it’s been around that long now. Windows was released in 1985 and Mac OS in 1984. I wonder what 6 or 7 more years will do for Linux and the various desktop environments…

via http://www.linux.org/people/linus_post.html (bandwidth has been exceeded, see cached page here instead).

Next Page »