Software Tools for Firmware Development
This article introduces some software development tools for firmware development.
Code Editor
Visual Studio Code
Instead of vi
, highly recommended to use Visual Studio Code(VSC) as a firmware development IDE. First of all, just install
Visual Studio Code as a foundation of code editor then don't forget to install its Recommended extensions as following as well.
VSC Extensions
- Visual Studio Code Remote - SSH (Highly Recommended)
- C/C++ for Visual Studio Code (Highly Recommended)
- Visual Studio IntelliCode
- GitLens: easy to check git history and so on.
- Git Graph
- Trailing Space
- BookMark
- Bracket Pair Colorizer 2
- Indent one space
- XML (Red Hat)
- shell-format
- Peacock
- PlantUML
- ToDo Tree
- Live Share
VSC Extensions - C/C++ for Visual Studio Code
It's highly recommended to install C/C++ for Visual Studio Code
, it supports Coding Convention
, Source Code Tagging System
and so on.
max_user_watches
Please consider to enlarge max_user_watches
to 524288
also.
$ echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf
$ cat /proc/sys/fs/inotify/max_user_watches
$ sudo sysctl -p
There is Visual Studio Code Keyboard shortcuts for Windows and it userful shortcuts as following
Action | Visual Studio Code Keymap |
---|---|
Go Back / Forward | Alt+ ← / → |
Deleting tabs when using tabs as spaces | ⇧ Shift+⇥ Tab |
Switch to next Tab | Ctrl+⇥ Tab |
BookMark | CTRL+ALT + J/L |
Toggle BookMark | CTRL+ALT+K |
Use below command to open a file from the terminal in Visual Studio Code
$ code -r filename.c
Code Server
VSC also provides Web IDE called Code Server, use below command to install Code Server.
$ curl -fsSL https://code-server.dev/install.sh | sh
Its setting file is in ~/.config/code-server/config.yaml
. You can revise Bind-addr
and Password
to allow external access (user needs to run code-server to product this config file).
Bind-addr: 0.0.0.0:9786 # < = Use IP 0.0.0.0 and port 9786 to allow external access
Password: 11111111 # < = define your password, this case is 11111111
Now, you can run code server with below command.
$ code-server .
WSL2
By the way, if you use Windows 10 OS, this OS also provides WSL2 after Windows 10 Versions 1903 and 1909. Install Windows 10 and WSL 2 with Remote - WSL extension. You can develop your code in VSC via WSL2 also.
- Get started using Python for web development on Windows
- Install Node.js on Windows Subsystem for Linux (WSL2)
- Get started with C++ and C
Terminal Tools
- ZOC: SSH Client and Terminal Emulator for Windows and macOS.
- Xshell: The Industry's Most Powerful SSH Client.
- MobaXterm: Enhanced terminal for tabbed SSH client, network tools and so on.
Services
TFTP Server
There are some TFTP tools, most of all I use tftp64
beacuse my development environment is Windows 10.
- tftp64: for Windows OS, it includes tftp server, client and syslog server.
- tftpd-hpa (Optional): for Linux OS.
- TftpServer for Mac (Optional): for Mac OS.
HTTP File Server (Optional)
There is HTTP file server which can run in Windows OS.
- HFS Server: HTTP file server.
- LiteServe: Web, Mail, FTP, and Telnet server
Code Comparer
- Code Compare: a free compare tool designed to compare and merge differing files and folders.
Coding Convention
Suggest to use default coding configuration by clang-format
of Visual Studio Code.
- ClangFormat: the default formattering tool in VSC.
Below script format main.c
by clang-format
.
$ sudo apt-get install clang-format
$ clang-format -i main.c
- AStyle: code formatter for the C, C++, C++/CLI, Objective‑C, C# and Java.
Install astyle
and there is a case for coding convention as following to format main.c
or *.c
and *.h
files
style: K&R
, and Indent: 2
$ sudo apt-get install astyle
$ astyle --style=kr --indent=spaces=2 -p -U -f main.c
- OR -
$ astyle --style=kr --indent=spaces=2 -p -U -f *.c *.h
Below script can help use to fomat all *.c
, *.h
and java
files.
#!/bin/sh
echo "running this script for doing code convention"
astyle -V
# formate c code
for f in $(find ../ -name '*.c' -or -name '*.cpp' -or -name '*.h' -type f)
do
astyle --style=kr --indent=spaces=2 -p -U -f $f
done
# formate java code
for f in $(find ../ -name '*.java' -type f)
do
astyle --style=java --indent=spaces=2 -p -U -f $f
done
# after formate the code,we need to rm '*.orig' file
for f in $(find ../ -name '*.orig' -type f)
do
rm -rf $f
done
Source Code Tagging System
Use hostapd as an example, fetch the code and untar it.
$ wget https://w1.fi/releases/hostapd-2.9.tar.gz
$ tar xvf hostapd-2.9.tar.gz
$ cd hostapd-2.9
- CScope: a developer's tool for browsing source code.
$ sudo apt-get install exuberant-ctags cscope
$ ctags --version
$ cscope --version
$ find ./ -name "*.c" -or -name "*.h" -or -name "*.cpp" -or -name "*.S" | cscope -Rbq
# - OR -
$ cscope -R
- GNU Global: source code tagging system.
Install global
$ sudo apt-get install global
$ sudo ldconfig
$ global
Usage: global [-adEFGilMnNqrstTvx][-S dir][-e] pattern
global -c[dFiIMoOPrsT] prefix
global -f[adlnqrstvx][-L file-list][-S dir] files
global -g[aEGilMnoOqtvVx][-L file-list][-S dir][-e] pattern [files]
global -I[ailMnqtvx][-S dir][-e] pattern
global -P[aEGilMnoOqtvVx][-S dir][-e] pattern
global -p[qrv]
global -u[qv]
$ gtags --help
Usage: gtags [-ciIOqvw][-d tag-file][-f file][dbpath]
Options:
--accept-dotfiles
Accept files and directories whose names begin with a dot.
By default, gtags ignores them.
-c, --compact
Make GTAGS in compact format.
This option does not influence GRTAGS,
because that is always made in compact format.
--config[=name]
Print the value of config variable name.
If name is not specified then print all names and values.
In addition to the variables listed in the ENVIRONMENT section,
you can refer to install directories by read only variables:
bindir, libdir, datadir, localstatedir and sysconfdir.
...
in short, the usage of global
is
$ global (find definition of pattern)
$ global -r (find references of pattern)
$ global -x (shows the detail)
$ global -xg (locates the lines which have specified pattern)
Run gtags, make sure it products GPATH
, GRTAGS
and GTAGS
files.
$ gtags
$ ls
CONTRIBUTIONS COPYING GPATH GRTAGS GTAGS hostapd README src
Find definition of pattern
$ global eloop_sock
src/utils/eloop.c
src/utils/eloop_win.c
Update database.
$ global -u
product HTML file and copy to HTTP folder.
$ htags -ffnsa # < = w/. Searching
$ sudo cp -r HTML/ /var/www/html/hostapd
- Doxygen: Generate documentation from source code.
An example for hostapd
to generate Doxygen document
$ sudo apt-get install doxygen
$ sudo apt-get install graphviz
$ sudo ldconfig
# -- PRODUCT CONFIGURATION --
$ doxygen -g Doxygen
# -- REVISE CONFIGURATION --
# HAVE_DOT = YES
# CALL_GRAPH = YES
# CALLER_GRAPH = YES
# RECURSIVE = YES
# INLINE_SOURCE = YES
# --- RUN --
$ doxygen Doxygen
# -- MOVE TO HTTPD FILE FOLDER ---
# sudo mv html/ /var/www/html/hostapd
- (woboq)[https://code.woboq.org/]: Code Browser by Woboq for C & C++.
Searching Tools
- grep
Usage
$ grep -rsni eloop_register_read_sock *
- ack
Install
$ sudo apt-get install ack-grep
$ sudo ldconfig
Usage
$ ack eloop_register_read_sock
Code Analysis Tools
Static Code Analysis Tools
- clang-tidy: a clang-based C++ “linter” tool.
- CPPCheck: A tool for static C/C++ code analysis
Install
# - INSTALL -
$ sudo apt-get update -y; sudo apt-get install cppcheck
Running:
$ cppcheck -j 3 ~/Project # < = open 3 threads to check source code from Project folder,--enable==error by default
$ cppcheck -j 3 --enable=all ~/Project
$ cppcheck -j 3 --enable=all --xml 2>err.xml ./ # < = Get Report
- splint: a tool for statically checking C programs for security vulnerabilities and coding mistakes.
Install:
$ sudo apt-get update -y
$ sudo apt-get install -y splint
Example:
bounds1.c
#include <stdio.h>
int main(void)
{
int a[10];
a[10] =0;
return 0;
}
Running:
$ splint bounds1.c +bounds -varuse # bounds: check memory leak
Result:
Splint 3.1.2 --- 20 Feb 2018
bounds1.c: (in function main)
bounds1.c:7:2: Likely out-of-bounds store: a[10]
Unable to resolve constraint:
requires 9 >= 10
needed to satisfy precondition:
requires maxSet(a @ bounds1.c:7:2) >= 10
A memory write may write to an address beyond the allocated buffer. (Use
-likelyboundswrite to inhibit warning)
Finished checking --- 1 code warning
Resource:
Dynamic Code Analysis Tools
- Valgrind: an instrumentation framework for building dynamic analysis tools.
Terminal Multiplexer
- Tmux Terminal: a terminal multiplexer.
# - INSTALL -
$ sudo apt-get install tmux
# - USAGE -
$ tmux
# - RUN BELOW COMMANDS THEN EXIT -
$ ping 8.8.8.8
$ tmux deattach
# - RUN BELOW COMMAND TO ATTACH AGAIN -
$ tmux attach
- GNU Screen: a full-screen window manager that multiplexes a physical terminal.
Wi-Fi Tools
- InSSIDer 5: fast WiFi scanning, and packet capture capabilities.
- wifiinfoview: WiFi Scanner for Windows 10/7/8/Vista.
- airodump-ng: packet capturing of raw 802.11 frames.
- Wireshark/tshark: network protocol analyzer.
Web Debugging Proxy
- Fiddler: web Debugging Proxy and Troubleshooting Solutions.