U-Boot bootcmd (auto vs manual) - embedded-linux

I'm running into an issue where when I power up my device, it hangs at
Starting kernel ...
Or it loops with
Starting kernel ...
resetting ...
However, if I interrupt the boot process and manually run boot, ie:
=> run bootcmd
or
=> boot
then the kernel loads fine.
According to DENX (5.9.6.5) this is equivalent to what Uboot should be doing automatically.
Does anyone know if there is a difference between letting uboot run on it's own and interrupting and running boot manually? Otherwise, how do I start debugging this?
ENVIRONMENT
=> printenv
autoload=no
baudrate=115200
board_name=EVK
board_rev=pilot
boot_fdt=try
bootcmd=echo Booting from network ...; usb start; setenv ethact asx0; if dhcp && tftp $loadaddr $bootfile && tftp $f
dt_addr $fdt_file; then run nfsboot; else echo WARN: Issue with TFTP.; run sdboot; fi;
bootdelay=3
bootfile=zImage
bootscript=echo Running bootscript from mmc ...; source
console=ttymxc1
ethact=asx0
ethprime=FEC
fdt_addr=0x83000000
fdt_file=imx6ul-pilot-v1-evk.dtb
fdt_high=0xffffffff
image=zImage
initrd_high=0xffffffff
ip_dyn=yes
loadaddr=0x80800000
loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};
loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
mmcargs=setenv bootargs console=${console},${baudrate} root=${mmcroot}
mmcautodetect=yes
mmcboot=echo Booting from mmc ...; run mmcargs; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then bootz ${loadaddr} - ${fdt_addr}; else if test ${boot_fdt} = try; then bootz; else echo WARN: Cannot load the DT; fi; fi; else bootz; fi;
mmcdev=1
mmcpart=1
mmcroot=/dev/mmcblk1p2 rootwait rw
netargs=setenv bootargs console=${console},${baudrate} root=/dev/nfs ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp
nfsboot=run netargs; bootz $loadaddr - $fdt_addr
nfsroot=/nfs/rootfs
script=boot.scr
sdboot=echo Booting from mmc ...; mmc dev ${mmcdev}; mmc dev ${mmcdev}; if mmc rescan; then if run loadbootscript; then run bootscript; else if run loadimage; then run mmcboot; else echo ERROR: Cannot run loadimage; fi; fi; else run ERROR: Cannot run mmc rescan; fi;
serverip=192.168.0.219
Environment size: 1714/8188 bytes

This issue was with the SDBOOT env var:
sdboot = echo Booting from mmc ...; mmc dev ${mmcdev}; mmc dev ${mmcdev};
if mmc rescan; then
if run loadbootscript; then
run bootscript;
else
if run loadimage; then
run mmcboot;
else
echo ERROR: Cannot run loadimage;
fi;
fi;
else
echo ERROR: Cannot run mmc rescan;
fi;
Load bootscript kept failing with "** Unable to read file boot.scr **". I'm still not sure what was causing the difference but removing the loadbootscript branch and going straight to loadimage fixed the issue.

Related

Ubuntu Server 21.10 - How to run Shell Script when plugging USB device

I would like to run a specific script when plugging a USB device. But, nothing happens when I a USB device.
Here is the script I would like to run ( /home/update.sh ):
#!/bin/sh
netplan apply
In the same directory, I made it executable by running:
sudo chmod +x update.sh
I updated the udev rule file ( /etc/udev/rules.d/70-snap.snapd.rules ) by adding the following line after LABEL="mm_mbm_check" :
ACTION=="add", ATTRS{idVendor}=="`****`", ATTRS{idProduct}=="`****`", RUN+="/home/update.sh"
As far as I understand, I'm using the * to allow any usb device.
After updating this udev rule file, I run the following script to apply the rules:
sudo service udev restart
Here is the log from syslog after running the restart udev command ( tail -f /var/log/syslog ):
Nov 8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:14 Invalid value "/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if cmp -s $ALIASES/uart0 $ALIASES/serial0; then echo 0;elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then echo 1; else exit 1; fi'" for PROGRAM (char 58: invalid substitution type), ignoring, but please fix it.
Nov 8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:27 Invalid value "/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if [ -e /dev/ttyAMA0 ]; then exit 1; elif cmp -s $ALIASES/uart0 $ALIASES/serial0; then echo 0;elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then echo 1; else exit 1; fi'" for PROGRAM (char 97: invalid substitution type), ignoring, but please fix it.
Nov 8 19:52:20 ubuntu systemd-udevd[23328]: /usr/lib/udev/rules.d/90-pi-bluetooth.rules:38 Invalid value "/bin/sh -c 'ALIASES=/proc/device-tree/aliases; if cmp -s $ALIASES/uart1 $ALIASES/serial0; then echo 0; elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then echo 1; else exit 1; fi '" for PROGRAM (char 58: invalid substitution type), ignoring, but please fix it.
Finally, when I plug the USB device to the Raspberry, nothing happens.
My configuration:
Raspberry Pi 3
Ubuntu Server 21.10
Thanks for your help !
Everything is correct, except the added rule in the file /etc/udev/rules.d/70-snap.snapd.rules .
To make it works, I added a new file 90-usb.rules in the /etc/udev/rules.d/ directory including the following rule:
ACTION=="add", ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", RUN+="/home/update.sh"
instead of
ACTION=="add", ATTRS{idVendor}=="`****`", ATTRS{idProduct}=="`****`", RUN+="/home/update.sh"
I restarted the udev using the following script:
sudo service udev restart
And now, when I'm plugging any USB device, my script is running.

How to save U-Boot environment variable persistently?

I have following U-Boot environment variables:
nas220> printenv
autoload=no
autostart=no
baudrate=115200
bootargs=console=ttyS0,115200
bootargs_base=console=ttyS0,115200
bootcmd=run bootcmd_nand
bootcmd_nand=setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a40000#0x5c0000(rootfs)
bootcmd_rescue=setenv bootargs_extra rescue/enable=true; run bootcmd_usb
bootcmd_usb=setenv bootargs ${bootargs_base} ${mtdparts} ${bootargs_extra}; usb start; fatload usb 0:1 0x40000 uImage-dtb; fatload usb 0:1 0x800000 uInitrd; bootm 0x40000 0x800000
bootdelay=3
ethact=egiga0
ethaddr=00:10:75:07:0D:8D
ethadr=00:10:75:07:0D:8D
mtdids=nand0=orion_nand
mtdparts=cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a40000#0x5c0000(rootfs)
stderr=serial
stdin=serial
stdout=serial
Environment size: 876/65532 bytes
I need to change the bootcmd_nand variable from:
setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a40000#0x5c0000(rootfs)
to
setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a30000#0x5c0000(rootfs)
however when I try to run:
setenv bootcmd_nand setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a30000#0x5c0000(rootfs)
The system reads from the nand and boots so I'm not able to run the saveenv command to save the changes persistently.
How to I make the change without the system booting?
I figured out my mistake, but leaving the question up in case anyone else comes across this. To run a setenv command without actually running the code you just have the enclose the variable in single quotes. For example running,
setenv bootcmd_nand setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a30000#0x5c0000(rootfs)
will run the code and read from the nand not saving the variable permanently. However running,
setenv bootcmd_nand 'setenv bootargs console=ttyS0,115200 cmdlinepart.mtdparts=orion_nand:0xa0000#0x0(uboot),0x010000#0xa0000(env),0x500000#0xc0000(uimage),0x1a30000#0x5c0000(rootfs)'
Sets the variable without running the code so I can run the saveenv and save permanently.

( Minishift CentOS VM on ec2 ) Error starting the VM: Error getting the state for host: unexpected EOF

