Replace partition table

I made a sdcard for emmc update with Apalis-iMX6_LXDE-Image_2.8.6.

If I modify the partition, it won’t boot normally.

Here is what I modified:

-- update.sh --
#BOOT_START=$(expr 4096 \* 2)
BOOT_START=$(expr 10240 \* 2)
# Rootfs partition [in sectors of 512]
#ROOTFS_START=$(expr 20480 \* 2)
ROOTFS_START=$(expr 26624 \* 2)

-- u-boot --
Apalis iMX6 # mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     20480           32768           95e1a729-01     0c
  2     53248           7061504         95e1a729-02     83

However, it does not boot normally.

U-Boot 2016.11-2.8.6+g83a53c1c0c (Apr 01 2019 - 14:09:00 +0000)

CPU:   Freescale i.MX6Q rev1.5 at 792 MHz
Reset cause: WDOG
I2C:   ready
DRAM:  1 GiB
PMIC:  device id: 0x10, revision id: 0x21, programmed
MMC:   FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
auto-detected panel vga-rgb
Display: vga-rgb (640x480)
In:    serial
Out:   serial
Err:   serial
Model: Toradex Apalis iMX6 Quad 1GB V1.1B, Serial# 05198549
Net:   using PHY at 7
FEC [PRIME]
Hit any key to stop autoboot:  0
Booting from internal eMMC chip...
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **

emmcboot failed

What’s wrong?
Please let me know if there are any other fixes.
Thanks.

HI @LEEBAK

Did the update.sh script run without any errors?

Could you share the log of the run of update script?

Best regards,
Jaski

Hi @jaski.tx

update.sh execution log

blee@tm-server:~/toradex/Apalis-iMX6_LXDE-Image_2.8.6$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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: 85E370F9-4E77-4508-8B70-636504F0556B

Device     Start      End  Sectors  Size Type
/dev/sdb1   2048 31116254 31114207 14.9G Linux filesystem
blee@tm-server:~/toradex/Apalis-iMX6_LXDE-Image_2.8.6$ sudo mkfs.fat /dev/sdb1
mkfs.fat 3.0.28 (2015-05-16)
blee@tm-server:~/toradex/Apalis-iMX6_LXDE-Image_2.8.6$ sudo mount /dev/sdb1 /mnt/
blee@tm-server:~/toradex/Apalis-iMX6_LXDE-Image_2.8.6$ sudo ./update.sh -o /mnt
Apalis iMX6 rootfs detected

Creating MBR file and do the partitioning
0+0 records in
0+0 records out
0 bytes copied, 8.2394e-05 s, 0.0 kB/s
Model:  (file)
Disk /home/blee/toradex/Apalis-iMX6_LXDE-Image_2.8.6/apalis-imx6_bin/mbr.bin: 7168000s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End       Size      Type     File system  Flags
 1      20480s  53247s    32768s    primary               lba
 2      53248s  7114751s  7061504s  primary


Creating VFAT partition image with the kernel
mkfs.fat 3.0.28 (2015-05-16)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows

Creating rootfs partition image
682+0 records in
682+0 records out
715128832 bytes (715 MB, 682 MiB) copied, 0.326026 s, 2.2 GB/s
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done
Creating filesystem with 174592 4k blocks and 43680 inodes
Filesystem UUID: 091f34f3-c579-451b-9e8b-9c3cc78b07f2
Superblock backups stored on blocks:
        32768, 98304, 163840

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

tune2fs 1.42.13 (17-May-2015)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
umount: mnt/tdx-rootfs: not mounted
Successfully copied data to target folder.

To flash the Apalis/Colibri iMX6 module a running U-Boot is required. Boot the
module to the U-Boot prompt and

insert the SD card, USB flash drive or when using TFTP connect Ethernet only
and enter:
'run setupdate'

then to update all components enter:
'run update'

to update a single component enter one of:
'run update_uboot'
'run update_kernel'
'run update_fdt'
'run update_rootfs'

If you don't have a working U-Boot anymore, connect your PC to the module's USB
client port, bring the module in the serial download mode and start the
update.sh script with the -d option. This will copy U-Boot into the modules RAM
and execute it.
blee@tm-server:~/toradex/Apalis-iMX6_LXDE-Image_2.8.6$ sudo umount /mnt

Below is the ‘run update’ log on the EV board.

Apalis iMX6 # run setupdate
reading flash_blk.img
710 bytes read in 14 ms (48.8 KiB/s)
reading flash_blk.img
710 bytes read in 14 ms (48.8 KiB/s)
## Executing script at 12000000
reading apalis_imx6/flash_blk.img
4257 bytes read in 22 ms (188.5 KiB/s)
## Executing script at 12000000
enter "run update" to update the entire module
Apalis iMX6 # run update_spl
reading apalis_imx6/SPL
48128 bytes read in 25 ms (1.8 MiB/s)
switch to partitions #1, OK
mmc0(part 1) is current device

MMC write: dev # 0, block # 2, count 94 ... 94 blocks written: OK
Apalis iMX6 # run update_uboot
reading apalis_imx6/u-boot.img
370976 bytes read in 43 ms (8.2 MiB/s)
switch to partitions #1, OK
mmc0(part 1) is current device

MMC write: dev # 0, block # 138, count 725 ... 725 blocks written: OK
Fuse 0, 5:     5072
Fast boot mode already fused, no need to fuse
Apalis iMX6 # run update
switch to partitions #1, OK
mmc0(part 1) is current device

MMC read: dev # 0, block # 138, count 1 ... 1 blocks read: OK
reading apalis_imx6/u-boot.img
370976 bytes read in 43 ms (8.2 MiB/s)
switch to partitions #1, OK
mmc0(part 1) is current device

