Packaging a self-built image to make it be flashed by aml flash tool

Which system do you use? Android, Ubuntu, OOWOW or others?

self-built yocto image with uboot-2024.07

Please describe your issue below:

I have built a yocto image in the .wic format. I am able to flash this image to eMMC manually using the dd command when booted from the SD card.

My goal is to package this image so that it can be flashed directly into eMMC using your official USB Flash Tool.
I made a script based on the function pack_image_platform() in the fenix project:
https://github.com/khadas/fenix/blob/master/config/boards/VIM.inc#L237

And I took the config files such as package.conf, platform.conf in the $UPGRADE_DIR/Amlogic of output of fenix build and updated with my uboot, dtb and rootfs.

When I use the flash tool https://github.com/khadas/utils to run the flashage. I have some errors before the step “Create partitions” (after OK of step “Running u-boot”).

[LUSB]BL2 END, waiting TPL plug-in...
........[OK]

Command output: AmlUsbBulkCmd[     echo 12345]
AM_REQ_BULK_CMD_Handler ret=-110,blkcmd=     echo 12345 error_msg=error sending control message: Connection timed out
[AmlUsbRom]Err:rettemp = 0 buffer = [     echo 12345]
ERR: AmlUsbBulkCmd failed!

Command output: file size is 0x13386
AmlUsbTplCmd = download mem dtb normal 0x13386 IOCTL_TPL_CMD_Handler ret=-110,tpl_cmd=download mem dtb normal 0x13386 error_msg=error sending control message: Connection timed out
rettemp = 0 buffer = download mem dtb normal 0x13386

Create partitions
run_update_assert1 

Command output: AmlUsbBulkCmd[     disk_initial 1]
AM_REQ_BULK_CMD_Handler ret=-110,blkcmd=     disk_initial 1 error_msg=error sending control message: Connection timed out
[AmlUsbRom]Err:rettemp = 0 buffer = [     disk_initial 1]
ERR: AmlUsbBulkCmd failed!
[KO]

I think I made some errors on amlogic pakcaging config like package.conf, platform.conf, or I did not notice some details.
I did not found documentation about it. Do you have any idea or documentation about creating/pakcaging image? Thanks a lot.

You can try this command:

aml_image_v2_packer -r $UPGRADE_DIR/Amlogic/package.conf $UPGRADE_DIR/Amlogic $BUILD_IMAGES/${IMAGE_FILE_NAME}

And the links are as below:

khadas@0e524bdb85c1:~/fenix$ ll build/images_upgrade-d0bcc7f98d8294fc9554d07370270610c6732168/Amlogic/
total 1268
drwxr-xr-x 2 khadas khadas    4096 Dec  6 14:48 ./
drwxr-xr-x 4 khadas khadas    4096 Nov 21 12:05 ../
-rw-r--r-- 1 khadas khadas     589 Jul  1  2023 aml_sdc_burn.ini
-rw-r--r-- 1 khadas khadas 1048576 Jul  1  2023 fake-rootfs.img
lrwxrwxrwx 1 root   root        83 Dec  6 14:48 kvim.dtb -> /home/khadas/fenix/build/linux/common_drivers/arch/arm64/boot/dts/amlogic/kvim3.dtb
lrwxrwxrwx 1 root   root        40 Dec  6 14:48 logo.img -> /home/khadas/fenix/build/images/logo.img
lrwxrwxrwx 1 root   root        16 Dec  6 14:48 package.conf -> package_g12.conf
-rw-r--r-- 1 khadas khadas    1179 Jul  1  2023 package_dualos.conf
-rw-r--r-- 1 khadas khadas     910 Jul  1  2023 package_g12.conf
-rw-r--r-- 1 khadas khadas     921 Jul  1  2023 package_gx.conf
-rw-r--r-- 1 khadas khadas    1204 Jul  1  2023 package_s4.conf
-rw-r--r-- 1 khadas khadas    1199 Jul  1  2023 package_t7.conf
lrwxrwxrwx 1 root   root        17 Dec  6 14:48 platform.conf -> platform_g12.conf
-rw-r--r-- 1 khadas khadas     155 Jul  1  2023 platform_g12.conf
-rw-r--r-- 1 khadas khadas     202 Jul  1  2023 platform_gx.conf
-rw-r--r-- 1 khadas khadas      32 Jul  1  2023 platform_s4.conf
-rw-r--r-- 1 khadas khadas      28 Jul  1  2023 platform_t7.conf
lrwxrwxrwx 1 root   root        42 Dec  6 14:48 rootfs.img -> /home/khadas/fenix/build/images/rootfs.img
lrwxrwxrwx 1 root   root        51 Dec  6 14:48 u-boot.bin -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin
lrwxrwxrwx 1 root   root        58 Dec  6 14:48 u-boot.bin.sd.bin -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.sd.bin
lrwxrwxrwx 1 root   root        65 Nov 29 19:47 u-boot.bin.sd.bin.signed -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.sd.bin.signed
lrwxrwxrwx 1 root   root        58 Nov 29 19:47 u-boot.bin.signed -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.signed
lrwxrwxrwx 1 root   root        59 Dec  6 14:48 u-boot.bin.usb.bl2 -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.usb.bl2
lrwxrwxrwx 1 root   root        62 Nov 29 19:47 u-boot.bin.usb.signed -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.usb.signed
lrwxrwxrwx 1 root   root        59 Dec  6 14:48 u-boot.bin.usb.tpl -> /home/khadas/fenix/build/u-boot/fip/_tmp/u-boot.bin.usb.tpl
-rw-r--r-- 1 khadas khadas  188400 Jul  1  2023 usb_flow.aml

