Skip to content

Conversation

phodina
Copy link
Contributor

@phodina phodina commented Aug 15, 2025

No description provided.

@phodina phodina mentioned this pull request Aug 15, 2025
@phodina phodina force-pushed the ambarella-upstream branch from d9c7d51 to 0887d7d Compare August 15, 2025 15:05

[example](../src/snagrecover/templates/ambarella-cv22.yaml)

Ambarella SDK requires NDA in order to build the Amboot which is proprietary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is a proprietary bootloader

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's these file that after the DRAM is initialized are loaded and facilitate the next stage in the bootloader process:

find ./usr/share/ambausb-4.3.2/platform -iname "*.elf"
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5lm_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5l_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5l_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5l_4Gb_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5lm_bld_spinor.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5lm_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5lm_bld_spinor_spansion.elf
./usr/share/ambausb-4.3.2/platform/s5l/bld/s5l_4Gb_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/cv25/bld/cv25_bld_linux_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv25/bld/cv25_bld_linux_stack.elf
./usr/share/ambausb-4.3.2/platform/cv25/bld/cv25_bld_rtos_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv25/bld/cv25_bld_rtos_nand.elf
./usr/share/ambausb-4.3.2/platform/cv25/bld/cv25_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/cv2fs/bld/cv2fs_bld_rtos_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv2fs/bld/cv2fs_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/cv28/bld/cv28_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/cv28/bld/cv28_bld_linux_emmc.elf
./usr/share/ambausb-4.3.2/platform/s5/bld/s5_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s5/bld/s5_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/cv22/bld/cv22_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/cv22/bld/cv22_bld_linux_stack.elf
./usr/share/ambausb-4.3.2/platform/cv22/bld/cv22_bld_linux_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv2/bld/cv2_bld_linux_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv2/bld/cv2_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3lm_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3l_bld_spinor.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3l_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3l_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3lm_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3lm_bld_spinor.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3lm_bld_spinor_spansion.elf
./usr/share/ambausb-4.3.2/platform/s3l/bld/s3l_bld_spinor_spansion.elf
./usr/share/ambausb-4.3.2/platform/cv1/bld/cv1_bld_linux_emmc.elf
./usr/share/ambausb-4.3.2/platform/cv1/bld/cv1_bld_linux_nand.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2lm_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2l_bld_spinor_spansion.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2l_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2l_bld_spinor.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2l_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2lm_bld_spinor.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2lm_bld_spinor_spansion.elf
./usr/share/ambausb-4.3.2/platform/s2l/bld/s2lm_bld_emmc.elf
./usr/share/ambausb-4.3.2/platform/s6lm/bld/s6lm_bld_nand.elf
./usr/share/ambausb-4.3.2/platform/s6lm/bld/s6lm_bld_stack.elf
./usr/share/ambausb-4.3.2/platform/s6lm/bld/s6lm_bld_emmc.elf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ELF is preconfigured for the platform and the nonvolatile storage - nand, emmc or spinor. It also sets up the USB device.

Sure user could provide their own implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They provide a patch for mainline kernel. This available publicly online and probably could be reimplemented.

https://github.com/adipierro/ambarella/blob/master/ambarella/kernel/linux-3.10-ambarella.patch

@phodina phodina force-pushed the ambarella-upstream branch from 0887d7d to 36c9634 Compare August 15, 2025 15:09
@phodina
Copy link
Contributor Author

phodina commented Aug 15, 2025

Also not sure about the ADS files as they are crucial to setup the DRAM:

