LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   How to boot Linux from Scratch on Beaglebone Black via SD card? (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/how-to-boot-linux-from-scratch-on-beaglebone-black-via-sd-card-4175648031/)

ordealbyfire83 02-10-2019 04:36 PM

How to boot Linux from Scratch on Beaglebone Black via SD card?
 
As the title suggests, I would like to boot LFS or some arbitrary GNU/Linux distribution on a Beaglebone Black from the microSD card. (To be clear, I have LFS compiled, and now I'd just like to be able to boot it.) There are any number of tutorials on how to boot from the microSD slot, but these tutorials all use wildly diverging methods and most are geared towards downloading off-the-shelf distributions where the boot procedure seems intertwined into the specific OS at hand. Not to mention, some of them are hard to follow and read like jerk textbooks, leaving the most common use cases as exercises to the reader, while highlighting esoteric things like TFTP.

We know that the following is needed MLO, u-boot.img, uEnv.txt, dtb, kernel, and so on. My question is how to make this work in 2019.

What is to be done with the SD card? How is it to be partitioned? Some say to make a FAT partition (using some weird script that automagically finds some secret size) and put the u-boot related things there, others say to write it using dd to sectors < 2048 with brute force. I've tried both ways and nothing works.

Secondly, can you use a stock kernel without recompiling? Compiling u-boot for BBB typically uses some bootz patches so is uImage not mandatory? In the config file I don't see anything enabling bootz, so I assumed it is.

In short there are too many independent variables at work here to try tweaking one at a time. Has anyone actually done this, and if so, would you be so kind as to say what works? Thanks in advance.

ericgreenwood123 02-11-2019 11:13 AM

I have not done this, but i have just managed to get Archlinux ARM working on a Chromebook with similar hardware.
This tutorial explains how to get U-Boot on an SD card: https://archlinuxarm.org/platforms/a...ung-chromebook, although the supplied kernel probably will not work for your hardware.
Also have you seen this: http://www.bootembedded.com/embedded...glebone-black/ which i think explains it quite well.
and this: http://beagleboard.org/getting-started which gives you a pre-made version of Debian.

Hope this helps,
Eric.

ordealbyfire83 02-11-2019 01:02 PM

Thank you for those links - despite searching with several engines the 'bootembedded' technique never showed up for me. Long story short, I actually got this to work by following this method using a pre-made Ubuntu image. The primary issues are that they do not provide sources for u-boot or explain how it was compiled (patched or not), nor is it specified how the kernel was made. (By this, I do not mean the .config file, but rather what was run on the command line after "make.")

In terms of physically getting the BeagleBone to boot from the sd card, I had some trouble. The tutorials say just to press and hold the S2 button - which itself is a chore - while applying power. I use a 5V transformer and this was not happening. I found I had to do something like this

- Press and hold S2 for about 3 seconds
- Plug in transformer
- Keep holding S2 for another 3 seconds
- Wait another 3 seconds
- Unplug transformer and wait 5-10 seconds
- Plug in transformer (and do not press S2)

and then at the very least it would attempt to do something.

There are several versions of u-boot as well as partition layouts described in the tutorials. The partitioning script described on the gentoo wiki is not the least bit self-evident and seems not necessary. Whether or not you need to recompile the kernel depends on how you configure u-boot.

U-boot in itself expects a uImage to be present. Patching u-boot with the patch mentioned below introduces a 'bootz' method capable of booting a zImage. When you build a kernel using most normal methods, you'll end up with a bzImage which won't work. Furthermore, the mentioned patch does not require bootz to be declared in the uEnv.txt. There is also confusion over whether you need u-boot.img or u-boot.bin.

U-boot instructions, to build natively on the Beaglebone Black (not cross-compiled).

Code:

# Get u-boot (use this version) and the corresponding patch:

wget ftp://ftp.denx.de/pub/u-boot/u-boot-2015.10.tar.bz2
wget https://rcn-ee.com/repos/git/u-boot-patches/v2015.10/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

tar -xjf u-boot-2015.10.tar.bz2
cd u-boot-2015.10
patch -Np1 -i ../0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
make distclean
make am335x_boneblack_config
make

Now partition the sd card. The first partition is for u-boot while the second is your OS file system. Use fdisk to make these partitions, with the first beginning at 2048 and end at 4095 - yes, that small... The next can be whatever size you need for your OS but it should begin on the next sector, 4096. You can also have more partitions if they are needed.

Make a fat32 file system in the first partition, and ext4 for the second (I've not tested ext3 yet).

In the first partition (fat32), the structure should be like this:

MLO
u-boot.img
uEnv.txt

MLO and u-boot.img are copied from the parent directory of the u-boot source tree, which were built in the above step. uEnv is a plain text file which from the above ubuntu method contains the following:

Code:

optargs=
loadfdt=load mmc ${mmcdev}:2 ${fdtaddr} /boot/dtbs/${fdtfile}
loaduimage=mw.l 4804c134 fe1fffff; if load mmc 0:2 ${loadaddr} /boot/zImage; then setenv mmcdev 0; mw.l 4804c194 01200000; echo Booting from external microSD...; else setenv mmcdev 1; if test $mmc0 = 1; then setenv mmcroot /dev/mmcblk1p2 rw; fi; load mmc 1:2 ${loadaddr} /boot/zImage; mw.l 4804c194 00c00000; echo Booting from internal eMMC...; fi
mmcboot=run mmcargs; bootz ${loadaddr} - ${fdtaddr}
uenvcmd=i2c mw 0x24 1 0x3e; run findfdt; if test $board_name = A335BNLT; then setenv mmcdev 1; mmc dev ${mmcdev}; if mmc rescan; then setenv mmc1 1; else setenv mmc1 0; fi; fi; setenv mmcdev 0; mmc dev ${mmcdev}; if mmc rescan; then setenv mmc0 1; else setenv mmc0 0; fi; run loaduimage && run loadfdt && run mmcboot

In other words, you won't figure that out on your own by reading uBoot or TI documentation, and anyone who wants this posted outright must be immoral and illegally got paid to do some sixth grader's science project for him. But seriously, the goal here is to boot the Beaglebone Black in a similar manner as with the stock operating system, connected to the network, and logged in via ssh. Yet none of the tutorials other than the bootembedded even seem to give reasonable hints.

We get by using just these three files, because uEnv.txt specifies that the other files can be placed in the /boot directory of the OS, on the second partition. So, in the OS /boot directory, we can have

The kernel stuff:
config-xxx
System.map-xxx
vmlinuz-xxx (!)
zImage <- where this is a symlink to vmlinuz-xxx

Also in /boot, we have a subdirectory entitled dtbs.
In the ubuntu tutorial, they include the entire contents of this directory found on the stock OS. I find that we can just get by using the am335x_boneblack file, see below.

Also, in /boot, an empty directory entitled uboot.
This directory is intentionally left empty as the first partition can be mounted in here via the OS's /etc/fstab file.

Now for the kernel. If you use the patched u-boot, you can just use a zImage kernel, otherwise you'll need uImage. Building the kernel is generally straightforward if you have the appropriate sources and .config file. However this is not enough - you need to specify a LOADADDR when 'make' is run. For the Beaglebone Black, this is 0x80008000. You also must specify that the dtbs file gets built. So we configure the kernel as usual and then run 'make' like this:

Code:

make zImage dtbs LOADADDR=0x80008000
Replace zImage with uImage if needed. Or just use uImage as it also build zImage.

Then build the modules, but do not install them

Code:

make modules
make INSTALL_MOD_PATH=/some/directory modules_install

The last command places the modules in a directory of your choosing; you can zip this up in a tar archive and extract in your target OS.

The zImage | uImage is in arch/arm/boot. zImage can be renamed as vimlinuz-xxx and placed in your /boot directory. Then create the symlink entitled zImage pointing to this kernel image. The dtbs file is in arch/arm/boot/dts.

This should be reasonably OK, though I'm not too comfortable with the uEnv.txt. I will try the bootembedded method and see how that goes.


All times are GMT -5. The time now is 08:56 PM.