Skip to content

Instantly share code, notes, and snippets.

@Scott31393
Last active May 20, 2022 13:50
Show Gist options
  • Save Scott31393/ca2b033fee83714aea0e45af7df13964 to your computer and use it in GitHub Desktop.
Save Scott31393/ca2b033fee83714aea0e45af7df13964 to your computer and use it in GitHub Desktop.

Bring-up Cheatsheet

U-Boot

Boot using .scr

To enable this feature you need the following U-Boot config:

CONFIG_CMD_RUN=y
CONFIG_CMD_SOURCE=y

Then create .scr from a .txt using mkimage:

mkimage -A arm -T script -O linux -d boot.txt boot.scr

Now after load into memory at uboot you can run it using:

fatload mmc 1:1 ${loadaddr} file.scr
source ${loadaddr}

Boot using ramdisk (Minimal filesystem that is mounted on /dev/ram0)

First of all you need to add support for /dev/ram0 device on your Kernel, adding the following config:

+CONFIG_BLK_DEV_RAM=y

Then you need to convert .cpio.gz into ramdisk.img using:

$ mkimage -A arm -O linux -T ramdisk -n "Initial Ram Disk" -d initramfs-20200713133925.rootfs.cpio.gz initramfs.img

Now put initramfs.img into fat partition

sudo mount /dev/sdf1 /mnt
sudo cp initramfs.img /mnt

Now setup U-Boot env:

load mmc 1:2 ${loadaddr} /boot/loader/uEnv.txt
env import -t ${fileaddr} ${filesize}
load mmc 1:2 ${loadaddr} /boot${kernel_image}
load mmc 1:1  87E80000 initramfs.img
load mmc 1:1 85700000 file.dtb
bootz 0x80800000 87E80000 85700000

tftp boot

$ setenv bootcmd "tftp 0x80280000 Image; tftp 0x83000000 file.dtb; booti 0x80280000 - 0x83000000"

$ setenv bootargs console=ttyLP0,115200 earlycon=lpuart32,0x5a060000,115200 root=/dev/nfs ip=10.0.0.100:::::eth0 nfsroot=10.0.0.1:/targetfs,nfsvers=3 rw

$ setenv ipaddr 10.0.0.100
$ setenv serverip 10.0.0.1

mmc boot (ext3)

$ setenv bootcmd "fatload mmc 0:1 0x80280000 Image; fatload mmc 0:1 0x83000000 file.dtb; booti 0x80280000 - 0x83000000" 

$ setenv bootargs console=ttyLP0,115200 earlycon=lpuart32,0x5a060000,115200 root=/dev/mmcblk0p2 rootwait rw rootfstype=ext3

mmc boot (ext4)

$ setenv bootcmd "fatload mmc 0:1 0x80280000 Image; fatload mmc 0:1 0x83000000 file.dtb; booti 0x80280000 - 0x83000000" 

$ setenv bootargs console=ttyLP0,115200 earlycon=lpuart32,0x5a060000,115200 root=/dev/mmcblk0p2 rootwait rw rootfstype=ext4

usb boot

$ usb start
$ setenv bootcmd "fatload usb 0:1 0x80280000 Image; fatload usb 0:1 0x83000000 file.dtb; booti 0x80280000 - 0x83000000"
$ setenv bootargs console=ttyLP0,115200 earlycon=lpuart32,0x5a060000,115200 root=/dev/sda2 rootwait rw rootfstype=ext3

.lst script (for uuu)

uuu_version 1.2.39

# This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ
SDP: boot -f flash.bin

# This command will be run when ROM support stream mode
# i.MX8QXP, i.MX8QM
SDPS: boot -f flash.bin

# These commands will be run when use SPL and will be skipped if no spl
# SDPU will be deprecated. please use SDPV instead of SDPU
# {
SDPU: delay 1000
SDPU: write -f flash.bin -offset 0x57c00
SDPU: jump
# }

# These commands will be run when use SPL and will be skipped if no spl
# if (SPL support SDPV)
# {
SDPV: delay 1000
SDPV: write -f flash.bin -skipspl
SDPV: jump
# }

FB: ucmd setenv fastboot_buffer ${loadaddr}
FB: download -f flash.bin
FB: ucmd mmc write $fastboot_buffer 0x40 0x8000
FB: ucmd mmc partconf ${emmc_dev} 0 0 0
FB: Done

flash u-boot + rootfs

$ mmc partconf 0 0 0 0
$ sudo ./uuu -b emmc_all flash.bin image.sdcard

Device Tree Overlay (.dtbo)

#apply-overlay
Need:
CONFIG_OF_LIBFDT_OVERLAY


$ setenv fdt_loadaddr 0x83000000
$ setenv fdtovaddr 0x830C0000
$ setenv resize_dim 60000
$ setenv kernel_loadaddr 0x80280000

$ tftp $kernel_loadaddr Image
$ tftp $fdt_loadaddr file.dtb
$ tftp $fdtovaddr file.dtbo

$ fdt addr $fdt_loadaddr
$ fdt resize $resize_dim
$ fdt apply $fdtovaddr

$ boot


Note:

fdtovaddr = 0x830C0000
fdtovaddr 0x830C0000

Tips is that the difference between fdtovaddr and fdtovaddr must be around: C0000

0x830C0000 - 0x830C0000 = C0000

Kernel

source /opt/fsl-imx-xwayland/4.19-warrior/environment-setup-aarch64-poky-linux 
export ARCH=arm64   

make defconfig 
make -j20 Image dtbs modules  

make -j16 modules_install CROSS_COMPILE=$CROSS_COMPILER ARCH=arm64 INSTALL_MOD_PATH=./MODULES 

Yocto Project

Create folder: 

$ mkdir files 

Add these line inside linux-kerne .bb recipe: 

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"  

SRC_URI += "\ 
file://file1.patch \ 
file://file2.patch \ 
file://file3.patch \ 
file://file4.patch \ 
file://file5.patch \ 
file://file6.patch \ 
file://file7.patch;patch=1 \ 
" 

$ bitbake core-image-minimal

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)) 

Maintain symlink using tar

$ EXTRACT_UNSAFE_SYMLINKS=1 tar jxvpf source.tar -C destineation-folder

Flash .sdcard using mfgtool

uuu -b emmc_all bootloader rootfs.sdcard
uuu -b emmc_all bootloader rootfs.sdcard.bz2/*

From Yocto compilation

$ sudo uuu -v -b emmc_all imx-boot-seco-imx8qxp-c57-sd.bin-flash core-image-minimal-seco-imx8qxp-c57.sdcard.bz2/*

Recommended lectures https://developer.toradex.com/knowledge-base/initramfs-and-tmpfs

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