Recent Posts Tutorials Embedded Electrical Electronics

U-Boot | How to add a new command to u-boot console?

U-boot comes with a lot of stock commands which one can run on the u-boot console similar to the Linux console commands like 'ls'. The source for every command can be found under 'common/' directory with file names starting with 'cmd_'. However, not all commands are enabled by default.

A user may either want to enable a command the stock or add his/her own command. Both are possible in just few simple steps.

Note: You can check the list of commands already enabled from the commands list from the u-boot console by running the command 'help' or simply '?'.

1. Enabling a command from the stock
From the code, you can open 'common/Makefile' and under the '# command' section you can find the list of all the commands masked with config flags 'CONFIG_*'. To enable a command, you have to simply #define the corresponding flag under the 'include/configs/<board>.h' file and build the source. Now, you can see the command in the list of commands by running 'help'.

Example:
To enable a command 'source', in the 'common/Makefile', you can find
obj-$(CONFIG_CMD_SOURCE) += cmd_source.o

Simply include the corresponding flag in 'include/configs/<board>.h' file as follows
#define CONFIG_CMD_SOURCE

or another in another ways, simply replace $(CONFIG_CMD_SOURCE) with 'y' as follows.
obj-y += cmd_source.o
will enable the command irrespective of any flags defined. However, the first method is most reliable and controllable from the board.h config file.

2. Adding and enabling a new command of your own
In this case, there are three things to be done.
  • Write an API(function) that implements your command.
  • Register your function to the command list.
  • Enable your command.
Write an API that implements your command: First thing is to write an API that implements your expected functionality. But, the API should follow a fixed prototype.

/* Prototype */
int do_funcname(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 
where,
*cmdtp - Command table pointer (comparable to function vector table)
flag - Unused
argc - Argument count, including command name itself
argv[] -  Array of arguments (string)

Register your API to the command table: Registering your command to the command table is necessary for both, listed and command-line arguments to be properly passed to your API.
U-Boot provides the following prototype to register your API.

/* Prototype */
U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help)
where,
_name - Command Name (the name you want to run the command)
_maxargs - Maximum number of arguments
_rep - Autorepeat allowed? (0-No/1-Yes)
_cmd - Implementation function (pointer to your API)
_usage - Usage - Short help message (string)
_help - Long help message (string)

Note: Both the above prototypes are available in 'include/command.h' and hence need to include 'command.h' to your command file header.

Enable your command: Finally, all set to have your own command except one last thing, enabling them. For that, you have to follow the same method as follow for the first case.
obj-y += <filename>.o
or have a new flag defined, say CONFIG_CMD_FILENAME and
obj-$(CONFIG_CMD_FILENAME) += <filename>.o


Reference:
1. doc/README.commands in u-boot source.
2. xillybus.com

What is a device tree blob? Why is it needed?

Since the time when a number of ARM sub-architectures are entering the ground, it's been a big headache to the maintainers of the Linux source as there were huge number of duplicates to support specific sub-architecture and board configurations making the Linux Mainline so big and clumsy. To avoid this, the team came up with an idea to keep the board specific files away from the Kernel mainline and thus the birth of Device Tree Source (.dts) files which will be compiled as separate binary, Device Tree Blob (.dtb). With device tree, it is possible to use a single kernel image on different boards using the same SoC by simply passing a different device tree containing board specific data structure.. When booting, it is the boot-loader which passes this device tree to the kernel. At present, it is made mandatory to have Device Tree. More story about device tree can be found at xillybus.com, elinux.org, freebsd.org and more. Also check this document.

ARM Bare Metal Programming with GNU

ARM bare metal programming was considered a dark art and known only to very few. Here are the links that opens it to you on how to write a startup code, linker script and all that is hidden behind your popular IDEs. With this knowledge, you can start to write your code without the help of any IDEs. You can completely take in control where to place each of your bits on the RAM. Enjoy exploring the core of embedded programming.

Embedded programming with the GNU toolchain - bravegnu.org
Building Bare-Metal ARM Systems with GNU - embedded.com
Building Bare-Metal ARM Systems with GNU - mikrocontroller.net

Articles on 'const' and 'volatile' qualifiers

More recently I went through some of the articles and lectures on C and C++ by Dan Saks, a consultant in US. I especially liked his lecture on 'const' qualifier which was more thought provoking and felt, a must share article. http://www.dansaks.com/articles.htm. Also, he is a columnist at embedded.com

Bringing Wi-Fi Access Point Feature on your embedded board running GNU/Linux

Before reading through this article, to build and install GNU/Linux on embedded board, read through this link.

To bring WiFi client feature on your embedded board, read through this link.
----

Follow these simple steps below to bring your board as AP.
  1. Install necessary tools
    Install hostapd and dnsmasq necessary for an Access Point.
    # apt-get install hostapd dnsmasq --no-install-recommends
  2. Configure network interface
    Add or modify /etc/network/interface to contain the following.
    # cat /etc/network/interface
    auto lo wlan0
    iface lo inet loopback
    allow-hotplug eth0
    iface eth0 inet dhcp
    
    iface wlan0 inet static
    address 192.168.1.1
    network 192.168.1.0
    netmask 255.255.255.0
    allow-hotplug wlan0
    The above file says how our system get connected through eth0, wlan0 and lo. Check man page of interfaces for more details.
  3. Configure hostapd
    # cat /etc/default/hostapd
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
    DAEMON_OPTS="-dd"
    # cat /etc/hostapd/hostapd.conf
    interface=wlan0
    driver=nl80211
    ssid=zilogic
    channel=1
  4. Configure dnsmasq with Client IP range
    # cat /etc/dnsmasq.conf
    
    interface=wlan0
    dhcp-range=192.168.1.10,192.168.1.100,12h
    dhcp-option=3,192.168.1.1
  5. Start hostapd and dnsmasq services.
    # service hostapd start
    # service dnsmasq start

Note: Now, you can try Raspberry Pi 3 that comes with WiFi and Bluetooth on-board for IoT applications.

More Reading

  1. What is the significance of firmware-atheros package?
  2. What is the significance of wireless-tools utility?
  3. What is iw and iwconfig? How do they differ?
  4. What is wpa_supplicant? How to connect to an encrypted connection?
  5. What is Wireless Extensions(WE)?
  6. What are nl80211 and cfg80211 and how do they differ from WE?
  7. What is Bridging in network connections? 

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates:

dgpride - Study Zone - Free Books - Tamil Lyrics

Copyright © 2008 -2012 dgpride. All rights reserved.

Subject/Topics

2 Marks (26) 8051 (1) AC Machines (7) Animations (1) Anna University Chennai (31) Arduino (4) ARM (3) Audio (1) Basic C Concepts (8) Basic Electronics (13) Basic principles (9) Book list (1) CAD (1) Chemical (2) Circuit theory (6) Civil (2) Cloud Computing (1) Communication (4) Competitive exams (2) Computer Architecture (4) Control system and components (9) CSE (40) Curriculum (4) DC Machines (9) Did you know (14) Digital (13) DLC (4) Documentation (1) DSP (1) EC 2201 (3) ECE (45) EDC (1) EEE (34) EIE (63) Electrical (35) Electronics (43) Electroplating (2) Emacs (1) Embedded basics (19) Embedded C Programming (19) Embedded Linux (5) Embedded System (22) Engineering basics (15) Environmental Science (1) Fibre Optics (1) Filters (2) FPGA (1) GATE (3) General (7) GNU (4) Handwritten (1) Hobbyist (15) How to (8) HTML (3) Humanities (2) IC Engines (7) ICE (5) Industrial Electronics (10) Industrial Instrumentatin (2) industrial process (2) Instrumentation (21) IoT (2) IT (2) Laboratory Manuals (17) LabVIEW (2) Lesson notes (2) LIC (2) Links (9) Linux (8) Magnetics (1) Management (1) Mechanical (5) Mechatronics (9) Microcontrollers (14) Microprocessors (9) Microsoft (1) Motivation (1) Must Know (11) Networks (1) NuttX (1) Objective type (1) Open Source (1) Opportunities (7) Oscillators (2) Part Time (1) Physics (1) Post Graduation (1) Power Electronics (12) Power Plant Engineering (2) Power Supplies (2) Previous GATE Papers (1) Process Control (2) Project (4) Protocol (1) R2008 (11) R2009 (1) R2013 (1) Recruitment (2) Research (2) Robotics (9) RTOS (3) Signal Processing (8) Signals and Systems (4) SMPS (1) Software tutorial (4) Stepper Motor (2) Syllabus (5) Texas Instruments (2) Thermodynamics (2) Training and Placement (6) Transducer Engineering (2) Transformer (2) Transmission (1) Tutorials (48) Two Marks (26) U-Boot (1) University Question Papers (16) Verilog (1) Video (4) Virtual Instrumentation (3) Visual Basic (21) VLSI (11) Web designing (4) Wi-Fi (3) Wireless (6)