I provisioned a CentOS VM on ec2 and installed Minishift but it doesn't start and I realize this has something to do with nested virtualization.
What exactly should I do to use this existing CentOS VM on ec2 to run minishift ?
What is a proven way to install MiniShift on a cloud VM ?
I am going to deploy only projects for experimenting.
I am connecting using 'ssh' from my Windows laptop.
-- Starting profile 'minishift'
-- Check if deprecated options are used ... OK
-- Checking if https://github.com is reachable ... OK
-- Checking if requested OpenShift version 'v3.11.0' is valid ... OK
-- Checking if requested OpenShift version 'v3.11.0' is supported ... OK
-- Checking if requested hypervisor 'kvm' is supported on this platform ... OK
-- Checking if KVM driver is installed ...
Driver is available at /usr/local/bin/docker-machine-driver-kvm ...
Checking driver binary is executable ... OK
-- Checking if Libvirt is installed ... OK
-- Checking if Libvirt default network is present ... OK
-- Checking if Libvirt default network is active ... OK
-- Checking the ISO URL ... OK
-- Checking if provided oc flags are supported ... OK
-- Starting the OpenShift cluster using 'kvm' hypervisor ...
-- Starting Minishift VM .... FAIL E0812 12:08:28.036276 17936 start.go:494] Error starting the VM: Error getting the state for host: unexpected EOF. Retrying.
Error starting the VM: Error getting the state for host: unexpected EOF
What is a proven way to install MiniShift on a cloud VM ?
GCP supports nested virtualization which is required to install Minishift. I think this was the reason for the failure of my procedure. Not sure if this is supported by AWS ec2 instances.
There may be other ways to install Minishift.
I am posting instructions to install MiniShift on a GCP VM instance. Please note
this is a collection of guidelines I found by searching. So they are available else where but I am answering because this really worked for me and it was easy.
I have deployed a sample successfully.
gcloud compute disks create minishiftdisk \
--image-project ubuntu-os-cloud \
--image-family ubuntu-1804-lts --zone asia-south1-a
gcloud compute images create nested-vm-image \
--source-disk minishiftdisk --source-disk-zone asia-south1-a \
--licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
gcloud compute instances create minishift-vm \
--zone asia-south1-a \
--machine-type=n1-standard-2 \
--boot-disk-size=50GB \
--min-cpu-platform "Intel Skylake" \
--image nested-vm-image
sudo apt-get update
sudo apt install qemu-kvm libvirt-daemon libvirt-daemon-system
curl -L https://github.com/minishift/minishift/releases/download/v1.34.1/minish
ift-1.34.1-linux-amd64.tgz -O
tar xvzf minishift-1.34.1-linux-amd64.tgz
sudo cp minishift-1.34.1-linux-amd64/minishift /usr/local/bin/
sudo curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v
0.10.0/docker-machine-driver-kvm-ubuntu16.04 -o /usr/local/bin/docker-machine-driver-kvm
sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
minishift start
radhakrishnan_mohan#minishift-vm:~$ minishift oc-env
export PATH="/home/radhakrishnan_mohan/.minishift/cache/oc/v3.11.0/linux:$PATH"
# Run this command to configure your shell:
# eval $(minishift oc-env)
radhakrishnan_mohan#minishift-vm:~$ eval $(minishift oc-env)
radhakrishnan_mohan#minishift-vm:~$ oc get pods
No resources found.
sudo apt install -y xfce4 xfce4-goodies firefox
sudo apt install -y xrdp
radhakrishnan_mohan#minishift-vm:~$ echo xfce4-session > ~/.xsession
radhakrishnan_mohan#minishift-vm:~$ sudo nano /etc/xrdp/startwm.sh
My script looked like this. I added the last line and saved it.
#!/bin/sh
# xrdp X session start script (c) 2015, 2017 mirabilos
# published under The MirOS Licence
if test -r /etc/profile; then
. /etc/profile
fi
if test -r /etc/default/locale; then
. /etc/default/locale
test -z "${LANG+x}" || export LANG
test -z "${LANGUAGE+x}" || export LANGUAGE
test -z "${LC_ADDRESS+x}" || export LC_ADDRESS
test -z "${LC_ALL+x}" || export LC_ALL
test -z "${LC_COLLATE+x}" || export LC_COLLATE
test -z "${LC_CTYPE+x}" || export LC_CTYPE
test -z "${LC_IDENTIFICATION+x}" || export LC_IDENTIFICATION
test -z "${LC_MEASUREMENT+x}" || export LC_MEASUREMENT
test -z "${LC_MESSAGES+x}" || export LC_MESSAGES
test -z "${LC_MONETARY+x}" || export LC_MONETARY
test -z "${LC_NAME+x}" || export LC_NAME
test -z "${LC_NUMERIC+x}" || export LC_NUMERIC
test -z "${LC_PAPER+x}" || export LC_PAPER
test -z "${LC_TELEPHONE+x}" || export LC_TELEPHONE
test -z "${LC_TIME+x}" || export LC_TIME
test -z "${LOCPATH+x}" || export LOCPATH
fi
if test -r /etc/profile; then
. /etc/profile
fi
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
startxfce4
Restart xrdp
radhakrishnan_mohan#minishift-vm:~$ sudo service xrdp restart
Change password for root
sudo su
passwd
Windows Remote Desktop connection
Once I connected to the GCP VM instance's public IP I was able to login using the credentials root/password
Start firefox from the linux desktop and login to OpenShift

Systemd output in Docker without -t switch

When Docker image is started in terminal mode like:
docker run --mount type=tmpfs,destination=/run --mount type=tmpfs,destination=/run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro --entrypoint '/bin/bash' -it jrei/systemd-debian:10
and then manually entered:
exec /lib/systemd/systemd
systemd displays the init log like:
ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
Detected virtualization docker.
Detected architecture x86-64.
Welcome to Debian GNU/Linux 10 (buster)!
Set hostname to <e9366e98a874>.
File /lib/systemd/system/systemd-journald.service:12 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
[ OK ] Reached target Slices.
[ OK ] Started Dispatch Password Requests to Console Directory Watch.
[ OK ] Reached target Swap.
[ OK ] Reached target Local File Systems.
Starting Create System Users...
[ OK ] Reached target Local Encrypted Volumes.
[ OK ] Reached target Paths.
....
When Docker image is started in WITHOUT terminal mode like:
docker run --mount type=tmpfs,destination=/run --mount type=tmpfs,destination=/run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro --entrypoint '/bin/bash' jrei/systemd-debian:10 -c "exec /lib/systemd/systemd"
systemd displays no output. I can not use the -t or -i switch as the docker command is hardwired in the command executor I am using. How should the command above be modified to start the systemd with output and still with PID 1 (wth exec directly from the entry shell) but without the -t Docker tty switch?

Shell script - exiting before completion

I have made a short shell script which launches a VM, sleeps some time to allow the VM to boot and then mounts a share at the VM on the host computer:
#!/bin/bash
nohup VBoxManage startvm "Ubuntu server" --type headless &&
sleep 60 &&
sudo mount -t cifs //192.168.1.1/www /media/ubuntuserver/
The VM is started properly and the script sleeps but no mount occurs and the script seems to just exit instead. What am I doing wrong?
is your sudo mount working in non-interactive mode? make sure this command is not asking any password
Add some logging so that you know what output is being returned
#!/bin/bash
nohup VBoxManage startvm "Ubuntu server" --type headless 2>&1 >> ~/script_log.txt &&
sleep 60 2>&1 >> ~/script_log.txt &&
sudo mount -t cifs //192.168.1.1/www /media/ubuntuserver/ 2>&1 >> ~/script_log.txt
replace ~/script_log.txt with any suitable log file path

Resources