Flash Apalis iMX6 through internal eMMC

Hello.

I am aware of the current methods to flash the modules such as TFTP, storage device, tezi,…

Is there any chance I could keep a partition on the internal mmc with an image that I could flash with Uboot? Did anyone did something like it?

My idea is if I have an update, I wget the image, flag U-Boot, reset and update the image.

Best Regards

Yes, this is possible. You will need to modify the U-boot flashing scripts (or write your own) to accommodate this behavior, but there is not much more to it than preserving an area on flash for the update files. However, there is an element of risk to this approach.

Another approach is to use an A-B partition scheme wherein there are two mirrored partitions which house the rootfs. In this approach, the whole update can be done from Linux since you can update the rootfs which is not mounted from the mounted rootfs and then switch to the newly updated rootfs upon reboot. If the system fails to boot, the system will revert back to the working rootfs. This is the tactic used by mender.io who provides a complete OTA update solution for Linux which is compatible with Toradex modules. View our joint webinar.

Hi Brandon,

Thanks for your insights. I’ll start digging now, since I know it’s possible.

Best regards,

João

Regarding this question I am doing some experiments. This is how my eMMC looks like:
Partition Map for MMC device 0 – Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     8192            32768           976a3b41-01     0c
  2     40960           3502080         976a3b41-02     83
  3     3543040         1280000         976a3b41-03     83
  4     4823040         2304000         976a3b41-04     83

And I am using the variable setsdupdate as a basis. I have the results of update.sh on the 4th partition and I am trying to create the following environmental variable:

setemmcupdate setenv interface mmc; setenv drive 0; mmc rescan; load ${interface} ${drive}:1 ${loadaddr} flash_blk.img && source ${loadaddr}

With no success. I always get the message: ** Bad device 0:4 0x12000000 ** Isn’t the :4 the partition, how should I do it?

Regards,
Joao

When you set an environment variable that contains ‘;’ you must escape the value with ‘’ or it will set the variable with whatever is before the ‘;’ and then execute whatever comes after that.

So what about:

setenv setemmcupdate 'setenv interface mmc; setenv drive 0; mmc rescan; load ${interface} ${drive}:4 ${loadaddr} flash_blk.img && source ${loadaddr}'

Hi Max,

Thanks again. This allowed me to set the variable. Now it doesn’t detect the flash_blk but I assume it’s an issue caused by me.

Can you please just confirm that ${drive}:4 scans the 4th partition?

Best regards

EDIT: Ok, I confirmed the ‘:4’ reads the 4th partition. because with the :4 I can read the flash_blk in the parent directory, but it fails when trying to read something from the /apalis_imx6. Is there a reason for it? I simply copied the results of ./update.sh -o /srv/tftp -m 1 to the /firmware_update folder on apalis which is the mountpoint of the 4th partition. Why do I always get ** Unable to read file apalis_imx6/flash_blk.img **?

${drive}:4 scans the 4th partition, yes that is correct.

Note that you also have the possibility to list directories from U-Boot, e.g.:

ls mmc 0:4
ls mmc 0:4 /apalis_imx6

Hi Max

I didn’t know that, thank you.

When I perform those commands I see the files there. But the script cannot read them for some reason. I’ll post the result of ls down below.

Apalis iMX6 # ls mmc 0:4
       4096 .
       4096 ..
       4096 apalis_imx6
             710 flash_blk.img
             444 flash_eth.img
             307 flash_mmc.img
Apalis iMX6 # ls mmc 0:4 /apalis_imx6
       4096 .
       4096 ..
           50345 imx6q-apalis-eval.dtb
           50216 imx6q-apalis_v1_0-eval.dtb
           50486 imx6q-apalis-ixora-v1.1.dtb
           49875 imx6q-apalis_v1_0-ixora.dtb
          371640 u-boot.imx-spl
           48128 SPL
         5476752 uImage
             512 mbr.bin
        16777216 boot.vfat
            4261 flash_blk.img
            4021 flash_eth.img
             210 versions.txt
        67108864 root.ext4-100
        67108864 root.ext4-101
        67108864 root.ext4-102
        67108864 root.ext4-103
        67108864 root.ext4-104
        67108864 root.ext4-105
        67108864 root.ext4-106
        67108864 root.ext4-107
        67108864 root.ext4-108
        28311552 root.ext4-109

This confirms the files are there. Is it because of the . and … directories original from the Linux?

Apalis iMX6 # run setemmcupdate
710 bytes read in 25 ms (27.3 KiB/s)
## Executing script at 12000000
reading apalis_imx6/flash_blk.img
** Unable to read file apalis_imx6/flash_blk.img **

Did you try to read the file ‘by hand’?

load mmc 0:4 apalis_imx6/flash_blk.img

and if that works go back to your setemmcupdate variable why ${interface} ${drive} do not evaluate to the values they should.

Apalis iMX6 # load mmc 0:4 0 apalis_imx6/flash_blk.img
4261 bytes read in 81 ms (50.8 KiB/s)

I had to include a ‘0’ there or else it wouldn’t even try, I guess for a syntax error of load.

It can read ‘by hand’ since the byte count is the same as ls command.

Can it be an error caused by the first flash_blk.img in the parent directory? It can read that one and the setup fails while executing that script.

EDIT: Found it. On that script fatload ${interface} ${drive}:1 ${loadaddr} ${board_name}/flash_blk.img && source ${loadaddr} is there a way for me to patch this? meta-toradex-nxp?

EDIT2: Found it on the meta-toradex-demos, just like update.sh. I think i will create a new file script in paralell to this one but i think it’s worked out. Thank you one more time Max

As a follow up, i tried to flash apalis by switching the scripts. The places that load the files in mmc interface + drive : 1 i switched to : 4. Here’s the output. Why do I get bad partition? Is it because I create the partitions 3 & 4 after flashing?

Where can I define the partition table when flashing? That could make some of my initial scripts / reboots useless and that would be a good thing.

Apalis iMX6 # setenv setemmcupdate 'setenv interface mmc; setenv drive 0; mmc rescan; load ${interface} ${drive}:4 ${loadaddr} flash_blk.img && source ${loadaddr}'
Apalis iMX6 # run setemmcupdate
707 bytes read in 25 ms (27.3 KiB/s)
## Executing script at 12000000
4261 bytes read in 81 ms (50.8 KiB/s)
## Executing script at 12000000
enter "run update" to update the entire module
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
371640 bytes read in 70 ms (5.1 MiB/s)
switch to partitions #1, OK
mmc0(part 1) is current device

MMC write: dev # 0, block # 138, count 726 ... 726 blocks written: OK
Fuse 0, 5:     5072
Fast boot mode already fused, no need to fuse
512 bytes read in 69 ms (6.8 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
** Invalid partition 4 **
** Invalid partition 4 **
** Invalid partition 4 **
** Invalid partition 4 **
switch to partitions #0, OK
mmc0(part 0) is current device

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

UPDATE: I was right, I was deleting the partitions I needed. I created the 2 partitions I used to create on my init-scripts within update.sh and everything works as intended.

I can now flash a new imagem with the internal eMMC.

Once again thank you for your support

Regards