Tuesday 3 April 2012

HowToUbootScriptcmd

U-boot is a very versatile universal opensource bootloader, a customized version of which is used in VT8500 and WM8505-based devices. It has a built-in mini-shell with some handy commands that can be accessed through a [[serial console]]. Alternatively, required command sequences to e.g. redefine boot parameters and load a custom OS (like the Linux kernel) can be put into a so-called scriptcmd file. This is basically just a plain text script for the U-boot’s shell with just some binary header added to it.
The useful fact is that by default VT8500/WM8505 versions of U-boot will happily execute a scriptcmd file put into a script/ folder on the first partition (FAT) of an SD card, which allows for a simple and non-destructive redefinition of the boot sequence.
Below are the simple steps to take to create your own scriptcmd file (assuming that you have the mkimage program from U-boot tools package installed already).
  • Create a plain text file with the commands you need and call it, for example, script.txt. In the simplest case its contents may be something like this:
setenv bootargs rootwait root=/dev/sda1
fatload mmc 0 0 /script/uImage
bootm 0
The first statement redefines the kernel command line to allow the first partition on a USB drive (/dev/sda1) to be used as a root filesystem. The second one loads /script/uImage from the first partition of the SD card to a memory address 0. The third one executes the Linux kernel uImage that we've just loaded into memory.
  • Generate the final scriptcmd file (the one with a binary header) by issuing a command like this:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n “My scriptcmd” -d script.txt scriptcmd
  • Put the scriptcmd file together with your kernel uImage to a script/ folder on the first (FAT) partition on an SD card and turn your device on with this card inserted. If everything is OK, your kernel should boot up.

Pthread Example


Set up Ubuntu to use static ip address

 had bit problem when using tftp server to boot NGW100, every time DHCP tend to find a different ip address for my PC, which is not what I wanted;I don’t want to change NGW100 boot args everytime to use different TFTP server or NFS server.
Here is what I do:
If Your Ubuntu System has set to use DHCP, you will want to change it to a static IP address here is simple tip
open the /etc/network/interfaces file.
sudo vi /etc/network/interfaces
If you are using DHCP for your primary network card which is usually eth0, you will see the following lines
auto eth0
iface eth0 inet dhcp
As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should add and here is the example and you can change these settings according to your network settings.
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Restart the neworking service using the following command
sudo /etc/init.d/networking restart
My interfaces file like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
        address 192.168.1.59
        netmask 255.255.255.0
        broadcast 192.168.1.255
        network 192.168.1.0
        gateway 192.168.1.2

PThread example
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    void *print_message_function( void *ptr );
    main()
    {
         pthread_t thread1, thread2;
         char *message1 = “Thread 1″;
         char *message2 = “Thread 2″;
         int  iret1, iret2;
        /* Create independent threads each of which will execute function */
         iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
         iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
         /* Wait till threads are complete before main continues. Unless we  */
         /* wait we run the risk of executing an exit which will terminate   */
         /* the process and all threads before the threads have completed.   */
         pthread_join( thread1, NULL);
         pthread_join( thread2, NULL);
         printf(“Thread 1 returns: %d “,iret1);
         printf(“Thread 2 returns: %d “,iret2);
         exit(0);
    }
    void *print_message_function( void *ptr )
    {
         char *message;
         message = (char *) ptr;
         printf(“%s “, message);
    }