Automatically flashing eMMC after booting from SD - beagleboneblack

I created NEW.img, a custom Debian image (Mender converted) for our Beaglebone Green Wireless fleet. I am successfully able to flash the Beaglebone eMMC by copying that NEW.img to an SD card which has the standard bootable console image, booting from that SD card, logging in, and manually executing:
sudo dd if=NEW.img of=/dev/mmcblk1 bs=1M status=progress && sudo sync
This correctly flashes a bootable eMMC with all 4 partitions.
How can automate this? I'd like to create an SD card which automatically executes this dd flashing after boot. I have created flasher SD cards for the Beaglebone before by uncommenting the last line in /boot/uEnv.txt where it calls the init-eMMC-flasher-v3.sh script which uses functions.sh and I don't understand this script. It doesn't seem to pull from an *.img image file. Is there a way to execute that dd command above, or update the script so that it flashes the eMMC from NEW.img?

Related

Error installing Nvidia Drivers Fedora 35 Kernel 5.16.15

Spent three days trying to install nvidia graphic card drivers in Fedora 35 running on kernel 5.16. I was installing from the download .run file which threw error 'MIGRATE_PFN_LOCKED' undeclared in /var/lib/dkms/nvidia/495.46/build/make.log
I tried installing without enabling dkms but still couldn't install the drivers
systemctl set-default multi-user.target
then
systemctl reboot
as root user. On logging in, change directory to where you download .run installer for your Nvidia graphic card and run below
sh ./NVIDIA-Linux-x86_64-XXX.XX.run --extract-only
Above extract the installer file which will give us ability to edit the driver source code. Use your favorite editor to open the file uvm_migrate_pageable.c which is located in your extracted driver folder as below:
kernel/nvidia-uvm/uvm_migrate_pageable.c
My favorite editor is vim, so in my case, I will open it for editing as below:-
vim /NVIDIA-Linux-x86_64-XXX.XX/kernel/nvidia-uvm/uvm_migrate_pageable.c
Add below lines on declaration part of the source file or before where it is referenced in this c source file.
#ifndef MIGRATE_PFN_LOCKED
#define MIGRATE_PFN_LOCKED 0
#endif
save the file and now run your driver as below while inside the folder we extracted:
./nvidia-installer
Installation process should now complete without any errors and you can now revert to your X windowing system by running the command:
systemctl set-default desktop.target
References:
https://bbs.archlinux.org/viewtopic.php?id=271400
https://github.com/torvalds/linux/commit/ab09243aa95a72bac5c71e852773de34116f8d0f
Issue: The NVIDIA team do not yet have support for kernel 5.16.15 for the time being.
Solution: Patch the current installer yourself by running below, note that you must have x disabled probably by logging into your fedora via text mode which can be achieved by running the command

How to write new MLO and u-boot.img to an SD card without erasing the OS

I have an SD card with a standard Beaglebone Debian image. I also have the MLO and u-boot.img files from building u-boot. I'd like to install the new u-boot on the SD card and then flash the modified image to MMC on a Beaglebone Black.
I can flash onboard MMC from the SD card just fine. I can also connect to the board over serial and stop in u-boot.
What I don't know how to do is write the new u-boot to the SD card correctly. I've tried a few things:
These elinux instructions are for erasing the SD card and creating a new bootable partition. I didn't actually try this because I want to install the new u-boot to an existing image.
$ echo -e "o\nn\np\n1\n\n+64M\na\n1\nt\nc\nw\n" | sudo fdisk /dev/MYDISK ; sudo fdisk /dev/MYDISK -l
$ sudo mount /dev/MYDISK /mnt
$ sudo cp MLO /mnt
$ sudo cp u-boot.img /mnt
$ sudo sync
$ sudo umount /mnt
These digikey instructions are a different version of the same thing. I tried writing MLO and u-boot.img in this way, without erasing the disk, but the board still boots using the original u-boot instead of the new one.
$ sudo dd if=/dev/zero of=${DISK} bs=1M count=10
$ sudo dd if=./u-boot/MLO of=${DISK} count=1 seek=1 bs=128k
$ sudo dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 bs=384k
These beyondlogic instructions have a slightly different pair of dd commands. I tried these as well, but again the board still boot susing the original u-boot.
$ sudo dd if=MLO of=/dev/sdb bs=512 seek=256 count=256 conv=notrunc
$ sudo dd if=u-boot.img of=/dev/sdb bs=512 seek=768 count=1024 conv=notrunc
$ sudo blockdev --flushbufs /dev/sdb
Someone suggested that I write the new u-boot to MMC using tftp. Can I use the same procedure to write to the SD card? If so, how do I find the start addresses? And how to I load and write the files? I tried searching, but I didn't find what I needed.
- boot into u-boot
- discover the existing MLO and uboot.img start addresses
- load the new MLO and uboot.img into RAM using tftp
- write the new MLO and uboot.img to the correct location in MMC
Additional Notes
Ideally, I would like to write the new u-boot to the SD card and test it without flashing. Supposedly the beaglebone will boot the SD card u-boot (instead of the MMC u-boot) if you press S2 when you supply power, but I'm not sure if that is working. How can I tell which u-boot is loaded?
However, I can write the MMC image to an SD card, so it would also work to write the new u-boot to MMC and test that.
Lastly, I'm willing to erase the SD card, write u-boot with one of the above methods, and manually setup/write the partitions if I have to. Is that the only way to do this?
SD Card / Image
The SD card contains the Debian 7.9 2015-11-12 firmware image from beagleboard latest images.
This is the partition table.
Model: Generic- USB3.0 CRW -SD (scsi)
Disk /dev/sdb: 31.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 102MB 101MB primary fat16 boot, lba
2 102MB 3565MB 3463MB primary ext4
The boot partition does not contain MLO or u-boot.img files to replace:
total 96
drwxr-xr-x 2 root root 2048 Nov 12 2015 App
-rwxr-xr-x 1 root root 288 Nov 12 2015 autorun.inf
drwxr-xr-x 4 root root 2048 Nov 12 2015 Docs
drwxr-xr-x 5 root root 2048 Nov 12 2015 Drivers
-rwxr-xr-x 1 root root 40 Nov 12 2015 ID.txt
-rwxr-xr-x 1 root root 41174 Nov 12 2015 LICENSE.txt
-rwxr-xr-x 1 root root 1008 Nov 12 2015 nfs-uEnv.txt
-rwxr-xr-x 1 root root 16838 Nov 12 2015 README.htm
-rwxr-xr-x 1 root root 428 Nov 12 2015 README.md
drwxr-xr-x 2 root root 2048 Nov 12 2015 scripts
-rwxr-xr-x 1 root root 16838 Nov 12 2015 START.htm
-rwxr-xr-x 1 root root 1179 Nov 12 2015 uEnv.txt
What I don't know how to do is write the new u-boot to the SD card correctly.
...
The SD card contains the Debian u have7.9 2015-11-12 firmware image from beagleboard latest images.
The crux of your problem is that the ROM boot code of the AM335x SoC is capable of reading the MLO from the SD card (or eMMC) in either raw sector mode or in FAT file mode. Additionally in raw mode there are four possible areas to locate the boot image, although when the first sector of the medium contains the MBR, then there are only three areas.
The AM335x SoC will check for a boot image using raw mode first.
So if you want to install the MLO as a file in the FAT filesystem, then you have to ensure that any previous MLO stored in raw sectors are removed.
IOW there are multiple ways of storing the MLO on eMMC/SD card, and the order in which they are checked determines which image is used to boot. The FAT file would be the last image in the boot order.
The SD card with the Debian image that you have stores the MLO and u-boot.img as raw sectors (i.e. note that the FAT filesystem starts at sector 2049, offset 0x100000, so there are unallocated sectors preceding that first partition).
[Note that sector numbering starts with 1, not 0.]
The existing MLO on your SD card is stored at sector 257 (offset 0x20000 or 128K) which includes a sector for its TOC (Table of Contents) and an eight-byte GP header.
The existing u-boot.img on your SD card is stored at sector 769 (offset 0x60000 or 384K).
You can replace both of these images using the beyondlogic instructions, as the seek= displacements are correct for what already exists on your SD card.
The Digikey instructions specify similar seek= displacements but use different blocksizes and counts. The first command would also remove the MBR (and render the FAT and ext filesystems inaccessible).
Alternatively you could zero-out the TOC so that raw mode would fail and then the ROM boot would revert to FAT file mode.
You could then dispense with dd commands and sector offsets, and use ordinary filesystem commands.
Your SD card has only one TOC to eliminate, so one command would suffice:
dd if=/dev/zero bs=512 count=1 seek=256 of=/dev/sdX
If you didn't know where the image was located, then clearing the other possible areas would be necessary:
dd if=/dev/zero bs=512 count=1 seek=512 of=/dev/sdX
dd if=/dev/zero bs=512 count=1 seek=768 of=/dev/sdX
How can I tell which u-boot is loaded?
Do you mean which U-Boot image is executed/booted?
Wouldn't the version string (with build timestamp) that U-Boot displays on start-up indicate which image has been booted?
However, this bootloader isn't written to the MMC by the provided script, so it doesn't actually solve the problem.
The only "problem" I read is stated in your title.
Clarification
Although you may be able to locate/store the MLO at raw sectors or as a FAT file on eMMC or SD card, where you store the u-boot.bin image is dictated by how the U-Boot SPL was configured/built. (The MLO is simply the U-Boot SPL preceded with 520 bytes for a Table of Contents and GP header.)
For instance the default U-Boot configuration for the BBB will build a SPL/MLO that will expect the u-boot.bin to be stored at raw sector 0x300 (or 769 when properly not counting from zero).
I.E. from the .config file:
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x300
This seems to be the same configuration as the Debian SD card image that you are using.
If you want to store the u-boot.bin image as a file in the FAT filesystem of the SD card, then you would have to reconfigure the U-Boot SPL (i.e. make menuconfig) and rebuild to obtain a new MLO.
This is the information that I couldn't find anywhere.
Refer to chapter 26.1.8.5 MMC/ SD Cards of the AM335x and AMIC110 Sitara Processors Technical Reference Manual.
If you are using init-eMMC-flasher-v3.sh to flash the SD card to MMC, you can just copy the MLO and u-boot.img files to /opt/backup/uboot on the SD card. In addition to setting up the partitions and writing the rootfs, the script writes the MMC bootloader using these files if they are present.
It is not necessary to install the new u-boot to the SD card. It is also not necessary to boot the board using the SD card bootloader.
You may need to update the flasher scripts on the SD card by running git pull in /opt/scripts.
So, assuming the SD card drive is /dev/sdb:
$ mount /dev/sdb2 /mnt/sd
$ cp MLO /mnt/sd/opt/backup/uboot
$ cp uboot.img /mnt/sd/opt/backup/uboot
$ cd /mnt/sd/opt/scripts
$ git pull
$ umount /mnt/sd
And of course edit uEnv.txt to enable the eMMC flasher.
Then you can insert the SD card into the beaglebone and power on. Both the new bootloader and the SD card rootfs will be written to MMC.

Commands for reading, loading and unloading drivers on BeagleBone Black?

I am using a BeagleBone Black with Xenomai and RTnet on top. As some real-time programs are not working it could be that the installed drivers on my BeagleBone Black are still the standard drivers and not the real-time drivers.
As I did not find anything on internet (only how to install drivers for Windows when using BeagleBone Black) I would like to ask you if anybody knows a command for BeagleBone Black to read, load and unload installed drivers on BBB?
I have found the commands for read, load and unload driver/modules. See the following output of the command window: the commands are lsmod for reading, insmod for loading and rmmod for unloading.
# lsmod
Module Size Used by Tainted: G
rtipv4 18699 0
rtpacket 4179 0
rt_ticpsw 26115 0
rt_davinci_mdio 4570 0
rt_smsc 2165 0
rtnet 28479 3 rtipv4,rtpacket,rt_ticpsw
omap_rng 4174 0
# insmod
BusyBox v1.22.1 (2019-03-16 12:39:06 CET) multi-call binary.
Usage: insmod FILE [SYMBOL=VALUE]...
Load the specified kernel modules into the kernel
# rmmod
BusyBox v1.22.1 (2019-03-16 12:39:06 CET) multi-call binary.
Usage: rmmod [-wfa] [MODULE]...
Unload kernel modules
-w Wait until the module is no longer used
-f Force unload
-a Remove all unused modules (recursively)
#

How to take screenshot from command line on BBB Angstrom

Hi I have a BBB which is running on Angstrom 2013 image. For display purpose I am using a cape which is connected to gpio extensions. There is a Qt application running on BBB, which use to get displayed on the Cape.
How can I take screenshot of the cape.
I want to take some screen-shot of the running application.
I couldn't find gnome-screenshot on angstrom image, using import command to take screenshot I got an error regarding x11.
How can I get the screenshot?
You can try and install scrot
On Ubuntu based Beagle Bone Black, I installed it as follows:
sudo apt-get install scrot
To Capture a screenshot:
scrot -q 100 /home/debian/Desktop/Desktop.jpg
#-q 100 == best quality
# /home/debian/Desktop/Desktop.jpg is path where to store captured screenshot
For more information, you can read this tutorial here.

make an lp script into functioning printer

I'm trying to print to separate printers simultaneously in Ubuntu 14.04
From all of my reading the best option I've seen is to write a script
that sends an lp command to the separate printers.
This is the script I've written so far
!/bin/bash
lp -d printer "$#"
lp -d printer2 "$#"
where printer and printer 2 are the actual printers installed on the system
This script works from a terminal, however I would like to be able to send print jobs directly to a "printer" that is actually the script I've written.
How can I make this lp script into a "printer"
Ok I didn't find a way to do this the way I originally intended, however it is possible with tea4CUPS
great cups backend tool with an easy config file
http://www.pykota.com/software/tea4cups/download
The install instructions are on the download page.
As for printing to multiple printers, add this command in the config file for every printer you wish to print to.
prehook_firstprinter: /usr/bin/lp -d Name of Printer -o raw $TEADATAFILE
Here are the simplest instructions I could write
1. download the tea4cups.gz
Extract it to the home folder, rename it to tea4cups
Open a terminal and run these commands
sudo cp /home/manifester/tea4cups/tea4cups.conf /etc/cups
sudo cp /home/manifester/tea4cups/tea4cups /usr/lib/cups/backend/
sudo chmod 700 /usr/lib/cups/backend/tea4cups
Run this command
sudo gedit /etc/cups/tea4cups.conf
Paste this in the bottom of the document
prehook_firstprinter: /usr/bin/lp -d Name of Printer yes the literal name in the printer window -o raw $TEADATAFILE
you will need a new line for every printer you have, so if you want to print to 3 printers you will need three of the above line each having the name of the printer it will be talking to.
save and close everything
open a terminal and run
sudo service cups restart
open a web browser and go to the browser cups controller
http://localhost:631/admin
go to Add Printer
you should see a printer named "tea4CUPSnothing"
If you don't see it go back and press "Find Printers"
it should be there
Change the info of the printer to "Print all" for all type fields"
Press Continue
The generic printer driver works because the printer doesn't actually exist.
Press Continue
Set Defaults
you should be done, go to your printer window on ubuntu and do a test print.

Resources