find ./usr/share/ambausb-4.3.2/platform -iname "*.ads"
./usr/share/ambausb-4.3.2/platform/a5s/ads/a5s_ddr3.ads
./usr/share/ambausb-4.3.2/platform/a5s/ads/a5s_ddr2.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/s5l_lpddr4.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/s5lm_lpddr3_456MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_lpddr4_600MHz_32b.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/s5lm_ddr3_456MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_lpddr4_420MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_ddr3_456MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_lpddr3_456MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/s5l_4Gb_lpddr3_456MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_lpddr4_300MHz.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/h22_lpddr4_612MHz_16b.ads
./usr/share/ambausb-4.3.2/platform/s5l/ads/s5l_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s3/ads/s3_lpddr3_micron_EDF8132A3MAJDFD.ads
./usr/share/ambausb-4.3.2/platform/s3/ads/s3_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s3/ads/s3_lpddr3_hynix_H9CCNNN8GTMLAR.ads
./usr/share/ambausb-4.3.2/platform/cv25/ads/cv25m_lpddr4_540MHz.ads
./usr/share/ambausb-4.3.2/platform/cv25/ads/cv25m_ddr4_792MHz.ads
./usr/share/ambausb-4.3.2/platform/cv25/ads/cv25_ddr4_792MHz.ads
./usr/share/ambausb-4.3.2/platform/cv25/ads/cv25_lpddr4_540MHz.ads
./usr/share/ambausb-4.3.2/platform/cv25/ads/cv25bub_lpddr4_840MHz.ads
./usr/share/ambausb-4.3.2/platform/s2e/ads/s2e_lpddr3_micron_EDF8132A3MAJDFD.ads
./usr/share/ambausb-4.3.2/platform/s2e/ads/s2e_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s2e/ads/s2e_lpddr3_hynix_H9CCNNN8GTMLAR.ads
./usr/share/ambausb-4.3.2/platform/s2e/ads/s2e_lpddr3_micron_MT29UZ4B8DZZHGPB.ads
./usr/share/ambausb-4.3.2/platform/cv2fs/ads/cv2fs_lpddr4_816MHz.ads
./usr/share/ambausb-4.3.2/platform/cv2fs/ads/cv2fs_boot.ads
./usr/share/ambausb-4.3.2/platform/a9aq/ads/a9aq_ddr3_600MHz.ads
./usr/share/ambausb-4.3.2/platform/a9aq/ads/a9aqb_ddr3_216MHz.ads
./usr/share/ambausb-4.3.2/platform/cv28/ads/cv28_ddr4_540MHz.ads
./usr/share/ambausb-4.3.2/platform/cv28/ads/cv28_lpddr4_540MHz.ads
./usr/share/ambausb-4.3.2/platform/s5/ads/s5_16Gb_ddr3_336MHz.ads
./usr/share/ambausb-4.3.2/platform/s5/ads/s5_16Gb_lpddr3_336MHz.ads
./usr/share/ambausb-4.3.2/platform/s5/ads/s5_8Gb_ddr3_336MHz.ads
./usr/share/ambausb-4.3.2/platform/s5/ads/s5_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s5/ads/s5_lpddr3.ads
./usr/share/ambausb-4.3.2/platform/cv22/ads/cv22_lpddr4_408MHz.ads
./usr/share/ambausb-4.3.2/platform/s2/ads/s2_ddr3.ads
./usr/share/ambausb-4.3.2/platform/cv2/ads/cv2_lpddr4_408MHz.ads
./usr/share/ambausb-4.3.2/platform/cv2/ads/cv2_dk_lpddr4_408MHz.ads
./usr/share/ambausb-4.3.2/platform/cv2/ads/cv2_lpddr4_396MHz.ads
./usr/share/ambausb-4.3.2/platform/cv2/ads/cv2_lpddr4_420MHz_rtos.ads
./usr/share/ambausb-4.3.2/platform/cv2/ads/cv2_lpddr4_420MHz.ads
./usr/share/ambausb-4.3.2/platform/s3l/ads/s3lm_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s3l/ads/s3l_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s3l/ads/s3l_lpddr3.ads
./usr/share/ambausb-4.3.2/platform/s3l/ads/s3lm_lpddr3.ads
./usr/share/ambausb-4.3.2/platform/cv1/ads/cv1_lpddr4_1200MHz.ads
./usr/share/ambausb-4.3.2/platform/cv1/ads/cv1_lpddr4_1416MHz.ads
./usr/share/ambausb-4.3.2/platform/s2l/ads/a12_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s2l/ads/a12_lpddr3.ads
./usr/share/ambausb-4.3.2/platform/s2l/ads/s2lm_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s2l/ads/s2l_ddr3.ads
./usr/share/ambausb-4.3.2/platform/s6lm/ads/s6lm_lpddr4_792MHz.ads
./usr/share/ambausb-4.3.2/platform/s6lm/ads/s6lm_lpddr4_540MHz.ads
./usr/share/ambausb-4.3.2/platform/s6lm/ads/h32_lpddr4_396MHz.ads
./usr/share/ambausb-4.3.2/platform/s6lm/ads/s6lm_ddr4_792MHz.ads
./usr/share/ambausb-4.3.2/platform/a7l/ads/a7l_ddr3.ads

I mean if they could be shared or the user needs to install the tool from vendor and use them from the disc.

@rgantois
Copy link
Collaborator

Hi, thanks a lot for the big contrib :) I'm a bit short on time right now but I'll review this as soon as I can.

@phodina
Copy link
Contributor Author

phodina commented Aug 28, 2025

@rgantois Sure, no problem.

@phodina phodina force-pushed the ambarella-upstream branch 3 times, most recently from 15a3961 to 70e1964 Compare September 2, 2025 16:31
Implements the Ambarella USB protocol handler with:
- Command/response packet handling
- File transfer support
- Device info queries
- Error handling
Implements firmware handling for Ambarella devices:
- Bootloader and DRAM script loading
- Firmware info extraction
- Board/firmware info structure packing
- Error handling
Implements recovery flow for Ambarella devices:
- ADS script parser for DRAM configuration
- DRAM initialization support
- Bootloader loading and execution
- Firmware flashing with proper addressing
- Complete recovery process handling
Adds recovery configuration template for CV22:
- Device identification (VID/PID)
- Required firmware files
- Recovery steps and flow
- Documentation and notes
@phodina
Copy link
Contributor Author

phodina commented Sep 4, 2025

@rgantois rebased to solve the conflicts and reformatted the code to pass all the checks

Copy link
Collaborator

@rgantois rgantois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've requested some changes. Please let me know if you have questions.

2. The USB cable is connected to the correct port (usually the OTG port)
3. The board is powered on

### DRAM initialization fails
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, this applies to every board which relies on closed-source firmware binaries.

family: sunxi
v853:
family: sunxi
cv22:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SoC models should only appear once in supported_socs.yaml, either in the "tested" section or the "untested" one. This one appears in both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will keep the cv22 under tested, rest untested as I don't have the HW.


zynqmp_run(port, fw_name, fw_blob, subfw_name)
elif soc_family == "bcm":
from snagrecover.firmware.bcm import bcm_run
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit-wide comment: the commit history of Snagboot should be bisectable as much as possible, meaning each commit should allow Snagboot to run without errors.

In this commit, you're adding references to modules which don't exist yet.

I'd prefer if you reordered the commits so that each one is valid Python. So in this specific case, the commits adding the protocol and firmware code should come before this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will rearrange the code so it's self contained and does not require any future code.

pid: 0xc022 # CV22 product ID

# Recovery protocol
protocol: amba
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is information about some internal details of the snagrecover code, it shouldn't be included in the user interface.

# DRAM initialization script
dram_script:
path: cv22_lpddr4_408MHz.ads
description: DRAM initialization script for CV22 LPDDR4 at 408MHz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have a description here, but it's also repetitive, as this information is already given in the fw_binaries docs. I don't have a definitive opinion about this yet.


# Recovery steps
steps:
- name: Initialize DRAM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that it's documentation for how snagrecover works internally. So if the recovery process or the nomenclature evolves at some point, we'll have to keep this template up to date as well.

Moreover, the user ideally shouldn't have to worry about these details.

@phodina
Copy link
Contributor Author

phodina commented Sep 15, 2025

Thanks, I've requested some changes. Please let me know if you have questions.

thanks for review, will refactor the comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants