Difference between revisions of "PineNote Development/Booting Linux"

From PINE64
Jump to navigation Jump to search
m (Add note that this page only refers to batch 1)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
To boot linux, we need to patch stock uboot. I used [https://gist.github.com/charasyn/206b2537534b6679b0961be64cf9c35f charasyn's method], based off work from Dorian as credited in the script. We'll use the script to pull the uboot environment out of the stock uboot partition. We'll then apply the patch, recreate the image, add a configuration file, and flash the new image to the PineNote.
{{Note|This page is only relevant for the first batch of PineNotes, sold in 2021/2022! Batch 2 (2024) PineNote come with linux pre-flashed!}}


== Steps to patch uboot ==
To boot Linux, the stock U-Boot has to be patched.
<ol>
 
<li> Get the [https://gist.github.com/charasyn/206b2537534b6679b0961be64cf9c35f patch and the python tool]:
Here the method from [https://gist.github.com/charasyn/206b2537534b6679b0961be64cf9c35f charasyn] is used, based of work from Dorian as credited in the script. We'll use the script to pull the U-Boot environment out of the stock U-Boot partition. We'll then apply the patch, recreate the image, add a configuration file, and flash the new image to the PineNote.
<pre>
 
$ mkdir pinenote-uboot && cd pinenote-uboot
== Steps to patch U-Boot ==
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/boot-menu.patch -o boot-menu.patch
 
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/pinenote-uboot-envtool.py -o pinenote-uboot-envtool.py
1. Get the [https://gist.github.com/charasyn/206b2537534b6679b0961be64cf9c35f patch and the Python tool]:
$ chmod o+x pinenote-uboot-envtool.py
 
</pre>
$ mkdir pinenote-uboot && cd pinenote-uboot
</li>
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/boot-menu.patch -o boot-menu.patch
<li> Write your uboot partition to an img file: <code>dd if=/dev/mmcblk0p1 of=~/uboot.img</code></li>
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/pinenote-uboot-envtool.py -o pinenote-uboot-envtool.py
<li> Extract the environment: <code> ./pinenote-uboot-envtool.py extract uboot.img uboot.env</code></li>
$ chmod o+x pinenote-uboot-envtool.py
<li> Poke around the files (or skip this if you don't like to learn...):</li>
 
<ol>
2. Write your U-Boot partition to an image file: <code>dd if=/dev/mmcblk0p1 of=~/uboot.img</code>
<li> Open <code>uboot.env</code> -- see, it's just text at this point!</li>
 
<li> Open <code>boot-menu.patch</code> to get a feel for how that works</li>
3. Extract the environment: <code>./pinenote-uboot-envtool.py extract uboot.img uboot.env</code>
</ol>
 
<li> The boot-menu.patch makes assumptions about where your linux partition lives. Specifically, it will look at partition 0x11 (which is 17 in decimal). Change this in boot-menu.patch to reflect where your linux boot partition lives.</li>
4. Poke around the files (or skip this if you don't like to learn...):
<li> Apply boot-menu.patch: <code>patch uboot.env boot-menu.patch</code></li>
 
<ol>
# Open <code>uboot.env</code> -- see, it's just text at this point!
<li>This doesn't work for me for some reason:
 
<pre>
# Open <code>boot-menu.patch</code> to get a feel for how that works
$ patch uboot.env boot-menu.patch                                                           
 
patching file env.original
5. The boot-menu.patch makes assumptions about where your Linux partition lives. Specifically, it will look at partition 0x11 (which is 17 in decimal). Change this in boot-menu.patch to reflect where your Linux boot partition lives.
Hunk #3 FAILED at 24.
 
patch unexpectedly ends in middle of line
6. Apply boot-menu.patch: <code>patch uboot.env boot-menu.patch</code>
patch: **** unexpected end of file in patch at line 27
 
</pre>
{{Info|Note: Might fail with the following error: "''patch: **** unexpected end of file in patch at line 27''". In that case applying the patch manually is the solution.}}
I couldn't figure out what it's complaining about here, so I ended up applying the patch manually. It's pretty straight-forward.</li>
 
</ol>
7. Rewrite the new environment to the image: <code>./pinenote-uboot-envtool.py insert uboot.img uboot.env uboot-patched.img</code>
<li>Rewrite the new environment to the image: <code>./pinenote-uboot-envtool.py insert uboot.img uboot.env uboot-patched.img</code></li>
 
<li> Write the image to the boot partition from the pinenote: <code>dd if=~/uboot-patched.img of=/dev/mmcblk0p1</code></li>
8. Write the image to the boot partition from the PineNote: <code>dd if=~/uboot-patched.img of=/dev/mmcblk0p1</code>
<li> At this point, restarting your system will boot into Android -- this is because the patched uboot we've just created looks for <code>/boot/which_os.txt</code> to determine whether to boot android or linux, and since it can't find this file (we haven't made it yet), the bootloader defaults to android. Create that file on the same boot partition you specified in the boot-menu.patch file, placing an <code>l</code> in the file for linux.</li>
 
<li> Reboot into linux and go "wow"</li>
9. At this point, restarting your system will boot into Android -- this is because the patched U-Boot we've just created looks for <code>/boot/which_os.txt</code> to determine whether to boot Android or Linux, and since it can't find this file (we haven't made it yet), the bootloader defaults to Android. Create that file on the same boot partition you specified in the boot-menu.patch file, placing an <code>l</code> in the file for Linux.  
</ol>
 
10. Reboot into Linux


== Sources and further reading ==
== Sources and further reading ==
# [https://u-boot.readthedocs.io/en/latest/board/rockchip/rockchip.html U-boot with rockchip docs]
# [https://u-boot.readthedocs.io/en/latest/board/rockchip/rockchip.html U-boot with rockchip docs]
# [https://stackoverflow.com/questions/31244862/what-is-the-use-of-spl-secondary-program-loader Helpful stack overflow to learn a bit about the boot process/terminology]
# [https://stackoverflow.com/questions/31244862/what-is-the-use-of-spl-secondary-program-loader Helpful stack overflow to learn a bit about the boot process/terminology]
# [https://matrix.to/#/!QtTzSRYMuozjbOQkzJ:matrix.org/$bVBxdD3E01da7w4LRm45-mwbw_jPk6CrJTQWGMG3B2I?via=matrix.org&via=kde.org&via=tchncs.de This conversation in matrix between pgwipeout, vveapon, and pinenewb about flashing uboot.]
# [https://matrix.to/#/!QtTzSRYMuozjbOQkzJ:matrix.org/$bVBxdD3E01da7w4LRm45-mwbw_jPk6CrJTQWGMG3B2I?via=matrix.org&via=kde.org&via=tchncs.de This conversation in matrix between pgwipeout, vveapon, and pinenewb about flashing U-Boot.]
 
[[Category:PineNote]]

Latest revision as of 10:42, 26 November 2024

This page is only relevant for the first batch of PineNotes, sold in 2021/2022! Batch 2 (2024) PineNote come with linux pre-flashed!

To boot Linux, the stock U-Boot has to be patched.

Here the method from charasyn is used, based of work from Dorian as credited in the script. We'll use the script to pull the U-Boot environment out of the stock U-Boot partition. We'll then apply the patch, recreate the image, add a configuration file, and flash the new image to the PineNote.

Steps to patch U-Boot

1. Get the patch and the Python tool:

$ mkdir pinenote-uboot && cd pinenote-uboot
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/boot-menu.patch -o boot-menu.patch
$ curl https://gist.githubusercontent.com/charasyn/206b2537534b6679b0961be64cf9c35f/raw/cc513998a36fac0cea266260e3ca3e64abfe3696/pinenote-uboot-envtool.py -o pinenote-uboot-envtool.py
$ chmod o+x pinenote-uboot-envtool.py

2. Write your U-Boot partition to an image file: dd if=/dev/mmcblk0p1 of=~/uboot.img

3. Extract the environment: ./pinenote-uboot-envtool.py extract uboot.img uboot.env

4. Poke around the files (or skip this if you don't like to learn...):

  1. Open uboot.env -- see, it's just text at this point!
  1. Open boot-menu.patch to get a feel for how that works

5. The boot-menu.patch makes assumptions about where your Linux partition lives. Specifically, it will look at partition 0x11 (which is 17 in decimal). Change this in boot-menu.patch to reflect where your Linux boot partition lives.

6. Apply boot-menu.patch: patch uboot.env boot-menu.patch

Note: Note: Might fail with the following error: "patch: **** unexpected end of file in patch at line 27". In that case applying the patch manually is the solution.

7. Rewrite the new environment to the image: ./pinenote-uboot-envtool.py insert uboot.img uboot.env uboot-patched.img

8. Write the image to the boot partition from the PineNote: dd if=~/uboot-patched.img of=/dev/mmcblk0p1

9. At this point, restarting your system will boot into Android -- this is because the patched U-Boot we've just created looks for /boot/which_os.txt to determine whether to boot Android or Linux, and since it can't find this file (we haven't made it yet), the bootloader defaults to Android. Create that file on the same boot partition you specified in the boot-menu.patch file, placing an l in the file for Linux.

10. Reboot into Linux

Sources and further reading

  1. U-boot with rockchip docs
  2. Helpful stack overflow to learn a bit about the boot process/terminology
  3. This conversation in matrix between pgwipeout, vveapon, and pinenewb about flashing U-Boot.