JTAG and Linux Embedded Development

Homepage JTAG and Linux Embedded Development

A seemingly simple question on the best practices surrounding JTAG and Linux here at Witekio evolved/devolved into a heated discussion.

That’s nothing new when talking about a subject that has pros and cons – after all, it’s our job to know what’s best for our customer’s projects.

So we’ve turned this into blog, so you can make up your own mind on the JTAG and Linux-embedded development puzzle.

But first, let’s set up what you need to know….

What is JTAG?

If you work with embedded devices, the chances are you are familiar with JTAG. This grizzled old veteran has been helping engineers debug hardware for over 30 years.  

As software gets more complex, hardware must in turn follow. This makes debugging and testing even more important, and difficult.  

For those who may be new to JTAG debugging, this process was designed to help test printed circuit boards (PCBs) after the manufacturing process, without requiring cumbersome and expensive “bed of nail” testing equipment. This is important because it gives you low-level access to the registers, memory, and peripherals of a device with just a single JTAG interface.  

This tool allows developers to find and fix bugs, test features, program firmware, and analyze security. JTAG debugging can also be used to recover devices that are bricked or corrupted, by flashing a new firmware or bootloader. As embedded software experts, this is especially useful as JTAG debugging might be the only viable option for many embedded systems. We often work on embedded devices with minimal power draw and external connections. Part of what enables us to optimize low-level embedded devices so effectively is the way we utilize JTAG.  

Unlocking Hardware

We mentioned before that software complexity brings with it hardware complexity.

JTAG helps us to develop devices with highly customized hardware selections that aren’t otherwise covered by standardized debugging protocols.

For example, JTAG is invaluable during the hardware bring-up phase of embedded development, or when flashing firmware onto a microcontroller or embedded device. 

A simple boundary scan can verify the connectivity and functionality of multiple on-board components, giving you a comprehensive insight into these crucial areas. 

Linux and JTAG - the Dream Team

However, this bastion of bare metal programming can be used for much more than just testing PCBs and optimizing firmware. No, we don’t mean jailbreaking your dusty old Xbox 360. We are referring to everyone’s favorite pastime, Linux Kernel Debugging!  

While the Linux kernel is a versatile and powerful foundation for an embedded device, tailoring it to suit specific hardware requirements or adding custom features requires serious attention to detail and expertise. Kernel panics and crashes can emerge from codebase issues or driver conflicts, while poorly optimized interrupt service routines (ISRs) can significantly impact system performance, stability, and responsiveness. Digging around for the root cause of these issues eats up precious development time.  

This is where JTAG debugging steps in, offering a robust set of tools to tackle these intricate challenges and weed out any issues before your device setup is finalized. This is especially true when developing a custom BSP for your embedded device, as you will need to ensure proper kernel/hardware interaction, diagnose communication issues, and identify any vulnerabilities. 

Using the integrated kgdb tool, on the other hand, is less intrusive than JTAG debugging, but does not give you the same low-level access and so is less suitable for diagnosing hardware-related issues. If your focus is on embedded development or bare metal programming, then you will likely need to become familiar with JTAG debugging.  

How Witekio Does It

While there are many tools available, some of our engineers have found success using the Lauterbach hardware and software suite. At our Lyon office, for example, we’ve harnessed several Lauterbach hardware components to connect seamlessly with the boards under test via interfaces like JTAG and ETM.  

Complementing these hardware tools is the versatile Trace32 software, which empowers developers to execute software step by step, modify memory, tweak registers, and more. This level of control, akin to what we can achieve on microcontrollers, extends its utility beyond just the kernel, encompassing bootloaders, including the Secondary Program Loader (SPL).  

Given that we work with a (very) wide range of hardware components, it’s essential that our toolkit can cope with this diversity. TRACE32 supports a wide array of processors, including the likes of the i.MX family. We have also used these tools to debug older processors, such as the Texas Instrument AM3703 processor, a sibling to the one found in the original BeagleBoards from a decade ago.  

In a recent project, we revamped decade-old software to the latest U-Boot and kernel versions, and the JTAG probe integrated with Lauterbach proved invaluable for kernel debugging. 

So There Are No Problems Then?

As with any tool, there are upsides and drawbacks to using JTAG when developing an embedded product. The first word on most embedded developers’ lips will be “SECURITY!”  The presence of an open JTAG interface on an embedded product is like a big red bullseye for hackers and other ne’er-do-wells. The level of access JTAG gives you is a real double-edged sword, so it is much more likely that you will encounter it during pre-production before it is removed.   

Another fun aspect of JTAG debugging is its magical ability to sometimes throw up new problems during, or even thanks to, the debugging process. This could be due to interrupting real-time behavior, resource contention, or other timing issues. Never is this more true than when debugging a complex and multi-threaded custom Linux kernel. Proper planning and implementation can mitigate these mishaps, but it takes experience and technical expertise to do so reliably.

It's Ok to Ask for Help!

While a simple JTAG device isn’t the be-all and end-all of debugging, it is still an invaluable tool in embedded Linux system design and development.

Each project will come with its own requirements and intricacies, and so the toolbox needed to meet each challenge gets bigger and bigger.

Superlative firmware requires superlative development. Bringing in the right embedded experts can help build a long-lasting foundation for your project and there’s where Witekio can help.

Need help with your JTAG debugging?
On-Page Form
Patrick HADDAD - Copywriter
13 September 2023