Thanks @numbqq, I was already doing this and then got errors as shown in my post. I have replaced my own uboot.bin and replaced kvim3.dtb by my own dtb file meson-g12b-a311d-khadas-vim3.dtb (the “printenv fdtfile” in my uboot). Regarding the mainline kernel, are the config of package.conf and plateform.conf different? (or any info/doc about how I should modify them?)

Which U-boot and kernel you used?

Kernel 6.0.0-yocto-standard and U-Boot 2024.07 used in my yocto.

This version of u-boot not support to use aml flash tool to upgrade the image, only the vendor 2015 u-boot this feature.

OK, for this version USB_Burning_Tool in Windows does not work either? I have also an error.
There is a mainline version uboot 2024.10 in fenix project, for this option, how can we flash it in emmc without entering in a SD card OS?

Yes.

You need boot from sd card and write it to emmc via command sudo emmc-install.

Is emmc-install used to flash the whole current image of the SD card to the eMMC? However, can it flash an external image file (e.g., a .img file stored on the SD card) to the eMMC?
Do we have access to the source code for this program to make it integrable with other OS?

Yes, you can boot from other media, e.g. SD or USB storage, and just use dd command to write the whole .img file to eMMC.

As the aml flash tool does not work for mainline u-boot, I flashed image which has boot and rootfs partitions directly into /dev/mmcblk0. (I did not pack it using aml_image_v2_packer).

After flashing my image, the new u-boot only works for the first boot, after a reboot, it reverts to using the old Fenix u-boot.

If using the U-Boot console to write the new u-boot, it can work after reboots.

kvim3#fatload mmc 0:1 0x1080000 u-boot.bin.mmc.bin
reading u-boot.bin.mmc.bin
1654128 bytes read in 96 ms (16.4 MiB/s)

kvim3#store rom_write 0x1080000 0 $filesize
Wrting blocks 1 to 3231 @ user
Wrting blocks 1 to 3231 @ boot0
boot_info.rsv_base_addr : 12000
boot_info.ddr.addr : 4000
boot_info.ddr.size : 0004
boot_info.version : 0001
boot_info.checksum : 16005
Wrting blocks 1 to 3231 @ boot1
boot_info.rsv_base_addr : 12000
boot_info.ddr.addr : 4000
boot_info.ddr.size : 0004
boot_info.version : 0001
boot_info.checksum : 16005

Should I perform any specific operations on /dev/mmcblk0boot0 or /dev/mmcblk0boot1 to correctly flash u-boot using dd?

You need also dd u-boot to /dev/mmcblk0boot0 and /dev/mmcblk0boot1 , check here: