RobertCNelson / boot-scripts

Just a bunch of useful scripts placed under /opt/scripts/
124 stars 131 forks source link

init-eMMC-flasher-v3.sh failing `are_we_flasher` check #138

Closed wohali closed 5 months ago

wohali commented 5 months ago

From a running v5.10 image on a BBB, I cloned this repo and ran tools/eMMC/beaglebone-black-make-microSD-flasher-from-eMMC.sh. I then used the resulting uSD card to flash a new (rev C3) BBB.

Similar to @RobertCNelson 's results here, the tool flashes correctly, but then in function.sh around line 315 incorrectly determines this is not a flasher image, but prints We are init and continues booting:

...
==> Setting LEDs to                                                                       
==> Displaying mount points                                                               
--------------------------------------------------------------------------------          
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)                                
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)                                 
udev on /dev type devtmpfs (rw,nosuid,relatime,size=218504k,nr_inodes=54626,mode=755)     
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)    
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=49504k,mode=755)           
/dev/mmcblk0p1 on / type ext4 (ro,relatime)                                               
--------------------------------------------------------------------------------          

================================================================================          
eMMC has been flashed: please wait for device to power down.                              
================================================================================          
We are init                                                                               
[  330.100807] Not activating Mandatory Access Control as /sbin/tomoyo-init does not exis.
[  330.382730] systemd[1]: System time before build time, advancing clock.                
[  330.446453] systemd[1]: systemd 247.3-7+deb11u4 running in system mode. (+PAM +AUDIT +)
[  330.471896] systemd[1]: Detected architecture arm.                                     
...

The line in /boot/uEnv.txt on the uSD card is:

cmdline=init=/opt/source/boot-scripts/tools/eMMC/init-eMMC-flasher-v3.sh

The only thing I can deduce is that /proc/cmdline is unavailable and the grep fails.

I've manually patched around this for now (by forcing it to always shut down after flashing) but something must be amiss.

RobertCNelson commented 5 months ago

So this old flasher is no longer used in our Debian 11.x+ images.. It was cleaned up and made more generic for both arm64 and armhf targets...

It is also now safe to shutdown in single user mode, with older system/kernel versions the pmic would not properly shutdown the system.

Today we shutdown via:

echo s > /proc/sysrq-trigger
echo o > /proc/sysrq-trigger

Here's the change: https://openbeagle.org/beagleboard/usr-customizations/-/commit/70cf4592763c6d1a61bf36a65221f562fdbabbb0

Two flashers, user space and via single user:

https://openbeagle.org/beagleboard/usr-customizations/-/tree/master/arm32/usr/sbin?ref_type=heads

for end device, and which direction the flash goes, we have example config files here: https://github.com/rcn-ee/repos/tree/master/bb-beagle-flasher/suite/bookworm/debian

this flasher is provided int the bb-beagle-flasher package in our apt repo

wohali commented 5 months ago

@RobertCNelson OK, so I'm now even more confused.

1) What is the correct process to take a working 11.x image and create a "auto-flasher" uSD image from it?

2) In that image, which script is being set up in uEnv as the init replacement?


EDIT: I am able to take an old image made with this repo's beaglebone-black-make-microSD-flasher-from-eMMC.sh, change the card's /boot/uEnv.txt so it references cmdline=init=/usr/sbin/init-beagle-flasher, and manually copying the contents of beaglebone-black-microsd-to-emmc to /etc/default/beagle-flasher on the card, and then that boots correctly. I also had to touch /etc/machine-id else I receive this error on boot over serial console:

[   27.314031] systemd[1]: System cannot boot: Missing /etc/machine-id and /etc is mounte.
[   27.323361] systemd[1]: Booting up is supported only when:                             
[   27.328969] systemd[1]: 1) /etc/machine-id exists and is populated.                    
[   27.335321] systemd[1]: 2) /etc/machine-id exists and is empty.                        
[   27.341318] systemd[1]: 3) /etc/machine-id is missing and /etc is writable.            

In case I didn't miss it, and there's no direct replacement, it would be nice if there was a single script I could run like the old beaglebone-black-make-microSD-flasher-from-eMMC.sh that would do this for me.

Meanwhile I am back to the C3 eth phy patch not working right, so I'll comment elsewhere on that.

RobertCNelson commented 5 months ago

For new images, the same script goes both ways..

sudo cp -v /etc/beagle-flasher/beaglebone-black-microsd-to-emmc /etc/default/beagle-flasher

Then run:

sudo enable-beagle-flasher

Now microSD is setup to auto-flash eMMC...

Now here's teh differentce, once you bootup in the eMMC... run...

sudo enable-beagle-flasher

it'll now 'flash' a microSD on every bootup..

going back and forth..

Now if you don't want to flash in single user mode (not recommended for docker/xorg/etc..) basic..

sudo cp -v /etc/beagle-flasher/beaglebone-black-microsd-to-emmc /etc/default/beagle-flasher

and

sudo beagle-flasher

and microsd -> eMMC live..

Everything is in teh config file:

debian@41-am335x-bbbw:~$ cat /etc/default/beagle-flasher 
#debug_over_display=tty0
source=/dev/mmcblk0
destination=/dev/mmcblk1
rfs_partition=single
rfs_rootfs_type=ext4
rfs_rootfs_startmb=4
bootloader=/opt/u-boot/bb-u-boot-am335x-evm/install-mmcblk1.sh
flash_back=beaglebone-black-emmc-to-microsd

source and destination rfs type...

bootloader to install on target flash_back... version of /etc/default/beagle-flasher copied at the end to go back to the other way..

Regards,

RobertCNelson commented 5 months ago
What is the correct process to take a working 11.x image and create a "auto-flasher" uSD image from it?

1: Boot with microSD blank eMMC...

sudo apt update
sudo apt install bb-beagle-flasher bb-u-boot-am335x-evm
sudo cp -v /etc/beagle-flasher/beaglebone-black-microsd-to-emmc /etc/default/beagle-flasher
sudo enable-beagle-flasher
sudo systemctl poweroff

1: Boot with eMMC, blank microSD installed

sudo apt update
sudo apt install bb-beagle-flasher bb-u-boot-am335x-evm
sudo cp -v /etc/beagle-flasher/beaglebone-black-emmc-to-microsd /etc/default/beagle-flasher
sudo beagle-flasher
sudo systemctl poweroff

2: Boot with microSD, prep for auto-flashing

sudo enable-beagle-flasher
sudo systemctl poweroff

that...