MMC write: dev # 0, block # 138, count 725 ... 725 blocks written: OK
Fuse 0, 5:     5072
Fast boot mode already fused, no need to fuse
reading apalis_imx6/mbr.bin
512 bytes read in 19 ms (25.4 KiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 0, count 1 ... 1 blocks written: OK
reading apalis_imx6/boot.vfat
16777216 bytes read in 814 ms (19.7 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 8192, count 32768 ... 32768 blocks written: OK
reading apalis_imx6/zImage
5410472 bytes read in 279 ms (18.5 MiB/s)

** Unable to use mmc 0:1 for fatwrite **
reading apalis_imx6/imx6q-apalis-eval.dtb
54620 bytes read in 30 ms (1.7 MiB/s)

** Unable to use mmc 0:1 for fatwrite **
reading apalis_imx6/root.ext4-100
67108864 bytes read in 3185 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 40960, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-101
67108864 bytes read in 3182 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 172032, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-102
67108864 bytes read in 3185 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 303104, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-103
67108864 bytes read in 3186 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 434176, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-104
67108864 bytes read in 3182 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 565248, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-105
67108864 bytes read in 3185 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 696320, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-106
67108864 bytes read in 3185 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 827392, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-107
67108864 bytes read in 3182 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 958464, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-108
67108864 bytes read in 3185 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 1089536, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-109
67108864 bytes read in 3186 ms (20.1 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 1220608, count 131072 ... 131072 blocks written: OK
reading apalis_imx6/root.ext4-110
44040192 bytes read in 2099 ms (20 MiB/s)
switch to partitions #0, OK
mmc0(part 0) is current device

MMC write: dev # 0, block # 1351680, count 86016 ... 86016 blocks written: OK
resetting ...


U-Boot 2016.11-2.8.6+g83a53c1c0c (Apr 01 2019 - 14:09:00 +0000)

CPU:   Freescale i.MX6Q rev1.5 at 792 MHz
Reset cause: WDOG
I2C:   ready
DRAM:  1 GiB
PMIC:  device id: 0x10, revision id: 0x21, programmed
MMC:   FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
auto-detected panel vga-rgb
Display: vga-rgb (640x480)
In:    serial
Out:   serial
Err:   serial
Model: Toradex Apalis iMX6 Quad 1GB V1.1B, Serial# 05198549
Net:   using PHY at 7
FEC [PRIME]
Hit any key to stop autoboot:  0
Booting from internal eMMC chip...
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **

emmcboot failed
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
MMC: no card present
starting USB...
USB0:   Port not available.
USB1:   USB EHCI 1.00
scanning bus 1 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
       scanning usb for ethernet devices... 0 Ethernet Device(s) found

USB device 0: unknown device
Apalis iMX6 # <INTERRUPT>
Apalis iMX6 # mmc dev 0
switch to partitions #0, OK
mmc0(part 0) is current device
Apalis iMX6 # mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     20480           32768           cb008d0c-01     0c
  2     53248           7061504         cb008d0c-02     83

SDCARD info

blee@X205TA:~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 14.9 GiB, 15931539456 bytes, 31116288 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: 85E370F9-4E77-4508-8B70-636504F0556B

Device     Start      End  Sectors  Size Type
/dev/sda1   2048 31116254 31114207 14.9G Linux filesystem
blee@X205TA:~$ sudo mount /dev/sda1 /mnt/
blee@X205TA:~$ ls -l /mnt/
total 32
drwxr-xr-x 2 root root 8192  8월 13 08:56 apalis_imx6
-rwxr-xr-x 1 root root  710  8월 13 08:56 flash_blk.img
-rwxr-xr-x 1 root root  444  8월 13 08:56 flash_eth.img
-rwxr-xr-x 1 root root  307  8월 13 08:56 flash_mmc.img
blee@X205TA:~$ ls -l /mnt/apalis_imx6/
total 720656
-rwxr-xr-x 1 root root 16777216  8월 13 08:56 boot.vfat
-rwxr-xr-x 1 root root     4257  8월 13 08:56 flash_blk.img
-rwxr-xr-x 1 root root     4017  8월 13 08:56 flash_eth.img
-rwxr-xr-x 1 root root    54620  8월 13 08:56 imx6q-apalis-eval.dtb
-rwxr-xr-x 1 root root    54319  8월 13 08:56 imx6q-apalis-ixora.dtb
-rwxr-xr-x 1 root root    54833  8월 13 08:56 imx6q-apalis-ixora-v1.1.dtb
-rwxr-xr-x 1 root root      512  8월 13 08:56 mbr.bin
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-100
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-101
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-102
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-103
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-104
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-105
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-106
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-107
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-108
-rwxr-xr-x 1 root root 67108864  8월 13 08:56 root.ext4-109
-rwxr-xr-x 1 root root 44040192  8월 13 08:56 root.ext4-110
-rwxr-xr-x 1 root root    48128  8월 13 08:56 SPL
-rwxr-xr-x 1 root root   370976  8월 13 08:56 u-boot.img
-rwxr-xr-x 1 root root      270  8월 13 08:56 versions.txt
-rwxr-xr-x 1 root root  5410472  8월 13 08:56 zImage

Best regards,
LeeBak

Hi @jaski.tx

I found that the address is fixed in the * .scr file.

So I change partitions and boot normally.

However, the ‘mmc read’ command still reads only 0x1000 size.

Apalis iMX6 # mmc dev 0 1
switch to partitions #1, OK
mmc0(part 1) is current device
Apalis iMX6 # mmc dev 0 1; mmc read $fdt_addr_r 8a 1
switch to partitions #1, OK
mmc0(part 1) is current device

MMC read: dev # 0, block # 138, count 1 ... 1 blocks read: OK
Apalis iMX6 # mmc dev 0 1; mmc read $fdt_addr_r 1000 1
switch to partitions #1, OK
mmc0(part 1) is current device

MMC read: dev # 0, block # 4096, count 1 ... MMC: block number 0x1001 exceeds max(0x1000)
0 blocks read: ERROR
Apalis iMX6 #

I want to read and write up to 0x5000.

Best regards, LeeBak

I made it.

Perfect that it works. Could you share your solution, please?

Best regards,
Jaski

[ update.sh ]

    #BOOT_START=$(expr 4096 \* 2)
     BOOT_START=$(expr 10240 \* 2)
     # Rootfs partition [in sectors of 512]
     #ROOTFS_START=$(expr 20480 \* 2)
     ROOTFS_START=$(expr 26624 \* 2)

[ *.scr ]

setenv update_2 'load ${interface} ${drive}:1 ${fdt_addr_r} ${board_name}/boot.vfat && run set_blkcnt && mmc dev 0 0 && mmc write ${fdt_addr_r} 0x2000 ${blkcnt}'
setenv update_3 'setenv filesize 4000000; setenv filenum 100; setenv blkstart a000; while test ${filesize} -eq "4000000"; do run cp_file_chunk; run set_nextnum; done; true'

0x2000 => 0x5000
a000 => d000

[ u-boot ] mmc access ‘dev 0 0’

mmc dev 0 1 => mmc dev 0 0

Perfect. Thanks for sharing your solution.