Skip to content

Instantly share code, notes, and snippets.

@Scott31393
Last active May 3, 2025 03:02
Show Gist options
  • Save Scott31393/547510a8b0dbb9d1fddea1c59a7dbeb9 to your computer and use it in GitHub Desktop.
Save Scott31393/547510a8b0dbb9d1fddea1c59a7dbeb9 to your computer and use it in GitHub Desktop.

Linux Tips Cheatsheet

Create User and add to main group

$ sudo useradd -d <folder> <username>
$ sudo usermod -a -G <main-group> <username>
$ sudo passwd <username>
$ su <username>

Remove user

$ userdel username

Remount rw /system

mount -o remount,rw /system
touch /system/PIPPIPIPPO
mount -o remount,ro /system

Corrupted mmc/uSD

dd if=/dev/zero of=/dev/diskname bs=1k count=1
blockdev --rereadpt /dev/diskname

Mount .sdcard file

$ file -s file.sdcard 

file.sdcard: DOS/MBR boot sector; partition 1 : ID=0xc, active, start-CHS (0x80,0,1), end-CHS (0x3ff,3,32), startsector 16384, 170392 sectors; partition 2 : ID=0x83, start-CHS (0x3ff,3,32), end-CHS (0x3ff,3,32), startsector 196608, 206284 sectors 

$ sudo mount file.sdcard sd1/ -o offset=$((512*16384)) 

$ sudo mount file.sdcard sd2/ -o offset=$((512*196608)) 

Create Local http server

##HOST
$ sudo apt install apache2
$ sudo a2enmod userdir
$ mkdir -p ~/public_html/ostree/repo
$ sudo systemctl restart apache2.service
$ mkdir -p ~/public_html/ostree/build-webos
$ cd build-webos~/public_html/ostree/
$ echo "OSTREE_REPO = \"\${HOME}/public_html/test-folder\"" >> webos-local.conf
$ cp file ~/public_html/test-folder

To debug:

Open browser an test the following ip:

192.168.1.2 (Host pc router) 
192.168.1.2/~tom/ostree/public_html/test-folder

Script To Change zImage modules and dtb

Usage: script.sh sdd
if [ -z "$1" ]; then
    echo " Specify micro sd inode (eg: sdd)"
    exit
fi

dev=$1
echo ${dev}

sudo rm -vr /mnt/sd1/* /mnt/sd2/*
sync
sudo mount /dev/${dev}1 /mnt/sd1/
sudo mount /dev/${dev}2 /mnt/sd2/
sync
sudo rm -vr /mnt/sd2/lib/modules*
sync
sudo cp -vr MODULES/lib/ /mnt/sd2/
sync
sudo cp -v arch/arm/boot/dts/file*.dtb /mnt/sd1/
sync
sudo cp -v arch/arm/boot/zImage /mnt/sd1/
sync
sudo umount -v /mnt/sd*
sync

Copy u-boot and put into .sdcard

#Dump first 2MB
$ sudo dd if=/dev/sdd of=file.img bs=512 count=2000

#skip first 1k of input (using skip) put it into output skipping 1k (seek)
$ sudo dd if=file.img of=seco-image-base-seco-sbc-a62.wic bs=512 seek=2 skip=2 conv=notrunc

Hide/Remove cursor from Xorg

grep -rni /usr/bin/Xorg /etc
XSERVER=/usr/bin/Xorg
DISPLAY=:0
ARGS=" -br -pn  "
HOME=/home/root
USER=root
XSERVER=/usr/bin/Xorg
DISPLAY=:0
ARGS=" -br -pn   -nocursor "
HOME=/home/root
USER=root

Rotate Open Embedded logo

/lib/systemd/system/psplash-start.service

and change

[Service]
ExecStartPre=/bin/sh -c "if [ -e /sys/class/graphics/fbcon/cursor_blink ]; then echo 0 > /sys/class/graphics/fbcon/cursor_blink; fi"
ExecStart=/usr/bin/psplash --angle 90 -n

Fast way to flash image @alienmind01

$ sudo apt-get install bmap-tools
$ sudo bmaptool copy image.rootfs.wic.gz /dev/sdb

Cross Compile .c Using Yocto toolchain

source /opt/fsl-imx-x11/4.19-warrior/environment-setup-cortexa9hf-neon-poky-linux-gnueabi
$CC -o hello sendcode2.c

Dump Address (fw_printenv )

#define CONFIG_ENV_SIZE         0x4000          /* 16KB */
#define CONFIG_ENV_MMC_OFFSET   0x138000
#define CONFIG_ENV_MMC_OFFSET_REDUND 0x13c000

