<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shubham Gupta on Medium]]></title>
        <description><![CDATA[Stories by Shubham Gupta on Medium]]></description>
        <link>https://medium.com/@shubhamgupta577?source=rss-04b99420b7fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XbZM8PrqJTP4Mgt-</url>
            <title>Stories by Shubham Gupta on Medium</title>
            <link>https://medium.com/@shubhamgupta577?source=rss-04b99420b7fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:51:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shubhamgupta577/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Custom Embedded Linux From Scratch( Phase 5): Integration, Deployment, and Booting the BeagleBone…]]></title>
            <link>https://shubhamgupta577.medium.com/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a?source=rss-04b99420b7fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb35d998566a</guid>
            <category><![CDATA[buildroot]]></category>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[embedded-linux]]></category>
            <category><![CDATA[u-boot]]></category>
            <category><![CDATA[beaglebone-black]]></category>
            <dc:creator><![CDATA[Shubham Gupta]]></dc:creator>
            <pubDate>Thu, 05 Mar 2026 11:02:13 GMT</pubDate>
            <atom:updated>2026-03-05T11:02:13.258Z</atom:updated>
            <content:encoded><![CDATA[<h3>Custom Embedded Linux From Scratch( Phase 5): Integration, Deployment, and Booting the BeagleBone Black</h3><pre>Custom Embedded Linux for BeagleBone Black — Article Series<br><br>Toolchain → U-Boot → Kernel → RootFS → Booting<br>   ✓         ✓        ✓          ✓      ★</pre><p>Over the previous phases of this series, we built each component required to create a fully custom embedded Linux system for the BeagleBone Black:</p><h4><strong>Phase 1:</strong> A cross-compilation toolchain:</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Custom Embedded Linux(Phase-1): Building cross compilation toolchain(Crosstool-ng) for BeagleBone</a></p><h4><strong>Phase 2:</strong> The U-Boot bootloader:</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6">Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black</a></p><h4><strong>Phase 3:</strong> The Linux kernel and Device Tree:</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315">Custom Embedded Linux Phase 3: Building Kernel for the BeagleBone Black</a></p><h4><strong>Phase 4:</strong> The Buildroot-generated Root Filesystem (RootFS):</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d">Custom Embedded Linux Phase 4: Constructing the Root Filesystem with Buildroot</a></p><p>At this point we have all the pieces required to run a complete operating system:</p><ul><li><strong>MLO</strong> → First stage bootloader</li><li><strong>U-Boot</strong> → Main bootloader</li><li><strong>Linux Kernel (zImage)</strong> → Core of the OS</li><li><strong>Device Tree (.dtb)</strong> → Hardware map</li><li><strong>Root Filesystem (RootFS)</strong> → User space environment</li></ul><p>But these components are still just files sitting on our development machine.</p><p>To transform them into a <strong>bootable embedded system</strong>, they must be assembled, structured, and deployed onto physical storage in a format the BeagleBone Black can understand.</p><p>By the end of this phase, our custom firmware stack will move <strong>from source code to a running Linux system on the BeagleBone Black</strong>.</p><h4>What You Will Learn</h4><p>In this article we will cover:</p><ul><li>Understanding the <strong>AM335x boot sequence</strong></li><li>Partitioning an SD card for embedded Linux</li><li>Deploying bootloader, kernel, and root filesystem</li><li>Configuring <strong>U-Boot boot instructions</strong></li><li>Booting and debugging the system via serial console</li></ul><p><strong>Now that every component of the system has been built, it is time to assemble them and bring the BeagleBone Black to life.</strong></p><p>In this final phase, we will <strong>assemble these pieces onto an SD card</strong>, configure the boot process, and <strong>bring our custom Linux system to life on the BeagleBone Black</strong>.</p><h3>1. Understanding the Boot Flow</h3><p>Before copying files, it is important to understand <strong>what actually happens when the board powers on</strong>.</p><p>The boot sequence on the AM335x processor follows a strict order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxIWJk-I-4v-bqSYP563fA.png" /></figure><p>Each stage prepares the system for the next one. If <strong>any single component is missing or misconfigured</strong>, the board will fail to boot.</p><h3>2. The Architectural Layout: Partitioning the SD Card</h3><p>Embedded Linux rarely dumps every file into a single folder. To manage the different stages of the boot process, it uses distinct partitions to separate the bootloader, the kernel, and the userspace.</p><p>While many default setups use a 2-partition layout, we are using a highly modular <strong>3-partition layout</strong>:</p><p>To manipulate block devices (like your SD card), you will need administrative privileges (sudo) on your host machine. You can use utilities like fdisk or gparted(GUI based)to destroy the existing partition table and create three new primary partitions</p><h4>2.1 Preparing the SD Card</h4><p>The BeagleBone Black ROM bootloader expects a <strong>specific partition layout</strong>.</p><p>We will create three partitions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49da70d8f7f8030871709605d37894fa/href">https://medium.com/media/49da70d8f7f8030871709605d37894fa/href</a></iframe><p>Insert the SD card and identify its device name:</p><pre>lsblk<br>#Assume the card appears as <br>/dev/sdb<br><br><br>#Now start the partitioning tool:<br>sudo fdisk /dev/sdb<br></pre><p>Create three partitions as per the table above</p><blockquote>Note: Ensure the <strong>BOOT flag</strong> is enabled in first partition where MLO and UBoot lives</blockquote><p>Write the partition table and exit.</p><h4>2.2 Formatting the Partitions</h4><p>Now we format all partitions.</p><p>Boot partition:</p><pre># Boot partition<br>sudo mkfs.vfat /dev/sdb1<br># Kernel partition<br>sudo mkfs.ext4 /dev/sdb2<br># RootFS partition<br>sudo mkfs.ext4 /dev/sdb3</pre><h4>2.3 Mount the Partitions</h4><p>Create temporary mount points.</p><pre># Create temporary mount points.<br>mkdir boot<br>mkdir kernel<br>mkdir rootfs<br><br># Mount them<br>sudo mount /dev/sdb1 boot<br>sudo mount /dev/sdb2 kernel<br>sudo mount /dev/sdb3 rootfs</pre><p>Now the SD card is ready to receive our firmware.</p><h4>2.4 Copy the Components</h4><p>From previous phases, we already built:</p><pre>MLO<br>u-boot.img<br>zImage<br>am335x-boneblack.dtb<br>rootfs.tar.xz</pre><p>First copy the <strong>bootloader and kernel files</strong> to the partitions.</p><pre>cp MLO boot/<br>cp u-boot.img boot/<br><br>sudo cp zImage kernel/<br>sudo cp am335x-boneblack.dtb kernel/<br><br>sudo tar -xvJf rootfs.tar.xz -C rootfs/</pre><p><em>Question:</em> Why did copying to the BOOT partition work fine without sudo, but copying to the KERNEL partition required it?</p><p><em>Answer:</em> FAT32 does not support Linux permissions (owners/groups), so the OS mounts it with default user access. Ext4 <em>does</em> support permissions, and because the mount point is owned by root, it requires sudo to write to it.</p><p>(Note: You may notice a lost+found folder appear in Partitions 2 and 3. This is a standard feature of ext4 filesystems used for file recovery, which does not exist on FAT32.)</p><blockquote>⚠️ Important rule: <strong>MLO must be the first file copied to the FAT partition.</strong></blockquote><blockquote>The ROM bootloader reads the filesystem in order.</blockquote><h3>3. The Instruction Manual: Decoding uEnv.txt</h3><p>The default U-Boot configuration often assumes a 2-partition setup. Because we built a 3-partition system, if we let U-Boot run automatically, it will look for the Kernel in the wrong place and fail.</p><p>We must manually tell U-Boot where to look by creating a uEnv.txt file in the BOOT partition.</p><p>Here is what the configuration logic looks like:</p><pre>console=ttyS0,115200n8<br><br>loadaddr=0x82000000<br>fdtaddr=0x88000000<br><br>loadkernel=ext4load mmc 0:2 ${loadaddr} /zImage<br>loadfdt=ext4load mmc 0:2 ${fdtaddr} /am335x-boneblack.dtb<br><br>setbootargs=setenv bootargs console=${console} root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait<br><br>uenvcmd=echo Custom 3-Partition Boot; run setbootargs; run loadkernel; run loadfdt; bootz ${loadaddr} - ${fdtaddr}</pre><ul><li><strong>Pointer 1 (The Kernel):</strong> The load mmc 0:2 command changes the boot partition source to Partition 2 (0:2), instructing U-Boot to pull the zImage and .dtb from there.</li><li><strong>Pointer 2 (The RootFS):</strong> The bootargs variable includes root=/dev/mmcblk0p3. This tells the Linux kernel that once it takes over, it should mount the third partition as its root directory.</li><li><strong>The Debug Tip:</strong> We added a custom echo message (echo &quot;Custom Boot Starting&quot;) to verify on the serial console that our specific configuration is actually being loaded.</li></ul><h3>4. Booting the BeagleBone Black</h3><h4>4.1 Unmount the SD Card</h4><p>Once everything is copied, unmount all partitions.</p><pre>sudo umount boot<br>sudo umount kernel<br>sudo umount rootfs</pre><p>Your SD card now contains a <strong>complete embedded Linux system</strong>.</p><p>If you plug this SD card into your BeagleBone Black, hold the boot button, and apply power, you will watch your serial console light up. U-Boot will pass the baton to your Kernel, your Kernel will parse your Device Tree, and your Root Filesystem will launch your BusyBox environment.</p><p>If everything is correct, you should see something similar to:</p><pre>U-Boot 2025.xx<br>Loading kernel...<br>Starting kernel...</pre><p>After a few seconds:</p><pre>Welcome to Buildroot<br>buildroot login:</pre><p>Congratulations — your custom Linux system is now running.</p><h3>5. Debugging Boot Failures</h3><p>Boot failures are common in embedded development. Here are the most frequent problems.</p><h4>Kernel Panic: Unable to mount rootfs</h4><p><strong>Cause:</strong> root=/dev/mmcblkop2 incorrect</p><p><strong>Fix: </strong>Ensure the root filesystem partition number is correct.</p><h4>Board stops at U-Boot</h4><p><strong>Cause: </strong>Kernel or DTB file missing.</p><p><strong>Fix: </strong>Verify files exist in the boot partition.</p><h4>No serial output</h4><p><strong>Cause: </strong>Wrong console device.</p><p><strong>Fix: </strong>console=ttyS0, 115200</p><blockquote><strong>Pro Tip: </strong>If the BeagleBone <strong>fails to boot from SD card</strong>, verify that MLO was copied first. The AM335x ROM loader reads the FAT filesystem sequentially and expects the first-stage bootloader to appear early in the directory structure.</blockquote><h3>6. The Security Perspective: Connecting the Dots for Pentesting</h3><p>Since this series is geared towards Firmware Pentesting, understanding this physical deployment phase is arguably the most important lesson.</p><p>When you dump a real firmware image from a commercial IoT router or camera using a tool like binwalk, you will often see this exact structure: a FAT header (bootloader) followed by SquashFS or Ext4 sections (Kernel/RootFS).</p><p>Because you built this structure by hand, you now know exactly how to attack it:</p><ul><li><strong>Persistence:</strong> If an attacker gains write access to Partition 2, they can replace the zImage with a malicious kernel, allowing persistent control over the device even after firmware resets.</li><li><strong>Config Injection:</strong> If you can write to Partition 1, you can edit uEnv.txt to change the boot arguments. By simply adding init=/bin/sh, you can force the kernel to bypass all login prompts and drop you into a root shell.</li></ul><h3>7. Conclusion: From Source Code to Running Linux</h3><p>In this series, we constructed an entire embedded Linux system step-by-step.</p><p>We learned how to:</p><ul><li>Build a <strong>cross-compilation toolchain</strong></li><li>Compile the <strong>U-Boot bootloader</strong></li><li>Configure and build the <strong>Linux Kernel</strong></li><li>Generate a <strong>Root Filesystem with Buildroot</strong></li><li>Assemble everything and <strong>boot the BeagleBone Black</strong></li></ul><p>This process reveals something important about embedded systems:</p><p>The operating system is not a single program — it is a <strong>carefully orchestrated chain of components</strong>, each responsible for preparing the system for the next stage.</p><p>Understanding this chain is what separates someone who simply uses embedded Linux from someone who <strong>truly understands how it works</strong>.</p><h4>The Full System Architecture</h4><p>At the end of this series, we now understand every layer of an embedded Linux system. Have a look at it as a relay race</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zxdlj2_9ytMhm-_QiSmaFw.png" /></figure><p>But by building everything manually, we now understand <strong>how each component depends on the others</strong>.</p><p>If you are joining this article directly, you can start from the beginning of the series.</p><p><strong>1️⃣</strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong> Phase 1 — Toolchain Setup<br></strong></a><strong>2️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2 — Compiling U-Boot</strong></a><strong><br>3️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3 — Building the Linux Kernel</strong></a><strong><br>4️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4 — Constructing the Root Filesystem</strong></a><strong><br>5️⃣ Phase 5 — Integration and Booting the System</strong></p><h4><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d">◀<strong>Previous article</strong> — RootFS using Buildroot</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb35d998566a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Embedded Linux Phase 4: Constructing the Root Filesystem with Buildroot]]></title>
            <link>https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d?source=rss-04b99420b7fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/45018165554d</guid>
            <category><![CDATA[u-boot]]></category>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[buildroot]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Shubham Gupta]]></dc:creator>
            <pubDate>Tue, 03 Mar 2026 12:27:44 GMT</pubDate>
            <atom:updated>2026-03-03T12:27:44.521Z</atom:updated>
            <content:encoded><![CDATA[<p>In our previous phases, we built a</p><ul><li><strong>A cross-compilation toolchain:</strong></li></ul><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Custom Embedded Linux(Phase-1): Building cross compilation toolchain(Crosstool-ng) for BeagleBone</a></p><ul><li><strong>U-Boot bootloader:</strong></li></ul><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6">Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black</a></p><ul><li><strong>The Linux kernel:</strong></li></ul><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315">Custom Embedded Linux Phase 3: Building Kernel for the BeagleBone Black</a></p><p>If we booted our BeagleBone Black right now, the hardware would initialize, and the Kernel would successfully load into memory.</p><p>But then, the system would completely freeze with a <strong>“Kernel Panic.”</strong></p><p>Why? Because the Kernel is just the engine. It has no hands, no voice, and no user interface. It needs an init process to start, a /bin/sh shell to accept commands, and a filesystem to store data which all is provided by <strong>Root Filesystem (RootFS)</strong> .</p><p>In Phase 4, we build the <strong>Root Filesystem (RootFS)</strong>. This is the “body” of the operating system, where user applications, libraries, and configuration files reside. To automate this complex process, we will use <strong>Buildroot</strong>.</p><h3>1. The Core Concept: The Modular Approach</h3><h4>1.1 What Exactly is a Root Filesystem?</h4><p>When you log into a Linux machine and type ls /, you see directories like /bin, /etc, /lib, and /usr. This structure is the RootFS. It contains <strong>C library (uClibc in our case), BusyBox, utilities, Device files, System configurations.</strong></p><p>This is what turns a kernel into a usable operating system.</p><p>For embedded devices, building this by hand is a nightmare. You would have to cross-compile every single utility (like ls, grep, and ping), manually create device nodes in /dev, and link all the C-libraries perfectly.</p><p>Instead of doing that manually, embedded engineers use <strong>Buildroot</strong>.</p><h4>1.2 So What is Buildroot: The Automation Engine</h4><p>Buildroot is a powerful build system that automates the creation of a complete, bootable Linux filesystem. It downloads the source code for hundreds of user-space applications, compiles them for your specific architecture (ARMv7), and packages them into a neat, deployable archive. <strong>It can generate Toolchain, Bootloader, Kernel, and Root Filesystem.</strong></p><p>So why did we spend Phases 1 through 3 building those manually? Because true understanding comes from modularity. By disabling Buildroot’s Kernel and Bootloader builds , and forcing it to use our custom toolchain , we gain maximum control and a deep understanding of how each component interacts.</p><p>Since we already built our own toolchain, kernel, and bootloader in earlier phases, we will use Buildroot <strong>only for the RootFS</strong>.</p><h3>2. Step-by-Step: Building Rootfs using Buildroot</h3><h4>2.1 Setting the Stage: Prerequisites</h4><p>Before starting, ensure your custom toolchain from <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Phase 1</a> is in your path.</p><pre>cd ~/embedded-linux/step-4<br>source ../environ.sh<br># Ensure your alias points to your custom arm-uclibc compiler<br>arm-make --version</pre><p>If this is throwing error or points to host GCC, stop immediately you are about to build an unusable kernel. Cross-compilation mistakes at this stage waste hours.</p><h4>2.2 Get the Source</h4><p>We are using latest version to ensure stability and compatibility with our toolchain.</p><pre>wget https://buildroot.org/downloads/buildroot-2025.11.tar.xz<br>tar -xvf buildroot-2025.11.tar.xz<br>cd buildroot-2025.11</pre><h4>2.3 Preparing Buildroot</h4><p>First, we apply the default configuration for the BeagleBone Black to establish our baseline:</p><pre>arm-make beaglebone_defconfig</pre><h4>2.4 Customize the Buildroot</h4><p>we enter the configuration menu (arm-make menuconfig) to heavily customize the build.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f3ece18c82b4546d7def0576559cec5/href">https://medium.com/media/1f3ece18c82b4546d7def0576559cec5/href</a></iframe><h4>2.5 Building the RootFS</h4><p>Run arm-make to start the building process. Buildroot attempts to download every package from the internet, which can be slow or fail if links are broken. If broken: <strong>Buildroot stores downloads in a dl/ directory.(can check and download externally also)</strong></p><blockquote><strong>Expected Error:</strong> You may see “<strong>Could not set up MLO</strong>” at the very end.<br><strong>Verdict:</strong> Ignore this. It is a bug in the build system because we disabled the bootloader build. It does not affect the RootFS.</blockquote><h4>2.6 Verification &amp; Output</h4><p>Checkoutput/images/You should see:</p><ul><li><strong>rootfs.tar.xz</strong> (this is your compressed Root Filesystem)</li></ul><h3>3. Common Toolchain Problem(And Fixes)</h3><h4>The Architectural Lessons of Integration</h4><p>When you force a build system like Buildroot to use a toolchain it didn’t create, you learn very quickly how Linux components depend on each other. Buildroot validates toolchains aggressively and does not assume compatibility.</p><p>Here are the practical engineering lessons this phase teaches us:</p><ul><li><strong>Library Capabilities Must Match:</strong> Our custom uClibc library is designed to be highly minimal. If Buildroot is configured to build networking tools that require <strong>IPv6</strong>, but our minimal C-library wasn&#39;t compiled with IPv6 support, the linker will fail.</li><li><strong>Manual Alignment:</strong> When using external toolchains, the engineer must manually ensure that features like Stack Smashing Protection (SSP), Locale databases, and WCHAR support are perfectly aligned between the compiler and the Buildroot configuration.</li></ul><p>These aren’t just “build errors” — they are strict reminders that in embedded systems, the user-space applications are inextricably tied to the capabilities of the underlying C-library.</p><p>Here are the most common issues:</p><h4>Issue 1: The IPv6 Missing Link</h4><ul><li><strong>The Error:</strong> IPv6 support not available in C library, toolchain unsuitable for Buildroot.</li><li><strong>The Root Cause:</strong> Our uClibc library from Phase 1 was minimal and lacked IPv6, which Buildroot expects by default.</li><li><strong>The Fix:</strong> We had to return to crosstool-NG, enable IPv6 in the uClibc networking support menu, and completely rebuild the toolchain. <em>Lesson learned: Header presence (</em><em>#define AF_INET6) does not equal actual library linking support.</em></li></ul><h4>Issue 2: Locale Support Conflicts</h4><ul><li><strong>The Error:</strong> Locale support not available in C library.</li><li><strong>The Root Cause:</strong> uClibc was built without a locale database to save space, but Buildroot was trying to include it.</li><li><strong>The Fix:</strong> In Buildroot’s toolchain menu, we explicitly disabled Enable locale support. uClibc is minimal by design; we should not blindly enable heavy features.</li></ul><h4>Issue 3: Stack Smashing Protection (SSP)</h4><ul><li><strong>The Error:</strong> SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP.</li><li><strong>The Root Cause:</strong> Modern GCC defaults to including SSP, but we didn’t declare it in Buildroot.</li><li><strong>The Fix:</strong> We manually checked Toolchain has SSP support in the configuration.</li></ul><h3>5. The Security Perspective: Userspace Constraints</h3><p>For embedded security researchers, the RootFS is where the action happens.</p><p>For firmware security researchers, understanding the RootFS build process is invaluable. When you extract a real-world firmware image (using a tool like binwalk), you are usually unpacking a Buildroot or Yocto-generated filesystem. Because you now know how BusyBox and uClibc are integrated, you know exactly what constraints an attacker faces when they get a reverse shell on a device. You know to look in /etc/init.d/ for persistence mechanisms, and you understand why compiling a standard desktop exploit won&#39;t work on a stripped-down embedded target.</p><p><strong>Next Steps:</strong></p><p>We have all the puzzle pieces. In the final article, <strong>Phase 5</strong>, we will format our SD card, map the hardware partitions, configure uEnv.txt, and finally boot our custom Linux operating system on the BeagleBone Black.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45018165554d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Embedded Linux Phase 3: Building Kernel for the BeagleBone Black]]></title>
            <link>https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315?source=rss-04b99420b7fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3534859d4315</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[u-boot]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[linux-kernel]]></category>
            <category><![CDATA[dtb-firmware]]></category>
            <dc:creator><![CDATA[Shubham Gupta]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 11:58:20 GMT</pubDate>
            <atom:updated>2026-03-11T07:04:49.120Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is part of a <strong>hands-on series where we build a complete Embedded Linux system for the BeagleBone Black entirely from source. </strong>But don’t worry we made this articles like anyone can pick from any article.</p><pre>Custom Embedded Linux for BeagleBone Black — Article Series<br><br>Toolchain → U-Boot → Kernel → RootFS → Booting<br>   ✓        ✓          ★        ○        ○</pre><h3>Articles in the Series</h3><ol><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong>Phase 1: The Toolchain</strong></a> — Building the custom cross-compiler using <strong>Crosstool-ng</strong> (the “tools that build tools”).</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2: The Bootloader</strong></a> — Compiling U-Boot to initialize the AM335x hardware.(This Article)</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3: The Kernel</strong></a> — Tailoring the heart of the OS and the Device Tree.</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4: The RootFS</strong></a> — Constructing the RootFS using <strong>Buildroot</strong>.</li><li><a href="https://medium.com/@shubhamgupta577/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5: Integration</strong></a> — Partitioning the storage and performing the final booting process.</li></ol><p>In <strong>Phase 2</strong>, we built the <strong>U-Boot bootloader</strong>, the software responsible for initializing the hardware and loading the operating system.</p><p>Now we move to the <strong>core of the system — the Linux Kernel</strong>.</p><p>If the bootloader is responsible for starting the machine, the <strong>kernel is the engine that keeps it running</strong>. It manages memory, schedules processes, and provides the drivers that allow software to communicate with the BeagleBone Black’s hardware. Click for Phase -2 :</p><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6">Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black</a></p><p>In this phase we will:</p><ul><li>Compile <strong>Linux Kernel 6.1 (LTS)</strong></li><li>Understand the <strong>Device Tree</strong> and why ARM systems depend on it</li><li>Configure the kernel for <strong>research vs production environments</strong></li><li>Learn how kernel configuration choices affect the <strong>system attack surface</strong></li></ul><p>By the end of this phase, we will have the <strong>core executable that actually runs the operating system</strong>. In this article, we will compile <strong>Linux Kernel 6.1</strong>, configure the <strong>Device Tree Binary (DTB)</strong>, and explore the critical security trade-offs between a “Hardened” production kernel and a “Weakened” research kernel.</p><h3>1. The Core Concept: The Kernel-Hardware Bridge</h3><p>On an ARM-based system like the BeagleBone Black, the Kernel doesn’t “know” the hardware layout automatically. It relies on two critical things:</p><p>1.1 <strong>Kernel Image (</strong><strong>zImage)</strong> — This is the compressed ARM executable that contains:</p><ul><li>Scheduler</li><li>Memory manager</li><li>Drivers</li><li>System call interface</li></ul><p>1.2 <strong>Device Tree Binary (</strong><strong>.dtb)</strong>- The DTB is a structured description of hardware topology.</p><p>It tells the kernel:</p><ul><li>Where RAM is located</li><li>Which UART is connected to the console</li><li>Which GPIO controls the LEDs</li><li>Which interrupts map to which peripherals</li></ul><p>Without a valid DTB, the kernel cannot even locate its own console, results as immediate kernel panic</p><blockquote>The Device Tree is not configuration fluff — it is a hardware contract between silicon and software.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vYufAkMy5eAiSUHuPWROBw.png" /></figure><h3>2. Setting the Stage: Prerequisites</h3><p>Before starting, ensure your custom toolchain from <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Phase 1</a> is in your path.</p><pre>cd ~/embedded-linux/step-3<br>source ../environ.sh<br># Ensure your alias points to your custom arm-uclibc compiler<br>arm-make --version</pre><p>If this is throwing error or points to host GCC, stop immediately you are about to build an unusable kernel. Cross-compilation mistakes at this stage waste hours.</p><h3>3. Step-by-Step: Compiling the Kernel</h3><h4>3.1 Get the Source</h4><p>We are using a modern long-term support (LTS) version to ensure stability and compatibility with our toolchain.</p><pre>wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.16.tar.xz<br>tar -xvf linux-6.16.tar.xz<br>cd linux-6.16</pre><p><strong>Why LTS?</strong>- Because embedded products live for years. Security patches matter.</p><h4>3.2 The Base Configuration</h4><p>Manual kernel configuration is an impossible task — there are over 10,000 options. We start with a defconfig that <strong>Texas Instruments</strong> has already optimized for the ARMv7 architecture. Can be found in <strong>arch/arm/configs/</strong></p><pre>arm-make multi_v7_defconfig</pre><p>Note: multi_v7_defconfig is a &quot;generic&quot; ARMv7 config. It supports the AM335x (BeagleBone) but also many other SoCs, making the final image slightly larger but highly compatible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1GWX2vx97kPbZ6713jQYQ.png" /><figcaption>defconfigs</figcaption></figure><h4>3.3 Customization of Kernel</h4><p>Run arm-make menuconfig to enter the configuration interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TJE1Vw9N9ALA64fyVP13_g.png" /><figcaption>Configuration menu for Kernel</figcaption></figure><h4>A. Research Kernel (Intentionally Weak)</h4><p>For firmware pentesting or rootkit research, exploit development, or rootkit experimentation, you sometimes need to disable protections modern kernels enforce.</p><ul><li><strong>Disable Kernel Read-Only Protections:</strong> Navigate to General architecture-dependent options-&gt; Set loadable kernel module data as NX and text as RO. <strong>Unselect this.</strong></li><li><strong>Writable Syscall Table:</strong> Deselect “Make kernel text and rodata read-only.”</li><li><strong>The “Why”:</strong> This allows you to write scripts that “hook” system calls in memory — the primary method used by rootkits to hide files or processes. Disabling them allows to <strong>Writing to kernel text, Hooking syscalls in memory, and Studying how classic rootkits function</strong></li><li><strong>Disable Seccomp:</strong> Many legacy IoT kernels (2.4.x or 3.x) don’t support Seccomp (Secure Computing). Disabling it helps you replicate<strong> insecure legacy environments for research.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KlYfpFywKFXh2Qpn47HWdA.png" /><figcaption>architecture and networking options (can be different as per version)</figcaption></figure><h4>B. The “Production” Setup (Hardening)</h4><p>If you were building this for a real product, you would:</p><ul><li><strong>Enable Read-Only Protections: </strong>Keep kernel text immutable.</li><li><strong>Enable Kprobes:</strong> For non-intrusive debugging.</li><li><strong>Enable Netfilter:</strong> This allows for iptables or nftables support for firewalling.</li><li><strong>Optimize Size:</strong> Navigate to System Type and limit support <em>only</em> to the TI AM33xx family. This shrinks your kernel from ~8MB to ~3MB, saving critical flash storage</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*J9zGjpVOItY8e1WedPIjpA.png" /><figcaption>System type choices</figcaption></figure><h4>3.4 Execution: The Build</h4><p>Once configured, we compile three components: the compressed kernel image (zImage), the loadable modules, and the device tree binaries.</p><pre>arm-make -j$(nproc) zImage modules dtbs</pre><p>This produces:</p><ul><li><strong>zImage → compressed kernel binary</strong></li><li><strong>modules → loadable drivers</strong></li><li><strong>dtbs → compiled device tree blobs</strong></li></ul><h4>3.5 Output Verification</h4><p>After 10–20 minutes, check your build artifacts:</p><ul><li><strong>The Kernel:</strong> arch/arm/boot/zImage</li><li><strong>The Map:</strong> arch/arm/boot/dts/ti/omap/am335x-boneblack.dtb</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lhp0XGf4rXOa4eB3M3Dr5g.png" /><figcaption>Final outputs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uehbbsk_Ay0gGyZXYqxiDg.png" /></figure><h3>6. The Pentester’s Goldmine: Understanding the DTB</h3><p>As a researcher, the .dtb file is a goldmine. If you extract a .dtb from a commercial device convert it back to source, you can see exactly which peripherals are enabled.</p><pre>dtc -I dtb -O dts -o output.dts am335x-boneblack.dtb</pre><ul><li><strong>Hidden UARTs:</strong> Does the manufacturer claim there’s no serial port? The DTB will show you the memory address of every UART controller on the chip.</li><li><strong>GPIO Pins:</strong> It shows you which pins control LEDs, resets, or factory-wipe triggers.</li><li>Now you can inspect <strong>Hidden UART controllers, Unused GPIO pins, SPI/I2C buses, Interrupt mappings, Memory regions.</strong></li></ul><blockquote>Note: Manufacturers often disable interfaces in software while the hardware remains present.</blockquote><h3>Conclusion: The System Now Has a Brain</h3><p>We now have a <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong>custom cross-compiler</strong></a>, a <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>U-Boot</strong> <strong>bootloader</strong></a>, and a functional (and strategically configured) <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>custom Linux Kernel</strong></a>. We are 80% of the way there.</p><h4>What Comes Next</h4><p>In <strong>Phase 4</strong>, we will build the <strong>Root Filesystem (RootFS)</strong> using Buildroot. This is where we add the “personality” to our system — <strong>BusyBox, Init system, SSH servers, Userspace utilities</strong> and our custom security tools.</p><p>If you are joining this article directly, you can join the series.</p><p><strong>1️⃣</strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong> Phase 1 — Toolchain Setup<br></strong></a><strong>2️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2 — Compiling U-Boot</strong></a><strong><br>3️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3 — Building the Linux Kernel</strong></a><strong><br>4️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4 — Constructing the Root Filesystem</strong></a><strong><br>5️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5 — Integration and Booting the System</strong></a></p><h4>➡ Next Article:<br>Phase 3 — Building the ROOTFS using Buildroot for the BeagleBone Black</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d">Custom Embedded Linux Phase 4: Constructing the Root Filesystem with Buildroot</a></p><h4>⬅Previous Article:<br>Phase 2 — Compiling U-Boot for the BeagleBone Black</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6">Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3534859d4315" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black]]></title>
            <link>https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6?source=rss-04b99420b7fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/039b8d3239f6</guid>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[beaglebone-black]]></category>
            <category><![CDATA[u-boot]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Shubham Gupta]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 11:12:41 GMT</pubDate>
            <atom:updated>2026-03-10T10:46:48.900Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is part of a <strong>hands-on series where we build a complete Embedded Linux system for the BeagleBone Black entirely from source. </strong>But don’t worry we made this articles like anyone can pick from any article.</p><pre>Custom Embedded Linux for BeagleBone Black — Article Series<br><br>Toolchain  →  U-Boot  →  Kernel  →  RootFS  →  Booting<br>   ✓           ★          ○           ○          ○</pre><h3>Articles in the Series</h3><ol><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong>Phase 1: The Toolchain</strong></a> — Building the custom cross-compiler using <strong>Crosstool-ng</strong> (the “tools that build tools”).</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2: The Bootloader</strong></a> — Compiling U-Boot to initialize the AM335x hardware.(This Article)</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3: The Kernel</strong></a> — Tailoring the heart of the OS and the Device Tree.</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4: The RootFS</strong></a> — Constructing the RootFS using <strong>Buildroot</strong>.</li><li><a href="https://medium.com/@shubhamgupta577/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5: Integration</strong></a> — Partitioning the storage and performing the final booting process.</li></ol><p>In <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Phase 1</a>, we built a custom <strong>cross-compilation toolchain</strong> capable of generating ARM binaries for the BeagleBone Black. However, a compiler alone does not make a system. Now it is time to use that toolchain to build the <strong>first executable code that runs on the hardware</strong>. That component is the <strong>bootloader</strong>.</p><p>For most ARM-based systems, the industry standard bootloader is <strong>U-Boot (Universal Boot Loader)</strong>. Developers treat <strong>U-Boot</strong> as a black box — you run a few commands, get a file, and move on. In this article, we’re going deeper. We will explore how a processor with zero initial intelligence “wakes up,” why we need <strong>multiple stages of booting</strong>, and how to manipulate this process for development and security testing.<br>For toolchain and environment setup, check the Phase — 1:</p><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Custom Embedded Linux(Phase-1): Building cross compilation toolchain(Crosstool-ng) for BeagleBone</a></p><h3>1. The “Wake-Up” Architecture: Why Multi-Stage Booting?</h3><p>When you apply power to the AM335x SoC, it is in a state of “primitive” intelligence. It only knows how to do one thing: execute a tiny piece of code hardcoded into its silicon, known as the <strong>ROM Code</strong>.</p><p>The ROM Code follows a predefined boot order <strong>(e.g., SD → eMMC → UART → USB)</strong>, which is determined by hardware boot pins and internal SoC configuration. Understanding this order is critical when debugging “<strong>dead board</strong>” scenarios.</p><p>However, the ROM Code is limited. It cannot talk to the external 512MB DDR3 RAM because the RAM hasn’t been initialized yet. This creates a “Chicken and Egg” problem: <strong>How do you load a 500KB bootloader if you only have 64KB of internal memory (SRAM) available?</strong></p><p>The solution is a three-stage relay race:</p><ol><li><strong>Stage 1 (ROM Code):</strong> Hardcoded in silicon. It searches the SD card for a file named MLOor First Stage Bootloader.</li><li><strong>Stage 2 (MLO / SPL):</strong> This is the <strong>Secondary Program Loader</strong>. It is tiny enough to fit in the 64KB internal SRAM. Its primary mission is to initialize the external DDR RAM. Once the RAM is “alive,” it loads the main U-Boot image into that RAM.</li><li><strong>Stage 3 (U-Boot):</strong> The full “Universal Boot Loader.” Once RAM is ready, the full U-Boot image is loaded. It provides the interactive shell, networking, and the logic to find and decompress the Linux Kernel.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-pSkhpy67vFp2sd28LuLg.png" /><figcaption>Booting Sequence(2-Stage Booting)</figcaption></figure><h4>Why Compile from Source?</h4><p>As a security researcher or engineer, compiling from source allows you to:</p><ul><li><strong>Disable Console Access: </strong>In production devices, vendors often remove the interactive shell to prevent UART-based attacks.</li><li><strong>Modify Boot Delays:</strong> Give yourself more time to interrupt the boot process for debugging.</li><li><strong>Enable/Disable Commands:</strong> Enable commands like ext4write or mw (memory write) that are often disabled in production for security but are vital for testing.</li><li><strong>Hardcode Keys:</strong> For projects involving Verified Boot, this is where you would embed public keys.</li></ul><h3>2. Prerequisites &amp; Environment Setup</h3><p>Before we compile, we must ensure our path. If you’ve closed your terminal since Phase 1, your custom compiler isn’t in your path.</p><pre># Move to your workspace<br>cd ~/embedded-linux/step-2<br># Source your environment script from Phase 1<br>source ../environ.sh<br># The Litmus Test: Does your alias work?<br>arm-make --version</pre><p>If this command invokes your system’s x86 GCC instead of <strong>arm-unknown-linux-uclibcgnueabihf-gcc</strong> or <strong>return an error</strong>, you are about to build an unusable bootloader. Stop and fix your PATH as your toolchain isn’t linked correctly. Do not proceed until arm-make points to your custom uclibc compiler.</p><blockquote><strong>Critical Action:</strong> Always reload your environment variables if you have opened a new terminal.</blockquote><h3>3. The Build Process</h3><h4>Step 3.1: Get the Source</h4><p>We will use a stable version of U-Boot. You can choose a version that matches your specific project requirements.(If download fail, you can directly copy paste the at file)</p><pre>wget https://ftp.denx.de/pub/u-boot/u-boot-2025.10.tar.bz2<br>tar -xjf u-boot-2025.10.tar.bz2<br>cd u-boot-2025.10/</pre><h4>Step 3.2: Apply the Default Configuration</h4><p>U-Boot supports thousands of boards. We need the specific configuration for the BeagleBone Black’s AM335x chip. The transcript identifies <strong>am335x_evm_defconfig (found in configs/)</strong> as the correct file based on Texas Instruments documentation.</p><p>Instead of manually configuring thousands of hardware pins, we use a defconfig file provided by Texas Instruments for the AM335x EVM (the chip inside the BeagleBone).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u38Om3CZf0N3OeeIj2ozxA.png" /><figcaption>defconfigs</figcaption></figure><pre>#cmd for setting defconfig<br>arm-make am335x_evm_defconfig</pre><p>What this does: This command generated a .config file that tells U-Boot exactly where the UART pins are, how much RAM to expect, and which MMC (SD card) slot to use.</p><p><em>Note: We use our </em><em>arm-make alias to ensure the </em><em>ARCH=arm and </em><em>CROSS_COMPILE variables are automatically applied.</em></p><h4>Step 3.3: Customizing the Bootloader (menuconfig)</h4><p>This is where you make the bootloader your own.</p><pre>arm-make menuconfig</pre><p><strong>Recommended Tweaks:</strong></p><ul><li><strong>Boot Delay:</strong> Navigate to <strong>Boot options</strong> and change the <strong>autoboot delay</strong> from 2 to 10 seconds. This is a lifesaver when you need to stop the boot process to troubleshoot.</li><li><strong>Shell Prompt:</strong> Change the default =&gt; prompt to something unique (e.g., Shubham-Boot&gt;) to verify your custom build is running.</li><li><strong>Command Support:</strong> Ensure networking commands and filesystem write commands (like ext4write) are enabled.</li></ul><blockquote>One thing we deliberately skipped is bootloader security.</blockquote><blockquote>If you’d like a deep dive on <strong>locking down U-Boot</strong> — password protection, SHA256 hashed keys, and why uEnv.txt; a dedicated article on<strong> securing U-Boot</strong> for production is still a gap even after — let me know in the comments.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9pqhzx5ZMzsC3cj4SsSMjg.png" /><figcaption>Configuration menu forU-Boot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B56mDFc-nlThA-V4LX9PNQ.png" /><figcaption>CLI and Boot options(can be different as per version)</figcaption></figure><h4>Step 3.4: Final Compilation</h4><pre>arm-make -j$(nproc)</pre><blockquote><em>Note: </em>-j$(nproc) flag parallelizes compilation across all available CPU cores, significantly reducing build time.</blockquote><p>This process is significantly faster than building the toolchain, usually taking only a few minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*2CmfI8j-Hu1iHxx5nHqc_A.png" /><figcaption>Directory structure and build process</figcaption></figure><h3>4. The Hardware Map: Understanding Device Trees (DTS)</h3><p>In the old days of Linux, hardware information was hardcoded into the source code. Today, we use <strong>Device Trees</strong>. Think of a Device Tree as a “map” that tells the bootloader and kernel: <em>“The UART0 controller is at this memory address, and it uses these specific pins.”</em></p><p>Device Trees are not merely configuration files — they are a hardware contract between the bootloader and the kernel. Misconfigured device trees can result in non-functional UART, dead Ethernet ports, or silent boot failures.</p><h4>Why this matters for Phase 2:</h4><p>Inside your U-Boot source, navigate to arch/arm/dts/. You will see am335x-boneblack.dts.</p><ul><li><strong>The Inheritance:</strong> It pulls from am33xx.dtsi (the SoC family features) and adds specifics for the BeagleBone Black board.</li><li><strong>The Power:</strong> If you were designing your own custom PCB with an AM335x chip, this is the file you would modify to tell the software that you moved the LED to a different GPIO pin.</li></ul><h3>5. The Result: What did we create?</h3><p>Upon a successful build, check your directory for these two critical files:</p><ul><li><strong>MLO:</strong> The First Stage Bootloader. Without this, the processor cannot talk to its own RAM. It <strong>fits in internal SRAM, initializes external DDR RAM</strong></li><li><strong>u-boot.img:</strong> The main, interactive bootloader image. <strong>The interactive shell and responsible for loading Linux kernel.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-oPN9Z6XPyy53_1C354KQ.png" /><figcaption>Results as MLO and u-boot</figcaption></figure><h3>Conclusion</h3><h4>Summary Flow</h4><p>1. <strong>Setup:</strong> source environ.sh.<br> 2. <strong>Extract:</strong> tar -xvf ….<br> 3. <strong>Configure: </strong>arm-make am335x_evm_defconfig. (this should be in Uboot directory)<br> 4. <strong>Customize:</strong> arm-make menuconfig (e.g., Change boot delay).<br> 5.<strong> Build:</strong> arm-make.<br> 6. <strong>Verify:</strong> Check for MLO and u-boot.img.</p><h4>Troubleshooting &amp; “Gotchas”</h4><ul><li><strong>“Architecture Mismatch”:</strong> If you see errors about “unrecognized command-line option,” ensure you didn’t accidentally run standard make. Standard make uses your host&#39;s x86 compiler, which cannot compile ARM code.</li><li><strong>Missing MLO:</strong> If u-boot.img appears but MLO does not, your configuration might not be set for an SPL (Secondary Program Loader) build. Re-verify that you used am335x_evm_defconfig.</li><li><strong>Toolchain Errors:</strong> If the assembler complains about instructions like dsb sy, it means your toolchain was built for a generic ARM target instead of armv7-a. You may need to go back to Phase 1 and rebuild your toolchain with the correct CPU tuning.</li><li><strong>Clean Build:</strong> If you mess up settings, run arm-make distclean to wipe everything and start fresh from Step 2</li></ul><h4>The Pentester’s Perspective: Why this Phase matters</h4><p>In the world of firmware security, the bootloader is a high-value target. By mastering this phase, you now understand how to:</p><ul><li><strong>Identify Hardware Pins:</strong> Looking through the U-Boot source (especially in arch/arm/dts/am335x-boneblack.dts) tells you exactly which hardware pins are used for UART or JTAG.</li><li><strong>Environment Manipulation:</strong> If you have physical access to a device’s UART (Serial) port and can interrupt U-Boot, you can often change the bootargs. By adding init=/bin/sh, you tell the kernel to bypass the login screen and drop you straight into a root shell.</li><li>Many embedded devices ship with an unsecured U-Boot prompt. If boot delay is non-zero and no password protection is enabled, full system compromise is often possible with only physical UART access.</li></ul><h3>Continue the Series</h3><p>At this point we have successfully built:</p><p>• A <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong>custom cross-compilation toolchain</strong></a><br>• The <a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>U-Boot bootloader</strong></a></p><p>These components form the <strong>foundation of the embedded Linux boot chain</strong>.</p><p>In the next phase, we will build the <strong>Linux Kernel</strong>, the core of the operating system responsible for hardware management, memory control, and process scheduling.</p><p>If you are joining this article directly, you can join the series.</p><p><strong>1️⃣</strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong> Phase 1 — Toolchain Setup<br></strong></a><strong>2️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2 — Compiling U-Boot</strong></a><strong><br>3️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3 — Building the Linux Kernel</strong></a><strong><br>4️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4 — Constructing the Root Filesystem</strong></a><strong><br>5️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5 — Integration and Booting the System</strong></a></p><h4>➡ <strong>Next Article:</strong><br> <strong>Phase 3 — Building the Linux Kernel for the BeagleBone Black</strong></h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315">Custom Embedded Linux Phase 3: Building Kernel for the BeagleBone Black</a></p><h4>⬅Previous Article:<br>Phase 1 — Building Toolchain using crosstool-ng</h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97">Custom Embedded Linux(Phase-1): Building cross compilation toolchain(Crosstool-ng) for BeagleBone</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=039b8d3239f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Embedded Linux(Phase-1): Building cross compilation toolchain(Crosstool-ng) for BeagleBone]]></title>
            <link>https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97?source=rss-04b99420b7fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/949cfef98e97</guid>
            <category><![CDATA[beaglebone-black]]></category>
            <category><![CDATA[toolchain]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[linuxworld]]></category>
            <category><![CDATA[u-boot]]></category>
            <dc:creator><![CDATA[Shubham Gupta]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 10:50:24 GMT</pubDate>
            <atom:updated>2026-03-06T09:02:22.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>Custom Embedded Linux From Scratch(Phase-1): Building cross compilation toolchain(Crosstool-ng) for Beagle Bone Black</h3><p>This article is part of a <strong>5-part hands-on series</strong> where we build a complete Embedded Linux system for the <strong>BeagleBone Black</strong> completely from source.</p><pre>Custom Embedded Linux for BeagleBone Black — Article Series<br><br>Toolchain  →  U-Boot  →  Kernel  →  RootFS  →  Booting<br>   ★           ○         ○         ○         ○</pre><p>In the world of IoT and embedded systems, most developers are content with flashing a pre-built Debian or Ubuntu image onto an SD card and calling it a day. But for the security researcher, the kernel developer, or the high-stakes embedded engineer, a “black box” OS is not enough. To truly understand a system — and to secure it — you must be the one who built it. In this guide, we are going to strip away the abstractions and <strong>build a custom, minimalist Linux</strong> stack from the ground up for the <strong>BeagleBone Black (AM335x).</strong> We will resolve the inherent dependency complexities of cross-compilation, <strong>configure a bootloader(U-Boot) for hardware initialization</strong>, harden (and intentionally weaken) a <strong>Linux kernel</strong> for security research, and assemble a <strong>lean root filesystem(BuildRoot)</strong>. By the end of this article, you won’t just have a booting device; you will have a deep, architectural understanding of the embedded firmware supply chain.</p><h3>Prerequisites &amp; Environment Setup</h3><h4>System Requirements</h4><ul><li><strong>Host OS:</strong> Ubuntu 22.04 or 24.04 VM.</li><li><strong>Hardware:</strong> BeagleBone Black (ARMv7-A), microSD card (at least 8GB), and a USB-to-TTL Serial Cable for debugging.</li></ul><h3>The Master Plan: What We Are Building</h3><p>This project is divided into five distinct phases, each responsible for one layer of the embedded Linux stack:</p><ol><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong>Phase 1: The Toolchain</strong></a> — Building the custom cross-compiler using <strong>Crosstool-ng</strong> (the “tools that build tools”).</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2: The Bootloader</strong></a> — Compiling U-Boot to initialize the AM335x hardware.</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3: The Kernel</strong></a> — Tailoring the heart of the OS and the Device Tree.</li><li><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4: The RootFS</strong></a> — Constructing the userspace environment using <strong>Buildroot</strong>.</li><li><a href="https://medium.com/@shubhamgupta577/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5: Integration</strong></a> — Partitioning the storage and performing the final boot.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHwUs6sOtq5U2Dn5qqWcYw.png" /><figcaption>Credits: Google Gemini</figcaption></figure><h3>Phase 1: Building the Cross-Compilation Toolchain</h3><p>Before we can write code for our BeagleBone Black, we need a compiler. However, your standard PC compiler (x86) cannot create binaries that an ARM processor understands. We need a <strong>Cross-Toolchain</strong> — a set of tools that run on your host computer but target a different architecture</p><h4>1.1 The Core Concept: Why Not Just Use apt install?</h4><p>While you can download generic ARM compilers, building your own ensures that your C library (uClibc), Floating Point Unit (FPU) support, and instruction sets are perfectly aligned with your hardware.</p><ul><li><strong>uClibc-ng:</strong> We use this instead of glibc because it is specifically designed for resource-constrained IoT devices, resulting in much smaller binaries.</li><li><strong>Hard Float (hf):</strong> We will enable the hardware FPU to ensure the AM335x handles math operations via dedicated hardware rather than slow software emulation.</li></ul><blockquote>A mismatch between FPU settings (soft-float vs hard-float) can cause silent runtime crashes, ABI incompatibilities, and linker errors that are extremely difficult to debug. This is one of the most common mistakes in custom toolchain builds.</blockquote><ul><li>The suffix gnueabihf indicates:</li><li>gnu → GNU toolchain</li><li>eabi → Embedded ABI</li><li>hf → Hard Float</li></ul><h4>1.2 Environment Setup</h4><p>To avoid the build failing mid-way due to a missing library, install the following dependencies on your Ubuntu host:</p><pre>sudo apt update<br>sudo apt install open-vm-tools-desktop build-essential \<br>libc6-dev libncurses5-dev git gzip help2man tree bzip2 linux-tools-generic \<br>gperf flex bison make autoconf automake texinfo be curl mtd-utils net-tools \<br>device-tree-compiler dosfstools liblzo2-dev libfuse-dev libell-dev u-boot-tools \<br>gawk libgtk2.0-dev gparted screen patch squashfs-tools symlinks sysfsutils \<br>libssl-dev libglade2-dev libhugetlbfs-dev libtool-bin libpython-dev</pre><h4>Directory Organization</h4><p>Create a clean workspace to keep your source code and build artifacts separate:</p><pre>mkdir -p embedded-linux/{step-1,step-2,step-3,step-4}<br>cd embedded-linux/step-1<br>mkdir -p {tarballs,customtoolchain}</pre><h4>The Environment Script (environ.sh)</h4><p>This script is the most important part of your workflow. It tells your system where to find your custom tools. Create this in your embedded-linux directory:</p><pre>export BASE_INSTALL_DIR=$(pwd)<br>export TOOL_CHAIN_PATH=$BASE_INSTALL_DIR/step-1/customtoolchain<br>export PATH=$PATH:$TOOL_CHAIN_PATH/bin:$TOOL_CHAIN_PATH/arm-unknown-linux-uclibcgnueabihf/bin<br>alias arm-make=&#39;ARCH=arm CROSS_COMPILE=arm-unknown-linux-uclibcgnueabihf- make&#39;</pre><p><strong>Action:</strong> Always run source environ.sh before starting your work in a new terminal and give read/write permission to the file before run using sudo chmod 777 environ.sh</p><h4>1.3 Building the Toolchain Builder (Crosstool-NG)</h4><p>We use <strong>crosstool-NG (ct-ng)</strong> to manage the complex process of compiling a compiler.</p><ol><li><strong>Download and Install ct-ng:</strong></li></ol><pre>cd embedded_linux/step-1<br><br>wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.28.0.tar.xz<br>tar -xvf crosstool-ng-1.28.0.tar.bz2 &amp;&amp; cd crosstool-ng-1.28.0 <br>./configure --prefix=$BASE_INSTALL_DIR/step-1/customtoolchain <br>make &amp;&amp; make install</pre><ul><li>The --prefix flag ensures the tool installs locally in our project folder, not into your system root.</li></ul><p><strong>2. Configuration (</strong><strong>menuconfig):</strong> Run ct-ng menuconfig to define your target. You <strong>must</strong> set these specific values to avoid runtime failures:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da6784128ff02bfb4be71e5ed763f7bb/href">https://medium.com/media/da6784128ff02bfb4be71e5ed763f7bb/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_psoFq4vDg9y8GlRAyNBA.png" /><figcaption>Configuration menu for toolchain</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTphYf5uYPX1bSVRdv9CYQ.png" /><figcaption>Target and C- library options<strong><em>(can be different as per version)</em></strong></figcaption></figure><p><strong>3. The Build:</strong></p><pre>ct-ng build</pre><ul><li>The system downloads (or grabs from tarballs), extracts, configures, and compiles GCC, Binutils, the Linux Kernel headers, and uClibc</li><li>This process can take anywhere from 30 minutes to 2 hours depending on your CPU. Do not interrupt it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PNlJbg9s6SSe-1PZ3OR9Ng.png" /><figcaption>Directory structure and build</figcaption></figure><h4>1.4 Verification</h4><p>Once finished, Run ls step-1/customtoolchain/arm-unknown-linux-uclibcgnueabihf/binYou should see:</p><ul><li>arm-unknown-linux-uclibcgnueabihf-gcc (The C Compiler)</li><li>arm-unknown-linux-uclibcgnueabihf-ld (The Linker)</li><li><strong>Outcome:</strong> A new directory <strong>arm-unknown-linux-uclibcgnueabihf</strong> appears in custom-toolchain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oOr2TjdN5gOxoiYG5ESjQ.png" /><figcaption>Output result</figcaption></figure><h3><strong>Summary Flow</strong></h3><ol><li><strong>Setup Environment</strong> (source environ.sh).</li><li><strong>Build Builder</strong> (Compile crosstool-NG).</li><li><strong>Configure Target</strong> (Select ARM, Linux, uClibc in menuconfig).</li><li><strong>Build Toolchain</strong> (ct-ng build -&gt; waits…).</li><li><strong>Result:</strong> A custom compiler (gcc) specifically for the BeagleBone Black.</li></ol><h4><strong>Troubleshooting &amp; Pro-Tips</strong></h4><ul><li><strong>Incorrect FPU configuration → </strong>Illegal instruction at runtime</li><li><strong>Missing WCHAR → </strong>Buildroot failure later</li><li><strong>Wrong prefix path → </strong>Kernel cannot find cross-compiler</li><li><strong>Environment Variables:</strong> If ct-ng isn’t found, you likely forgot to run source environ.sh.</li><li><strong>Missing Packages:</strong> If the build fails early with “missing tool” errors, verify you ran the long sudo apt install command from the screenshot perfectly.</li><li><strong>Parallel Build:</strong> If you have a powerful CPU, set “Number of parallel jobs” in menuconfig to 4 or 8 to speed up the compile time.</li><li><strong>Case Sensitivity:</strong> The tool name is crosstool-NG (case sensitive in documentation), but the command is often just ct-ng.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5EzqTLvDX9iRkJiUcMNjuw.png" /></figure><h3>Continue the Series</h3><p>Understanding how to build a toolchain from scratch gives you complete control over how software is compiled for your device.</p><p>This article covered <strong>Phase 1 — Building the Cross-Compilation Toolchain</strong>.</p><p>In the next phase, we will use this toolchain to <strong>compile U-Boot</strong>, the bootloader responsible for initializing the hardware and launching the Linux kernel.</p><p>If you are joining this article directly, you can join the series.</p><p><strong>1️⃣</strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-for-beagle-bone-black-949cfef98e97"><strong> Phase 1 — Toolchain Setup<br></strong></a><strong>2️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6"><strong>Phase 2 — Compiling U-Boot</strong></a><strong><br>3️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-3-building-kernel-for-the-beaglebone-black-3534859d4315"><strong>Phase 3 — Building the Linux Kernel</strong></a><strong><br>4️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-4-constructing-the-root-filesystem-with-buildroot-45018165554d"><strong>Phase 4 — Constructing the Root Filesystem</strong></a><strong><br>5️⃣ </strong><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-from-scratch-phase-5-integration-deployment-and-booting-the-beaglebone-eb35d998566a"><strong>Phase 5 — Integration and Booting the System</strong></a></p><h4>➡ <strong>Next Article:</strong><br> <strong>Phase 2 — Compiling U-Boot for the BeagleBone Black</strong></h4><p><a href="https://shubhamgupta577.medium.com/custom-embedded-linux-phase-2-compiling-u-boot-for-the-beaglebone-black-039b8d3239f6">Custom Embedded Linux Phase 2: Compiling U-Boot for the BeagleBone Black</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=949cfef98e97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>