nxp-imx / mfgtools

Freescale/NXP I.MX Chip image deploy tools.
BSD 3-Clause "New" or "Revised" License
544 stars 298 forks source link

Flash both eMMC boot partitions #386

Closed aleeraser closed 1 year ago

aleeraser commented 1 year ago

Is it possible to flash the bootloader (U-Boot) for both boot partitions on an eMMC?

Right now, the normal -b emmc command only flashes the first boot partition.

nxpfrankli commented 1 year ago

You can use customer script to do that.

below this example:

FB: ucmd setenv fastboot_buffer ${loadaddr}

FB: download -f u-boot-imx8qxp.imx

FB: ucmd setexpr fastboot_blk ${fastboot_bytes}

FB: ucmd setexpr fastboot_blk ${fastboot_blk} + 0x1FF

FB: ucmd setexpr fastboot_blk ${fastboot_blk} / 0x200

FB: ucmd mmc partconf ${emmc_dev} 1 1 1

FB: ucmd echo ${fastboot_buffer}

FB: ucmd echo ${fastboot_blk}

FB: ucmd mmc write ${fastboot_buffer} 0x40 ${fastboot_blk}

aleeraser commented 1 year ago

Thanks for the quick answer. May I ask you to elaborate further on the fastboot_blk var?

nxpfrankli commented 1 year ago

Any name, just round up bytes to MMC block numbers.

aleeraser commented 1 year ago

Understood, thanks.

aleeraser commented 1 year ago

It seems I can't make it working.

I'm using mmc partconf to switch between boot0 and boot1 partitions, and I'm writing the boot container at address 0x0. However, it looks like that even when I switch to boot1, (i.e. mmc partconf 0 1 2 1) the mmc write operation still writes to boot0, since as I reboot I can see that the imx-boot-ALTERNATE.bin is being run.

How can I switch the mmc write target to the second boot partition ?

Here is my uuu script (EDIT: updated with working version - see comments below):

uuu_version 1.2.39

SDPS: boot -f imx-boot.bin
SDPV: delay 1000
SDPV: write -f imx-boot.bin -skipspl
SDPV: jump

FB: ucmd setenv fastboot_dev mmc
FB: ucmd setenv mmcdev $emmc_dev

FB: ucmd echo flashing first parttion

FB: ucmd setenv fastboot_buffer $loadaddr
FB: download -f imx-boot.bin
FB: ucmd setexpr fastboot_blk $fastboot_bytes
FB: ucmd setexpr fastboot_blk $fastboot_blk + 0x1FF
FB: ucmd setexpr fastboot_blk $fastboot_blk / 0x200
FB: ucmd mmc dev $emmc_dev 1
FB: ucmd echo fastboot_buffer: $fastboot_buffer
FB: ucmd echo fastboot_blk: $fastboot_blk
FB: ucmd mmc write $fastboot_buffer 0 $fastboot_blk

FB: ucmd echo flashing second parttion

FB: download -f imx-boot-ALTERNATE.bin
FB: ucmd setexpr fastboot_blk $fastboot_bytes
FB: ucmd setexpr fastboot_blk $fastboot_blk + 0x1FF
FB: ucmd setexpr fastboot_blk $fastboot_blk / 0x200
FB: ucmd mmc dev $emmc_dev 2
FB: ucmd mmc write $fastboot_buffer 0 $fastboot_blk

FB: ucmd mmc partconf $emmc_dev 1 1 0

FB: Done
nxpfrankli commented 1 year ago

Actually it is uboot's behavior. Can you try add FB: ucmd mmc partconf $emmc_dev 1 1 0 before write second's partition?

aleeraser commented 1 year ago

You mean replacing

FB: ucmd mmc partconf $emmc_dev 1 2 1

with

FB: ucmd mmc partconf $emmc_dev 1 1 0

or simply adding it before it?

nxpfrankli commented 1 year ago

simple adding it. u-boot=> help mmc ...., suppose only one can be 1

mmc partconf [[varname] | [ ]]

aleeraser commented 1 year ago

Unfortunately it doesn't help.

If in U-Boot I switch partitions with mmc partconf 0 1 1/2 0 and reboot, I can see that the correct U-Boot version starts... but I'm unable to flash it.

Those are the partitions as seen by fastboot:

idx 0, ptn 0 name='gpt' start=0 len=2048
idx 1, ptn 0 name='' start=0 len=0
idx 2, ptn 0 name='all' start=0 len=15384576
idx 3, ptn 0 name='bootloader' start=0 len=64512
idx 4, ptn 1 name='mmcsda1' start=8 len=1638400
idx 5, ptn 2 name='mmcsda2' start=1638408 len=1638400
idx 6, ptn 3 name='mmcsda3' start=3276808 len=9172992

What looks strange to me is that I can access and flash boot1 partition from linux. Only U-Boot is unable to see it.

aleeraser commented 1 year ago

I figured it out. In order to access boot0 and boot1 boot partitions of the eMMC, the right command is not mmc partconf but mmc dev.

aleeraser commented 1 year ago

I updated the previous script I posted and was able to flash both boot partitions. This can be closed.

nxpfrankli commented 1 year ago

Can you provide your work script? I can put it to FAQ wiki page.

aleeraser commented 1 year ago

As I mentioned, I updated the script in my previous post

nxpfrankli commented 1 year ago

Thanks, update faq: https://github.com/nxp-imx/mfgtools/wiki/FAQ