fw_env.config
/dev/mmcblk2boot0 0x138000 0x4000
/dev/mmcblk2boot0 0x13c000 0x4000
$ hexdump -C -s 0x138000 /dev/mmcblk2boot0

Flash board using ums (tested on px30 evb)

ums 0 mmc 0

Then plug the usb and dd into the exposed inode

Disable SOC Core

To disable cpu/soc cores just:

echo 0 > /sys/devices/system/cpu/cpu0/online
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 0 > /sys/devices/system/cpu/cpu2/online
echo 0 > /sys/devices/system/cpu/cpu3/online
echo 0 > /sys/devices/system/cpu/cpu4/online
echo 0 > /sys/devices/system/cpu/cpu5/online

Disable busfreq

echo 0 > /sys/bus/platform/drivers/imx_busfreq/busfreq/enable

Create Bootable Win10 image from another

# Create empty image
sudo dd if=/dev/zero of=empty.img bs=1M count=4500 status=progress

# Partitioning image
sudo gdisk empty.img

n
p1 -> 16384 -> +32M
p2 -> 81920 -> +5800M

t1 -> EF00
t2 -> 0700

# Mount and format .img into loop inode
sudo kpartx -a empty.img
sudo fdisk -l

sudo dd if=firmware_uuu.bin of=/dev/loop1 bs=512 bs=1k seek=32 conv=fsync
sudo dd if=efi-part1.img of=/dev/loop1p1 conv=fsync

sudo mkfs.vfat /dev/mapper/loop1p2
sudo mount /dev/mapper/loop1p2 /mnt
sudo cp -rf /media/tom/WINPE/* /mnt/
sudo umount /mnt

sudo kpartx -d empty.img

# Write image into sdcard
mv empty.img win10-iote-v21h2_w21h2-1-3-0_07022023.img
sudo dd if=win10-iote-v21h2_w21h2-1-3-0_07022023.img of=/dev/sda bs=1M conv=fsync status=progress

Build and run qt5 app using Yocto SDK

Build QT 5.15 helloworld app:

source /opt/fsl-imx-xwayland/5.15-kirkstone/environment-setup-armv8a-poky-linux
mkdir qt-test && cd qt-test
touch helloworld.cpp
touch helloworld.pro

Where:

helloworld.cpp

#include <QApplication>
#include <QPushButton>

int main(int argc, char **argv)
{
 QApplication app (argc, argv);

 QPushButton button ("Hello world !");
 button.show();

 return app.exec();
}

helloworld.pro

QT += core gui widgets
SOURCES += helloworld.cpp

build app:

qmake
make

cp app into target:

scp helloworld [email protected]:/home/root

run helloworld app with weston backend:

./helloworld

Run helloworld app eglfs backend:

systemctl stop weston
export QT_QPA_EGLFS_ALWAYS_SET_MODE=1
echo "{ \"device\": \"/dev/dri/card1\" }" > /home/root/eglfs.json
export QT_QPA_EGLFS_KMS_CONFIG=/home/root/eglfs.json
./helloworld -platform eglfs

References:

Create .ext4 file from existing folder

sudo dd if=/dev/zero of=./etc_image.ext4 bs=1M count=100
mke2fs -d <folder> -t ext4 -L etc_image etc_image.ext4

Play with psplash

psplash -n&
psplash-write "PROGRESS 50"
psplash-write "MSG copying update bundle..."
psplash-write "QUIT"

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment