Upload image from Radxa CM3S

There is utility rkdeveloptool which i using for flashing chip from this guide.

I want to upload image from Radxa after setting it up.

My Radxa has 16Gb eMMC and I tried did so:

sudo rkdeveloptool rl 0 33554432 image.img

33554432 is a count of sectors with 512 bytes in 16Gb. I got an error:

Read LBA to file (91%)
Read LBA failed!

Then i just multiply 33554432 to 0.9 :grinning: and

sudo rkdeveloptool rl 0 30198988 image.img
Read LBA to file (100%)

Reading was success))
Then tried to flash empty Radxa :

sudo rkdeveloptool db rk356x_spl_loader_ddr1056_v1.10.111.bin
sudo rkdeveloptool wl 0 image.img
Write LBA from file (100%)
sudo rkdeveloptool rd  

Nothing was loaded (( In Debug UART I saw:

DDR Version V1.13 20220218
ln
ddrconfig:7
LP4 MR14:0x4d
LPDDR4, 324MHz
BW=32 Col=10 Bk=8 CS0 Row=14 CS1 Row=14 CS=2 Die BW=16 Size=1024MB
tdqss: cs0 dqs0: 409ps, dqs1: 313ps, dqs2: 337ps, dqs3: 241ps, 
tdqss: cs1 dqs0: 385ps, dqs1: 313ps, dqs2: 313ps, dqs3: 217ps, 

change to: 324MHz
PHY drv:clk:38,ca:38,DQ:30,odt:0
vrefinner:41%, vrefout:41%
dram drv:40,odt:0
clk skew:0x58

change to: 528MHz
PHY drv:clk:38,ca:38,DQ:30,odt:0
vrefinner:41%, vrefout:41%
dram drv:40,odt:0
clk skew:0x78

change to: 780MHz
PHY drv:clk:38,ca:38,DQ:30,odt:0
vrefinner:41%, vrefout:41%
dram drv:40,odt:0
clk skew:0x5d

change to: 1056MHz(final freq)
PHY drv:clk:38,ca:38,DQ:30,odt:60
vrefinner:16%, vrefout:29%
dram drv:40,odt:80
vref_ca:00000068
clk skew:0x3f
cs 0:
the read training result:
DQS0:0x3d, DQS1:0x3c, DQS2:0x3c, DQS3:0x34, 
min  : 0xc  0xe 0x10  0xd  0x2  0x5  0x8  0x4 , 0x7  0x7  0x3  0x1  0xb  0xb  0xf  0xa ,
      0x10  0xd  0xd  0xb  0x5  0x1  0x3  0x6 , 0x9  0x4  0x3  0x1  0xc  0xc  0x8  0xb ,
mid  :0x2a 0x2a 0x2d 0x2a 0x1f 0x21 0x25 0x22 ,0x24 0x23 0x20 0x1d 0x28 0x28 0x2a 0x25 ,
      0x2b 0x29 0x27 0x26 0x20 0x1c 0x1e 0x20 ,0x24 0x20 0x21 0x1d 0x28 0x28 0x24 0x27 ,
max  :0x48 0x47 0x4a 0x47 0x3d 0x3d 0x43 0x40 ,0x41 0x3f 0x3d 0x3a 0x46 0x45 0x46 0x41 ,
      0x46 0x45 0x41 0x42 0x3c 0x38 0x39 0x3b ,0x40 0x3d 0x3f 0x39 0x45 0x44 0x41 0x43 ,
range:0x3c 0x39 0x3a 0x3a 0x3b 0x38 0x3b 0x3c ,0x3a 0x38 0x3a 0x39 0x3b 0x3a 0x37 0x37 ,
      0x36 0x38 0x34 0x37 0x37 0x37 0x36 0x35 ,0x37 0x39 0x3c 0x38 0x39 0x38 0x39 0x38 ,
the write training result:
DQS0:0x76, DQS1:0x69, DQS2:0x6c, DQS3:0x5f, 
min  :0x97 0x9b 0x9b 0x98 0x8f 0x93 0x95 0x95 0x94 ,0x87 0x87 0x83 0x80 0x8b 0x8d 0x8e 0x8d 0x88 ,
      0x8e 0x8d 0x8b 0x8b 0x85 0x82 0x85 0x8b 0x89 ,0x84 0x83 0x80 0x7c 0x89 0x89 0x87 0x89 0x83 ,
mid  :0xb4 0xb7 0xb8 0xb4 0xac 0xaf 0xb1 0xb1 0xb0 ,0xa4 0xa3 0x9f 0x9d 0xa8 0xa9 0xa9 0xa9 0xa4 ,
      0xab 0xaa 0xa7 0xa7 0xa0 0x9c 0x9e 0xa4 0xa5 ,0xa2 0x9e 0x9c 0x99 0xa5 0xa6 0xa3 0xa6 0x9f ,
max  :0xd2 0xd3 0xd5 0xd1 0xc9 0xcc 0xce 0xcd 0xcc ,0xc2 0xc0 0xbb 0xba 0xc5 0xc5 0xc5 0xc5 0xc0 ,
      0xc8 0xc7 0xc4 0xc4 0xbc 0xb6 0xb8 0xbd 0xc1 ,0xc0 0xba 0xb9 0xb7 0xc2 0xc4 0xc0 0xc3 0xbb ,
range:0x3b 0x38 0x3a 0x39 0x3a 0x39 0x39 0x38 0x38 ,0x3b 0x39 0x38 0x3a 0x3a 0x38 0x37 0x38 0x38 ,
      0x3a 0x3a 0x39 0x39 0x37 0x34 0x33 0x32 0x38 ,0x3c 0x37 0x39 0x3b 0x39 0x3b 0x39 0x3a 0x38 ,
cs 1:
the read training result:
DQS0:0x3c, DQS1:0x3a, DQS2:0x3e, DQS3:0x35, 
min  : 0xc  0xf  0xf  0xd  0x1  0x4  0x8  0x4 , 0x6  0x7  0x3  0x1  0xb  0xa  0xe  0x9 ,
       0xf  0xd  0xd  0xb  0x4  0x1  0x4  0x6 , 0x7  0x3  0x1  0x1  0xb  0xb  0x7  0xa ,
mid  :0x29 0x2b 0x2c 0x29 0x1e 0x20 0x24 0x21 ,0x22 0x22 0x1f 0x1c 0x27 0x26 0x29 0x24 ,
      0x2b 0x2a 0x28 0x27 0x20 0x1d 0x1f 0x21 ,0x24 0x20 0x20 0x1d 0x28 0x28 0x25 0x27 ,
max  :0x47 0x47 0x49 0x45 0x3c 0x3c 0x41 0x3e ,0x3f 0x3d 0x3c 0x38 0x43 0x42 0x44 0x3f ,
      0x47 0x47 0x44 0x44 0x3d 0x3a 0x3b 0x3d ,0x41 0x3d 0x40 0x39 0x46 0x45 0x43 0x44 ,
range:0x3b 0x38 0x3a 0x38 0x3b 0x38 0x39 0x3a ,0x39 0x36 0x39 0x37 0x38 0x38 0x36 0x36 ,
      0x38 0x3a 0x37 0x39 0x39 0x39 0x37 0x37 ,0x3a 0x3a 0x3f 0x38 0x3b 0x3a 0x3c 0x3a ,
the write training result:
DQS0:0x76, DQS1:0x69, DQS2:0x6c, DQS3:0x5f, 
min  :0x95 0x98 0x99 0x96 0x8d 0x90 0x92 0x93 0x92 ,0x88 0x88 0x83 0x81 0x8c 0x8e 0x8e 0x8d 0x89 ,
      0x8c 0x8a 0x88 0x88 0x82 0x7e 0x82 0x87 0x86 ,0x82 0x7e 0x7d 0x7b 0x86 0x86 0x84 0x87 0x7e ,
mid  :0xb1 0xb4 0xb5 0xb2 0xa9 0xac 0xae 0xae 0xad ,0xa5 0xa4 0x9f 0x9e 0xa8 0xaa 0xaa 0xa9 0xa5 ,
      0xa9 0xa8 0xa5 0xa5 0x9e 0x99 0x9c 0xa1 0xa3 ,0x9f 0x9b 0x9a 0x98 0xa3 0xa4 0xa0 0xa4 0x9c ,
max  :0xce 0xd0 0xd2 0xce 0xc6 0xc9 0xcb 0xc9 0xc9 ,0xc3 0xc1 0xbc 0xbb 0xc5 0xc6 0xc6 0xc5 0xc1 ,
      0xc7 0xc6 0xc2 0xc3 0xbb 0xb5 0xb7 0xbb 0xc0 ,0xbc 0xb8 0xb7 0xb5 0xc1 0xc3 0xbc 0xc2 0xba ,
range:0x39 0x38 0x39 0x38 0x39 0x39 0x39 0x36 0x37 ,0x3b 0x39 0x39 0x3a 0x39 0x38 0x38 0x38 0x38 ,
      0x3b 0x3c 0x3a 0x3b 0x39 0x37 0x35 0x34 0x3a ,0x3a 0x3a 0x3a 0x3a 0x3b 0x3d 0x38 0x3b 0x3c ,
CA Training result:
cs:0 min  :0x47 0x43 0x3e 0x38 0x3e 0x36 0x48 ,0x42 0x3b 0x3b 0x34 0x3a 0x32 0x48 ,
cs:0 mid  :0x82 0x84 0x7a 0x79 0x79 0x78 0x70 ,0x7e 0x7b 0x76 0x74 0x77 0x73 0x6f ,
cs:0 max  :0xbe 0xc5 0xb6 0xbb 0xb5 0xba 0x98 ,0xba 0xbc 0xb2 0xb5 0xb4 0xb5 0x97 ,
cs:0 range:0x77 0x82 0x78 0x83 0x77 0x84 0x50 ,0x78 0x81 0x77 0x81 0x7a 0x83 0x4f ,
cs:1 min  :0x49 0x45 0x3f 0x38 0x3e 0x39 0x3d ,0x45 0x3c 0x3d 0x37 0x3d 0x34 0x39 ,
cs:1 mid  :0x84 0x86 0x7c 0x7a 0x7b 0x7a 0x70 ,0x81 0x7e 0x79 0x77 0x79 0x76 0x6f ,
cs:1 max  :0xc0 0xc7 0xba 0xbc 0xb8 0xbb 0xa4 ,0xbe 0xc1 0xb6 0xb7 0xb6 0xb8 0xa5 ,
cs:1 range:0x77 0x82 0x7b 0x84 0x7a 0x82 0x67 ,0x79 0x85 0x79 0x80 0x79 0x84 0x6c ,
out
U-Boot SPL board init
U-Boot SPL rk356x-2017.09-1-15c53b0-g387f49e #runner (Mar 21 2023 - 04:18:44)
unknown raw ID phN
unrecognized JEDEC id bytes: 00, 00, 00
Trying to boot from MMC2
MMC error: The cmd index is 1, ret is -110
Card did not respond to voltage select!
mmc_init: -95, time 9
spl: mmc init failed with error: -95
Trying to boot from MMC1
## Verified-boot: 0
## Checking atf-1 0x00040000 ... sha256(fe4f274c06...) + OK
## Checking uboot 0x00a00000 ... sha256(9fa1a14245...) + OK
## Checking fdt 0x00b31218 ... sha256(1b9a4fe58a...) + OK
## Checking atf-2 0x00068000 ... sha256(8d44036095...) + OK
## Checking atf-3 0xfdcd0000 ... sha256(e410275b51...) + OK
## Checking atf-4 0xfdcc9000 ... sha256(990c53fc01...) + OK
## Checking atf-5 0x00066000 ... sha256(315a4195a9...) + OK
Jumping to U-Boot(0x00a00000) via ARM Trusted Firmware(0x00040000)
Total: 223.538 ms

INFO:    Preloader serial: 2
NOTICE:  BL31: v2.3():v2.3-181-gc9a647cae:cl
NOTICE:  BL31: Built : 10:55:41, Oct 18 2021
INFO:    GICv3 without legacy support detected.
INFO:    ARM GICv3 driver initialized in EL3
INFO:    pmu v1 is valid
INFO:    dfs DDR fsp_param[0].freq_mhz= 1056MHz
INFO:    dfs DDR fsp_param[1].freq_mhz= 324MHz
INFO:    dfs DDR fsp_param[2].freq_mhz= 528MHz
INFO:    dfs DDR fsp_param[3].freq_mhz= 780MHz
INFO:    Using opteed sec cpu_context!
INFO:    boot cpu mask: 0
INFO:    BL31: Initializing runtime services
WARNING: No OPTEE provided by BL2 boot loader, Booting device without OPTEE initialization. SMC`s destined for OPTEE will return SMC_UNK
ERROR:   Error initializing runtime service opteed_fast
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0xa00000
INFO:    SPSR = 0x3c9


U-Boot rk356x-2017.09-1-15c53b0-g387f49e #runner (Mar 21 2023 - 04:18:41 +0000)

Model: Radxa CM3 SODIMM IO
PreSerial: 2, raw, 0xfe660000
DRAM:  1022 MiB
Sysmem: init
Relocation Offset: 3d347000
Relocation fdt: 3b9f6ee0 - 3b9fecc8
CR: M/C/I
Using default environment

failed to find reset-gpios property
dwmmc@fe2b0000: 1, dwmmc@fe2c0000: 2, sdhci@fe310000: 0
Bootdev(atags): mmc 0
MMC0: HS200, 200Mhz
PartType: EFI
No misc partition
boot mode: None
FIT: No boot partition
No resource partition
No resource partition
Failed to load DTB, ret=-19
Failed to get kernel dtb, ret=-19
I2c0 speed: 100000Hz
vsel-gpios- not found! Error: -2
vdd_cpu init 900000 uV
PMIC:  RK8170 (on=0x40, off=0x00)
vdd_logic init 900000 uV
vdd_gpu init 900000 uV
io-domain: OK
Model: Radxa CM3 SODIMM IO
rockchip_set_serialno: could not find efuse/otp device
CLK: (sync kernel. arm: enter 816000 KHz, init 816000 KHz, kernel 0N/A)
  apll 816000 KHz
  dpll 528000 KHz
  gpll 1188000 KHz
  cpll 1000000 KHz
  npll 24000 KHz
  vpll 24000 KHz
  hpll 24000 KHz
  ppll 200000 KHz
  armclk 816000 KHz
  aclk_bus 150000 KHz
  pclk_bus 50000 KHz
  aclk_top_high 300000 KHz
  aclk_top_low 200000 KHz
  hclk_top 150000 KHz
  pclk_top 50000 KHz
  aclk_perimid 300000 KHz
  hclk_perimid 150000 KHz
  pclk_pmu 100000 KHz
No misc partition
Net:   No ethernet found.
Hit key to stop autoboot('CTRL+C'):  0 
failed to find reset-gpios property

Device 0: unknown device
MMC error: The cmd index is 1, ret is -110
Card did not respond to voltage select!
mmc_init: -95, time 10
switch to partitions #0, OK
mmc0(part 0) is current device
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
starting USB...
Bus dwc3@fcc00000: usb maximum-speed not found
Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
Bus dwc3@fd000000: usb maximum-speed not found
Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus dwc3@fcc00000 for devices... 1 USB Device(s) found
scanning bus dwc3@fd000000 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found

Device 0: unknown device
failed to find reset-gpios property
No ethernet found.
missing environment variable: pxeuuid
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm-rockchip
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default
No ethernet found.
Config file not found
failed to find reset-gpios property
No ethernet found.
No ethernet found.
## Booting FIT Image FIT: No boot partition
FIT: No FIT image
Could not find misc partition
ANDROID: reboot reason: "(none)"
optee check api revision fail: -1.0
optee api revision is too low
### ERROR ### Please RESET the board ###

How can I properly upload a full image from Radxa for flashing with it another Radxa?

I made mistake above.

Now i check fdisk -l:

Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mmcblk0: 14.56 GiB, 15634268160 bytes, 30535680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 767F10BF-A49B-4E49-A204-C3FED9851132

Device         Start      End  Sectors  Size Type
/dev/mmcblk0p1 32768    65535    32768   16M Microsoft basic data
/dev/mmcblk0p2 65536 30535646 30470111 14.5G EFI System


Disk /dev/zram0: 491.61 MiB, 515489792 bytes, 125852 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

and read correct count of blocks (30535680)

sudo rkdeveloptool rl 0 30535680 image_rk.img
Read LBA to file (100%)

After I tried to flash this image:

sudo rkdeveloptool wl 0 image_rk.img
Write LBA from file (100%)

But got the same error as I specified above ((

Next step was ssh )))
I connected Radxa and my laptop to the same network and on Radxa did:

sudo dd if=/dev/mmcblk0 status=progress | ssh -C user@192.168.42.2 dd of=/home/user/image-ssh.img

Then I wrote with rkdeveloptool image received through ssh
And it worked!

Now i want to shrink image before read it, because pull 16GB with ssh gets very long time.
At boot time,as i understood, image is resizing to whole volume of eMMC, because, for example, b24, has a size 3.4GB, but after installing rootfs partition occupies all free space.

Does anyone know where this is happening?

I tried to resize the image using the fdisk and gparted cli utilities, but after installing the resized image, the kernel threw me into the initramfs and I got stuck there.

I did it!

  1. First of all, you need to upload the image from Radxa, for example via ssh, as in previous post.
  2. On your linux machine create loop device with uploaded image:
sudo losetup --partscan --show --find image.img
/dev/loop0
  1. You can check
    Partitions:
Disk /dev/loop0: 14,56 GiB, 15634268160 bytes, 30535680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 767F10BF-A49B-4E49-A204-C3FED9851132

Device       Start      End  Sectors  Size Type
/dev/loop0p1 32768    65535    32768   16M Microsoft basic data
/dev/loop0p2 65536 30535646 30470111 14,5G EFI System

Ext4 filesystem:

sudo fsck /dev/loop0p2
fsck from util-linux 2.38.1
e2fsck 1.47.0 (5-Feb-2023)
rootfs: recovering journal
Clearing orphaned inode 354 (uid=0, gid=101, mode=0100640, size=8388608)
Setting free inodes count to 826534 (was 826535)
Setting free blocks count to 2407977 (was 2407980)
rootfs: clean, 120698/947232 files, 1400786/3808763 blocks

Get more info about ext4 filesystem:

sudo dumpe2fs -h /dev/loop0p2
dumpe2fs 1.47.0 (5-Feb-2023)
Filesystem volume name:   rootfs
Last mounted on:          /root
Filesystem UUID:          2145034c-4176-4996-b2c4-e0960f0f51e6
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              947232
Block count:              3808763
Reserved block count:     160748
Free blocks:              2407977
Free inodes:              826534
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      710
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8096
Inode blocks per group:   506
Flex block group size:    16
Filesystem created:       Tue Apr  4 13:24:52 2023
Last mount time:          Fri Aug  4 12:00:07 2017
Last write time:          Tue Jun 20 17:46:56 2023
Mount count:              145
Maximum mount count:      -1
Last checked:             Tue Apr  4 13:31:28 2023
Check interval:           0 (<none>)
Lifetime writes:          9 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      1b0099e4-f362-4591-84a5-fdf24223b99d
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x25c0c569
Journal features:         journal_incompat_revoke journal_64bit journal_checksum_v3
Total journal size:       64M
Total journal blocks:     16384
Max transaction length:   16384
Fast commit length:       0
Journal sequence:         0x0000833d
Journal start:            0
Journal checksum type:    crc32c
Journal checksum:         0x42a33aa4
  1. Before shrink the partition need to change size of ext4 filesystem. /dev/loop0p2 partition has ext4 filesystem with 14.5GB space, but using only 5GB. Let’s doing image size equal 6GB:
sudo resize2fs /dev/loop0p2 6G
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/loop0p2 to 1572864 (4k) blocks.
The filesystem on /dev/loop0p2 is now 1572864 (4k) blocks long.
  1. Repeat step3 for check that everything went well. fsck must be okay, dumpe2fs will have less count of blocks:
sudo fsck /dev/loop0p2
fsck from util-linux 2.38.1
e2fsck 1.47.0 (5-Feb-2023)
rootfs: clean, 120698/388608 files, 1364393/1572864 blocks

sudo dumpe2fs -h /dev/loop0p2                                                                                                                                                                          
dumpe2fs 1.47.0 (5-Feb-2023)
Filesystem volume name:   rootfs
Last mounted on:          /root
Filesystem UUID:          2145034c-4176-4996-b2c4-e0960f0f51e6
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              388608
Block count:              1572864
Reserved block count:     66382
Free blocks:              208471
Free inodes:              267910
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      711
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8096
Inode blocks per group:   506
Flex block group size:    16
Filesystem created:       Tue Apr  4 13:24:52 2023
Last mount time:          Fri Aug  4 12:00:07 2017
Last write time:          Tue Jun 20 18:04:54 2023
Mount count:              145
Maximum mount count:      -1
Last checked:             Tue Apr  4 13:31:28 2023
Check interval:           0 (<none>)
Lifetime writes:          10 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      1b0099e4-f362-4591-84a5-fdf24223b99d
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x43693308
Journal features:         journal_incompat_revoke journal_64bit journal_checksum_v3
Total journal size:       64M
Total journal blocks:     16384
Max transaction length:   16384
Fast commit length:       0
Journal sequence:         0x0000833d
Journal start:            0
Journal checksum type:    crc32c
Journal checksum:         0x42a33aa4
  1. Now need to reduce size of .img file. Execute:
sudo losetup -D  

For delete loop device.

Determine size of image considering the first partition(/dev/loop0p1):

Final size of .img = First partition size + Second partition size + Backup table for GPT

First partition size take from fdisk - 65535
Second partition size = Count of blocks in ext4 filesystem + “Some count of bytes”
Count of blocks = 1572864
Block size = 4096B
=> 12582912 sectors of 512 bytes.

As i understood “Some count of bytes” needed for ext4 in the end of filesystem. I will add 50 sectors of 512 bytes.

Finally: (65535 + (12582912 + 50) + 34) * 512
I used truncate utility:

sudo truncate --size=$[(65535+12582912+50+34)*512] image.img 

ls -lah image.img
-rw-r--r-- 1 user user 6,1G июн 20 18:47 image.img

  1. Now GPT table is broken, we need to restore it. I will use fdisk:
sudo fdisk image.img
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (30535679 != 12648530) will be corrected by write.

Command (m for help): p

Disk image.img: 6,03 GiB, 6476047872 bytes, 12648531 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors Size Id Type
image.img1          1 12648530 12648530   6G ee GPT

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): g
Created a new GPT disklabel (GUID: 79C4F0E5-064B-D04F-8856-D282AA7DE688).
The device contains 'PMBR' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-12648497, default 2048): 32768
Last sector, +/-sectors or +/-size{K,M,G,T,P} (32768-12648497, default 12648447): 65535

Created a new partition 1 of type 'Linux filesystem' and of size 16 MiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): n
Partition number (2-128, default 2): 
First sector (2048-12648497, default 65536): 65536
Last sector, +/-sectors or +/-size{K,M,G,T,P} (65536-12648497, default 12648447): 

Created a new partition 2 of type 'Linux filesystem' and of size 6 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): p

Disk image.img: 6,03 GiB, 6476047872 bytes, 12648531 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 79C4F0E5-064B-D04F-8856-D282AA7DE688

Device     Start      End  Sectors Size Type
image.img1 32768    65535    32768  16M Linux filesystem
image.img2 65536 12648447 12582912   6G Linux filesystem

Command (m for help): t
Partition number (1,2, default 2): 1
Partition type or alias (type L to list all): 11

Changed type of partition 'Linux filesystem' to 'Microsoft basic data'.

Command (m for help): t
Partition number (1,2, default 2): 
Partition type or alias (type L to list all): 1

Changed type of partition 'Linux filesystem' to 'EFI System'.

Command (m for help): p
Disk image.img: 6,03 GiB, 6476047872 bytes, 12648531 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 79C4F0E5-064B-D04F-8856-D282AA7DE688

Device     Start      End  Sectors Size Type
image.img1 32768    65535    32768  16M Microsoft basic data
image.img2 65536 12648447 12582912   6G EFI System

Command (m for help): w
The partition table has been altered.
Syncing disks.

Remove partition, create new GPT table, create partitions, change type of partitions and save changes.

  1. Flash the image on Radxa and enjoy:
rkdeveloptool ld
DevNo=1 Vid=0x2207,Pid=0x350a,LocationID=302    Loader

sudo rkdeveloptool wl 0 image.img
Write LBA from file (100%)

On Radxa:

radxa@radxa-cm3-sodimm-io:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            477M  8.0K  477M   1% /dev
tmpfs            99M  1.1M   98M   2% /run
/dev/mmcblk0p2  5.9G  4.9G  748M  87% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/mmcblk0p1   16M  2.5K   16M   1% /config
tmpfs            99M   40K   99M   1% /run/user/107
tmpfs            99M   40K   99M   1% /run/user/1000
  1. If you need to extend partition 2 (ext4) to fill all the disk space:
radxa@radxa-cm3-sodimm-io:~$ sudo growpart /dev/mmcblk0 2
CHANGED: partition=2 start=65536 old: size=12582912 end=12648448 new: size=30470111 end=30535647

radxa@radxa-cm3-sodimm-io:~$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mmcblk0p2 is now 3808763 (4k) blocks long.

radxa@radxa-cm3-sodimm-io:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            477M  8.0K  477M   1% /dev
tmpfs            99M  1.1M   98M   2% /run
/dev/mmcblk0p2   15G  4.9G  8.8G  36% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/mmcblk0p1   16M  2.5K   16M   1% /config
tmpfs            99M   40K   99M   1% /run/user/107
tmpfs            99M   40K   99M   1% /run/user/1000