<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>BootLoader on Rishav's Digital Garden</title><link>https://blog.rishavs.in/tags/bootloader/</link><description>Recent content in BootLoader on Rishav's Digital Garden</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 04 Dec 2024 17:20:00 +0000</lastBuildDate><atom:link href="https://blog.rishavs.in/tags/bootloader/index.xml" rel="self" type="application/rss+xml"/><item><title>Problem - fw_printenv does not print bootloader env variables</title><link>https://blog.rishavs.in/posts/problem---fw-printenv-does-not-print-bootloader-env-variables/</link><pubDate>Wed, 04 Dec 2024 17:20:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/problem---fw-printenv-does-not-print-bootloader-env-variables/</guid><description>&lt;h2 id="problem">Problem&lt;/h2>
&lt;p>In bootloader the environment variables are accessible. The values could be accessed and modified perfectly from bootloader cli (hush shell).
When booting to the linux kernel and accessing from bash shell (userspace) through &lt;code>fw_printenv&lt;/code> the environment variables are not accessible. Getting following logs:&lt;/p>
&lt;pre tabindex="0">&lt;code>Warning: Bad CRC, using default environment
&lt;/code>&lt;/pre>&lt;p>Setup:&lt;/p>
&lt;ul>
&lt;li>Using &lt;code>MMC&lt;/code> storage&lt;/li>
&lt;li>The &lt;code>/etc/fw_env.config&lt;/code> file has following entry and the offset and size are same from uboot&amp;rsquo;s &lt;code>.config&lt;/code> file&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code>/dev/mmcblk0p2 0x3f8000 0x8000
&lt;/code>&lt;/pre>&lt;h2 id="uboot-environment-in-rk3588">Uboot Environment in RK3588&lt;/h2>
&lt;h3 id="uboot-config">Uboot Config&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c" data-lang="c">&lt;span style="display:flex;">&lt;span>config ENV_OFFSET
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> hex &lt;span style="color:#e6db74">&amp;#34;Environment offset&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> depends on &lt;span style="color:#f92672">!&lt;/span>ENV_IS_IN_UBI
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> depends on &lt;span style="color:#f92672">!&lt;/span>ENV_IS_NOWHERE &lt;span style="color:#f92672">||&lt;/span> ENVF
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">default&lt;/span> &lt;span style="color:#ae81ff">0x0&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> ENVF
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">default&lt;/span> &lt;span style="color:#ae81ff">0x3f8000&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> help
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Offset from the start of the &lt;span style="color:#a6e22e">device&lt;/span> (or partition)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>config ENV_SIZE
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> hex &lt;span style="color:#e6db74">&amp;#34;Environment size&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">default&lt;/span> &lt;span style="color:#ae81ff">0x8000&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> help
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Size of the environment storage area
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="parameters">Parameters&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span style="display:flex;">&lt;span>CONFIG_ENV_SIZE&lt;span style="color:#f92672">=&lt;/span>0x8000 --&amp;gt; 32K
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>CONFIG_ENV_OFFSET&lt;span style="color:#f92672">=&lt;/span>0x3f8000 --&amp;gt; 4096-32&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">4064&lt;/span> 4096K&lt;span style="color:#f92672">=&lt;/span>4M
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>u-boot/tools/env/fw_env.c&lt;/code>
Either &lt;code>crc0_ok = (crc0 == *environment.crc);&lt;/code> is invalid&lt;/p></description></item><item><title>mkimage</title><link>https://blog.rishavs.in/posts/mkimage/</link><pubDate>Tue, 05 Nov 2024 12:17:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/mkimage/</guid><description>&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>U-Boot expects all bootable files (kernel, device tree blobs, initramfs, scripts, etc.) to have a specific image format called &lt;strong>U-Boot Image Format (uImage format)&lt;/strong>. &lt;code>mkimage&lt;/code> generates this format.&lt;/p>
&lt;h3 id="signing-images">Signing images&lt;/h3>
&lt;ul>
&lt;li>Generate signed image&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>build/uboot/tools/mkimage -k config/keys/secureboot -f boot.its boot.img
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>Dump information&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code>dumpimage -l boot-temp.img
&lt;/code>&lt;/pre>&lt;ul>
&lt;li>Resign the image&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>build/uboot/tools/mkimage -F -k config/keys/secureboot boot.img
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="directory-structure-expected-by--k">Directory Structure Expected by &lt;code>-k&lt;/code>&lt;/h4>
&lt;pre tabindex="0">&lt;code>/path/to/keys/
├── dev.key &amp;lt;-- Private key (used by mkimage)
├── dev.crt &amp;lt;-- X.509 certificate (optional)
├── dev.pub &amp;lt;-- Public key (for embedding in U-Boot, or image)
&lt;/code>&lt;/pre>&lt;p>The filename prefix (&lt;code>dev&lt;/code>) maps to the key-name in the &lt;code>.its&lt;/code> file.&lt;/p></description></item><item><title>RSA</title><link>https://blog.rishavs.in/posts/rsa/</link><pubDate>Fri, 18 Oct 2024 10:46:00 +0000</pubDate><guid>https://blog.rishavs.in/posts/rsa/</guid><description>&lt;p>&lt;strong>RSA (Rivest–Shamir–Adleman)&lt;/strong> is an asymmetric cryptographic algorithm, widely used for secure data transmission, especially for signing and encrypting data.&lt;/p>
&lt;p>In the RSA signing process, a &lt;strong>private key&lt;/strong> is used to sign the message, while a &lt;strong>public key&lt;/strong> is used to verify the signature. Here&amp;rsquo;s how the signing and verification process works:&lt;/p>
&lt;h3 id="1-public-and-private-keys">1. Public and Private Keys&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Private Key&lt;/strong>: This key is kept secret and is used to sign data. Only the entity that owns the private key should be able to generate the signature.&lt;/li>
&lt;li>&lt;strong>Public Key&lt;/strong>: This key is shared with others. It is used to verify that the data was indeed signed by the corresponding private key holder.&lt;/li>
&lt;li>&lt;strong>Key Pair&lt;/strong>: RSA works on a pair of keys(one private and one public). A unique public/private key pair is generated together. There cannot be multiple private keys for a given public key.&lt;/li>
&lt;/ul>
&lt;p>For embedded systems, where resources (CPU, memory) are limited, RSA’s asymmetric nature means that only the private key holder can sign, while anyone with the public key can verify. This is useful in &lt;strong>secure boot processes&lt;/strong> or &lt;strong>authenticating firmware updates&lt;/strong>, as the system can verify code signed by the vendor.&lt;/p></description></item></channel></rss>