开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育
[PATCH 2/3] designware: Use the remove() method with related drivers 5
Hi Jonas, That's interesting. I wrote that code about 9 years ago so perhaps can be forgiven for forgetting. Very few drivers set the DM_FLAG_ACTIVE_DMA flag, certainly not the designware ones. So how would they be removed? Hmm yes I saw that but then apparently forgot to include it. I can perhaps redo this patch to add the DMA flag. Yes, I wasn't sure which way to go on that. I'll remove them. Regards, Simon
Started by Simon Glass @ · Most recent @
[PATCH v2 2/4] net: designware: Mark drivers as having active DMA
Network devices which use this driver have DMA running while receiving packages. Add the required flag to driver model so that they will be removed before starting the OS. Signed-off-by: Simon Glass <sjg@...> --- Changes in v2: - Add a new patch to mark drivers as having active DMA drivers/net/designware.c | 2 +- drivers/net/dwmac_meson8b.c | 2 +- drivers/net/dwmac_s700.c | 2 +- drivers/net/dwmac_socfpga.c | 2 +- drivers/net/gmac_rockchip.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 5385849ea6b..9b2b0a5d602 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -885,7 +885,7 @@ U_BOOT_DRIVER(eth_designware) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dw_eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, }; static struct pci_device_id supported[] = { diff --git a/drivers/net/dwmac_meson8b.c b/drivers/net/dwmac_meson8b.c index bf94e50842d..95a99a98e99 100644 --- a/drivers/net/dwmac_meson8b.c +++ b/drivers/net/dwmac_meson8b.c @@ -162,5 +162,5 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, }; diff --git a/drivers/net/dwmac_s700.c b/drivers/net/dwmac_s700.c index e78193f3376..21df8e3ce81 100644 --- a/drivers/net/dwmac_s700.c +++ b/drivers/net/dwmac_s700.c @@ -64,5 +64,5 @@ U_BOOT_DRIVER(dwmac_s700) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, }; diff --git a/drivers/net/dwmac_socfpga.c b/drivers/net/dwmac_socfpga.c index dda33f90d65..9f262aaee60 100644 --- a/drivers/net/dwmac_socfpga.c +++ b/drivers/net/dwmac_socfpga.c @@ -145,5 +145,5 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, }; diff --git a/drivers/net/gmac_rockchip.c b/drivers/net/gmac_rockchip.c index 5c542d62bd8..52be3a5687f 100644 --- a/drivers/net/gmac_rockchip.c +++ b/drivers/net/gmac_rockchip.c @@ -760,5 +760,5 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat), - .flags = DM_FLAG_ALLOC_PRIV_DMA, + .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA, }; -- 2.43.0
Started by Simon Glass @
[GIT PULL] Please pull u-boot-amlogic-20250404 into master 2
Hi Tom, Here's a last minute fix for the libre-computer boards fixing the capsule update feature. Thanks, Neil The following changes since commit 82b69fc4224432d5aefa7ca750d950374cbc7fb2: Merge tag 'efi-2025-04-rc6' of https://source.denx.de/u-boot/custodians/u-boot-efi (2025-04-03 07:31:28 -0600) are available in the Git repository at: https://source.denx.de/u-boot/custodians/u-boot-amlogic.git tags/u-boot-amlogic-20250404 for you to fetch changes up to c5fd2c7ac7fa4835339ea09ead2884794314c9d8: board: libre-computer: check interface before comparing it in set_dfu_alt_info() (2025-04-04 10:37:40 +0200) ---------------------------------------------------------------- - check interface before comparing it in set_dfu_alt_info() to avoid hard crash on capsule update ---------------------------------------------------------------- Neil Armstrong (1): board: libre-computer: check interface before comparing it in set_dfu_alt_info() board/libre-computer/aml-a311d-cc/aml-a311d-cc.c | 2 +- board/libre-computer/aml-s805x-ac/aml-s805x-ac.c | 2 +- board/libre-computer/aml-s905d3-cc/aml-s905d3-cc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Started by Neil Armstrong @ · Most recent @
[PATCH v2 1/4] designware: Use the remove() method with related drivers
Several drivers make use of the designware Ethernet driver but do not implement the remove() method. Add this to keep things tidy. Note that the Ethernet uclass calls each driver's stop() method on removal, so there is no need to do that here. Signed-off-by: Simon Glass <sjg@...> Reported-by: Christian Kohlschütter <christian@...> --- Changes in v2: - Use the designware_eth_remove() method directly - Add gmac_rockchip too - Reword the commit message to mention the uclass' actions drivers/net/designware.c | 2 +- drivers/net/designware.h | 12 ++++++++++++ drivers/net/dwmac_meson8b.c | 1 + drivers/net/dwmac_s700.c | 1 + drivers/net/dwmac_socfpga.c | 1 + drivers/net/gmac_rockchip.c | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 07b0f49ef58..5385849ea6b 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -805,7 +805,7 @@ clk_err: return err; } -static int designware_eth_remove(struct udevice *dev) +int designware_eth_remove(struct udevice *dev) { struct dw_eth_dev *priv = dev_get_priv(dev); diff --git a/drivers/net/designware.h b/drivers/net/designware.h index e47101ccaf6..8c9d0190e03 100644 --- a/drivers/net/designware.h +++ b/drivers/net/designware.h @@ -247,6 +247,18 @@ struct dw_eth_dev { int designware_eth_of_to_plat(struct udevice *dev); int designware_eth_probe(struct udevice *dev); + +/** + * designware_eth_remove() - Remove the device + * + * Disables DMA and marks the device as remove. This must be called before + * booting an OS, to ensure that DMA is inactive. + * + * @dev: Device to remove + * Return 0 if OK, -ve on error + */ +int designware_eth_remove(struct udevice *dev); + extern const struct eth_ops designware_eth_ops; struct dw_eth_pdata { diff --git a/drivers/net/dwmac_meson8b.c b/drivers/net/dwmac_meson8b.c index fde4aabbace..bf94e50842d 100644 --- a/drivers/net/dwmac_meson8b.c +++ b/drivers/net/dwmac_meson8b.c @@ -158,6 +158,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat), diff --git a/drivers/net/dwmac_s700.c b/drivers/net/dwmac_s700.c index 969d247b4f3..e78193f3376 100644 --- a/drivers/net/dwmac_s700.c +++ b/drivers/net/dwmac_s700.c @@ -60,6 +60,7 @@ U_BOOT_DRIVER(dwmac_s700) = { .of_match = dwmac_s700_ids, .of_to_plat = dwmac_s700_of_to_plat, .probe = dwmac_s700_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct eth_pdata), diff --git a/drivers/net/dwmac_socfpga.c b/drivers/net/dwmac_socfpga.c index a9e2d8c0972..dda33f90d65 100644 --- a/drivers/net/dwmac_socfpga.c +++ b/drivers/net/dwmac_socfpga.c @@ -141,6 +141,7 @@ U_BOOT_DRIVER(dwmac_socfpga) = { .of_match = dwmac_socfpga_ids, .of_to_plat = dwmac_socfpga_of_to_plat, .probe = dwmac_socfpga_probe, + .remove = designware_eth_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_socfpga_plat), diff --git a/drivers/net/gmac_rockchip.c b/drivers/net/gmac_rockchip.c index 8cfeeffe95b..5c542d62bd8 100644 --- a/drivers/net/gmac_rockchip.c +++ b/drivers/net/gmac_rockchip.c @@ -756,6 +756,7 @@ U_BOOT_DRIVER(eth_gmac_rockchip) = { .of_match = rockchip_gmac_ids, .of_to_plat = gmac_rockchip_of_to_plat, .probe = gmac_rockchip_probe, + .remove = designware_eth_remove, .ops = &gmac_rockchip_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct gmac_rockchip_plat), -- 2.43.0
Started by Simon Glass @
[PATCH v2 0/4] dm: net: Assorted patches related to networking and DMA
This series collects together a few patches related to U-Boot leaving DMA running when booting. Changes in v2: - Use the designware_eth_remove() method directly - Add gmac_rockchip too - Reword the commit message to mention the uclass' actions - Add a new patch to mark drivers as having active DMA Simon Glass (4): designware: Use the remove() method with related drivers net: designware: Mark drivers as having active DMA efi_loader: Move device-removal later in exit-boot-services dm: core: Rename dm_remove_devices_active() arch/arm/lib/bootm.c | 4 ++-- arch/riscv/lib/bootm.c | 2 +- arch/x86/lib/bootm.c | 2 +- drivers/core/root.c | 2 +- drivers/net/designware.c | 4 ++-- drivers/net/designware.h | 12 ++++++++++++ drivers/net/dwmac_meson8b.c | 3 ++- drivers/net/dwmac_s700.c | 3 ++- drivers/net/dwmac_socfpga.c | 3 ++- drivers/net/gmac_rockchip.c | 3 ++- include/dm/root.h | 6 +++--- lib/efi_loader/efi_boottime.c | 21 +++++++++++++-------- test/dm/core.c | 2 +- 13 files changed, 44 insertions(+), 23 deletions(-) -- 2.43.0 base-commit: d47b5693e21f78d8cd8caa8fcd9e64fd6ae85759 branch: eth2
Started by Simon Glass @
[PATCH v2 2/4] net: designware: Mark drivers as having active DMA
Reviewed-by: Neil Armstrong <neil.armstrong@...>
Started by Neil Armstrong @
[PATCH v2 1/4] designware: Use the remove() method with related drivers
Reviewed-by: Neil Armstrong <neil.armstrong@...>
Started by Neil Armstrong @
[PATCH] configs: meson64: move DFU step at the end to give the board a chance to boot something on storage 2
The DFU was set to run at the beginning, but we may want to boot something over USB, MMC or Ethernet even if booted over USB, so move the DFU as the final fallback. This keeps the current Amlogic U-Boot CI working and makes the default config more generic. Signed-off-by: Neil Armstrong <neil.armstrong@...> --- include/configs/meson64.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/configs/meson64.h b/include/configs/meson64.h index f3275b37a516da6befd41324ddb2a3fe1f36fc83..675df623311f361f3a55971c3894ffbe1d07fee6 100644 --- a/include/configs/meson64.h +++ b/include/configs/meson64.h @@ -118,13 +118,13 @@ #ifndef BOOT_TARGET_DEVICES #define BOOT_TARGET_DEVICES(func) \ func(ROMUSB, romusb, na) \ - func(USB_DFU, usbdfu, na) \ BOOT_TARGET_MMC(func) \ BOOT_TARGET_DEVICES_USB(func) \ BOOT_TARGET_NVME(func) \ BOOT_TARGET_SCSI(func) \ BOOT_TARGET_PXE(func) \ - BOOT_TARGET_DHCP(func) + BOOT_TARGET_DHCP(func) \ + func(USB_DFU, usbdfu, na) #endif #define BOOTM_SIZE __stringify(0x1700000) --- base-commit: c17f03a7e93dfbbe5d32f5738274187065d9493f change-id: 20250402-u-boot-meson64-move-dfu-end-eb9f5fe55608 Best regards, -- Neil Armstrong <neil.armstrong@...>
Started by Neil Armstrong @ · Most recent @
[PATCH v1 00/11] Amlogic: ADNL and Optimus protocols support 2
This patchset adds support of two Amlogic firmware burning protocols: ADNL and Optimus. Each protocol is supported on the following SoC: axg, g12a, g12b, sm1 - Optimus. a1, s4, a5, c1, c2, c3, sc2, t3, t7, p1 - ADNL. Both work in fastboot manner, but significant feature is that they are supported by current Amlogic BootROMs. As transport both use USB: device is switched to gadget mode and then it can communicate with PC. On PC side protocols are supported by: 1) https://github.com/superna9999/pyamlboot (with some limitation) For example: pyamlboot/./ubt.py --img <image> --wipe all --reset Note, image has special format, specific for Amlogic. 2) Proprietary vendor tools. As protocols are supported by BootROM, it allows to "resurrect" devices when boot image (BL2, Uboot) missed/invalid. Typical flow for such cases is (both protocols): DEVICE PC *-------------------* | | | Runs update tool, | | waits for device | | on USB bus. | | | *-------------------* | *---------------------* | | Power on |<-----<------/ *---------------------* | | *---------------------* | | | Boot ROM switches | | device to USB gadget|>----->------\ | mode and waits for | | | commands. | | | | | *---------------------* | | *-------------------* | Detects device on | | USB bus. | *-------------------* | | *-------------------* | Sends BL2 image | | over USB. | *-------------------* | *---------------------* | | Boot ROM runs |<-----<------/ | BL2 image. | *---------------------* | | *---------------------* | BL2 waits for |>----->------\ | Uboot image (FIP). | | *---------------------* | | *-------------------* | Sends Uboot image | | over USB. | *-------------------* | *---------------------* | | BL2 runs received |<-----<------/ | Uboot image. | *---------------------* | | *---------------------* | Uboot waits for |>----->------\ | commands. | | *---------------------* | | *-------------------* | Sends commands to | | over USB. | *-------------------* | *---------------------* | | Uboot processes | | | commands: erases, | | | writes NAND, checks |<-----<------/ | CRC of written data | | etc. | *---------------------* | | *---------------------* | Uboot does reboot | *---------------------* There is also another mode to operate both protocols when we run not from BootROM, but from Uboot shell. To do that, we enter protocol specific command in shell ("adnl" or "optimus"). In this case Uboot switches device to gadget mode, write some value to special register and does reboot. Then BootROM checks above mentioned register and then switches device to gadget mode. After that flow from above is executed. This mode has same purposes as image update by 'fastboot'. Limitations: 1) Only limited set of each protocol commands are supported - it is enough to update image. But, for example 'secureboot' feature is not implemented. 2) ADNL was tested on A1 SoC only. 3) Optimus was tested on AXG SoC only. For more details of each protocol pls see the following: ADNL - drivers/usb/gadget/amlogic/adnl/f_adnl.c Optimus - drivers/usb/gadget/amlogic/optimus/f_optimus.c. Arseniy Krasnov (8): arch: arm: meson: use 'meson_sm_call()' in 'meson_sm_pwrdm_set()' usb: gadget: fastboot: make part of USB fastboot code shared usb: gadget: amlogic: common code for Amlogic flashing commands mtd: rawnand: meson: move some defines to dedicated header arch: arm: meson: bootloader write support arm: meson: a1: add A1_SYSCTRL_SEC_STICKY_REG2 usb: gadget: amlogic: implement ADNL protocol arm: meson: a1: ADNL protocol support Vladimir Mitrofanov (3): arch: arm: meson: sm: add commands to reboot device in different modes usb: gadget: amlogic: implement Optimus protocol arch: arm: axg: Optimus protocol support arch/arm/include/asm/arch-meson/a1.h | 19 + arch/arm/include/asm/arch-meson/axg.h | 12 + arch/arm/include/asm/arch-meson/nand.h | 34 + arch/arm/include/asm/arch-meson/rawnand.h | 38 + arch/arm/include/asm/arch-meson/sm.h | 98 +- arch/arm/include/asm/arch-meson/spinand.h | 43 + arch/arm/mach-meson/Kconfig | 31 + arch/arm/mach-meson/Makefile | 4 +- arch/arm/mach-meson/board-a1.c | 32 +- arch
Started by Arseniy Krasnov @ · Most recent @
[PATCH v1 07/11] arm: meson: a1: add A1_SYSCTRL_SEC_STICKY_REG2
This register is used by ADNL protocol, to check boot source of current U-boot instance. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/include/asm/arch-meson/a1.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/include/asm/arch-meson/a1.h b/arch/arm/include/asm/arch-meson/a1.h index 86d1a68de8c..16e209ed932 100644 --- a/arch/arm/include/asm/arch-meson/a1.h +++ b/arch/arm/include/asm/arch-meson/a1.h @@ -13,6 +13,12 @@ #define A1_SYSCTRL_ADDR(off) (A1_SYSCTRL_BASE + ((off) << 2)) #define A1_SYSCTRL_SEC_STATUS_REG4 A1_SYSCTRL_ADDR(0xc4) +/* + * Checked during boot. Tells, that previous code, e.g. + * executed before reboot requested to continue boot + * from USB. Used by ADNL protocol. + */ +#define A1_SYSCTRL_SEC_STICKY_REG2 A1_SYSCTRL_ADDR(0xe2) #define A1_SYSCTRL_MEM_SIZE_MASK 0xFFFF0000 #define A1_SYSCTRL_MEM_SIZE_SHIFT 16 -- 2.30.1
Started by Arseniy Krasnov @
[PATCH v1 06/11] arch: arm: meson: bootloader write support
BootROM of Amlogic SoCs that use ADNL/Optimus protocols needs special layout of "bootloader" partition. So let's implement functions that support bootloader writing on such SoCs. This is prerequisite for ADNL/Optimus implementation. We place such functions to 'arch/arm/mach-meson', because this code is also needed by 'fastboot' protocol which can also write "bootloader" partition. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/include/asm/arch-meson/nand.h | 34 +++ arch/arm/include/asm/arch-meson/spinand.h | 43 ++++ arch/arm/mach-meson/Kconfig | 31 +++ arch/arm/mach-meson/Makefile | 4 +- arch/arm/mach-meson/rawnand.c | 291 ++++++++++++++++++++++ arch/arm/mach-meson/spinand.c | 158 ++++++++++++ 6 files changed, 559 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/arch-meson/nand.h create mode 100644 arch/arm/include/asm/arch-meson/spinand.h create mode 100644 arch/arm/mach-meson/rawnand.c create mode 100644 arch/arm/mach-meson/spinand.c diff --git a/arch/arm/include/asm/arch-meson/nand.h b/arch/arm/include/asm/arch-meson/nand.h new file mode 100644 index 00000000000..1f5a20d237b --- /dev/null +++ b/arch/arm/include/asm/arch-meson/nand.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2023-2024 SaluteDevices, Inc. + */ + +#ifndef __MESON_NAND_H__ +#define __MESON_NAND_H__ + +#define BOOT_LOADER "bootloader" +#define BOOT_BL2 "bl2" +#define BOOT_SPL "spl" +#define BOOT_TPL "tpl" +#define BOOT_FIP "fip" + +#define BL2_COPY_NUM (CONFIG_MESON_BL2_COPY_NUM) +#define BL2_IMAGE_SIZE_PER_COPY (CONFIG_MESON_BL2_IMAGE_SIZE) +#define BL2_TOTAL_PAGES 1024 + +#define TPL_COPY_NUM (CONFIG_MESON_TPL_COPY_NUM) +#define TPL_SIZE_PER_COPY 0x200000 + +#define NAND_RSV_BLOCK_NUM 48 + +/** + * meson_bootloader_write - write 'bootloader' partition to NAND + * according to the required layout. It will + * write BL2, TPL and info pages. + * + * @buf: buffer with BL2 and TPL + * @length: buffer length + * @return: 0 on success, -errno otherwise. + */ +int meson_bootloader_write(unsigned char *buf, size_t length); +#endif diff --git a/arch/arm/include/asm/arch-meson/spinand.h b/arch/arm/include/asm/arch-meson/spinand.h new file mode 100644 index 00000000000..1628c8bd4e0 --- /dev/null +++ b/arch/arm/include/asm/arch-meson/spinand.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2024 SaluteDevices, Inc. + */ + +#ifndef __MESON_SPINAND_H__ +#define __MESON_SPINAND_H__ + +#include <stdint.h> +#include <string.h> +#include <asm/types.h> +#include <asm/arch-meson/nand.h> +#include <linux/compiler_attributes.h> +#include <linux/mtd/mtd.h> + +struct meson_spi_nand_info_page { + char magic[8]; /* Magic header of info page. */ + /* Info page version, +1 when you update this struct. */ + u8 version; /* 1 for now. */ + u8 mode; /* 1 discrete, 0 compact. */ + u8 bl2_num; /* bl2 copy number. */ + u8 fip_num; /* fip copy number. */ + union { + struct { + u8 rd_max; /* spi nand max read io. */ + u8 oob_offset; /* User bytes offset. */ + u8 planes_per_lun; /* number of planes per LUN. */ + u8 rsv; /* Reserved gap. */ + u32 fip_start; /* Start pages. */ + u32 fip_pages; /* Pages per fip. */ + u32 page_size; /* spi nand page size (bytes). */ + u32 page_per_blk; /* Page number per block. */ + u32 oob_size; /* Valid oob size (bytes). */ + u32 bbt_start; /* BBT start pages. */ + u32 bbt_valid; /* BBT valid offset pages. */ + u32 bbt_size; /* BBT occupied bytes. */ + } __packed spinand; /* spi nand. */ + struct { + u32 reserved; + } emmc; + } dev; +} __packed; +#endif diff --git a/arch/arm/mach-meson/Kconfig b/arch/arm/mach-meson/Kconfig index 7570f48e25f..883ee78f49b 100644 --- a/arch/arm/mach-meson/Kconfig +++ b/arch/arm/mach-meson/Kconfig @@ -93,4 +93,35 @@ config SYS_BOARD Based on this option board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD> will be used. +config MESON_BL2_COPY_NUM + depends on ADNL || FASTBOOT_FLASH + int "Number of BL2 copies written to storage" + default 8 + help + The ADNL / Optimus / fastboot protocol writes several copies of BL2 + bootloader during fi
Started by Arseniy Krasnov @
[PATCH v1 03/11] usb: gadget: fastboot: make part of USB fastboot code shared
This is preparation for fastboot-based flashing protocols (such as Amlogic ADNL). When device enters ADNL mode, it becomes "fastboot" device from USB point of view, so to avoid copy-paste of USB part of fastboot protocol, reimplement it as shared code between fastboot and ADNL implementations. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- drivers/usb/gadget/Makefile | 2 +- drivers/usb/gadget/f_fastboot.c | 295 +---------------------- drivers/usb/gadget/f_fastboot_common.c | 320 +++++++++++++++++++++++++ drivers/usb/gadget/f_fastboot_common.h | 71 ++++++ 4 files changed, 403 insertions(+), 285 deletions(-) create mode 100644 drivers/usb/gadget/f_fastboot_common.c create mode 100644 drivers/usb/gadget/f_fastboot_common.h diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 4bda224ff1a..6c16ad83f6e 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -27,7 +27,7 @@ obj-$(CONFIG_USB_GADGET_DOWNLOAD) += g_dnl.o obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o obj-$(CONFIG_DFU_OVER_USB) += f_dfu.o obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o -obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o +obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o f_fastboot_common.o obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o obj-$(CONFIG_USB_FUNCTION_ROCKUSB) += f_rockusb.o obj-$(CONFIG_USB_FUNCTION_ACM) += f_acm.o diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 3c76d42c5ef..9298658b569 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -23,29 +23,7 @@ #include <linux/compiler.h> #include <g_dnl.h> #include <rabbith.h> - -#define FASTBOOT_INTERFACE_CLASS 0xff -#define FASTBOOT_INTERFACE_SUB_CLASS 0x42 -#define FASTBOOT_INTERFACE_PROTOCOL 0x03 - -#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0 (0x0200) -#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1 (0x0040) -#define TX_ENDPOINT_MAXIMUM_PACKET_SIZE (0x0040) - -#define EP_BUFFER_SIZE 4096 -/* - * EP_BUFFER_SIZE must always be an integral multiple of maxpacket size - * (64 or 512 or 1024), else we break on certain controllers like DWC3 - * that expect bulk OUT requests to be divisible by maxpacket size. - */ - -struct f_fastboot { - struct usb_function usb_function; - - /* IN/OUT EP's and corresponding requests */ - struct usb_ep *in_ep, *out_ep; - struct usb_request *in_req, *out_req; -}; +#include "f_fastboot_common.h" static char fb_ext_prop_name[] = "DeviceInterfaceGUID"; static char fb_ext_prop_data[] = "{4866319A-F4D6-4374-93B9-DC2DEB361BA9}"; @@ -66,113 +44,7 @@ static struct usb_os_desc_table fb_os_desc_table = { .os_desc = &fb_os_desc, }; -static inline struct f_fastboot *func_to_fastboot(struct usb_function *f) -{ - return container_of(f, struct f_fastboot, usb_function); -} - -static struct f_fastboot *fastboot_func; - -static struct usb_endpoint_descriptor fs_ep_in = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(64), -}; - -static struct usb_endpoint_descriptor fs_ep_out = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(64), -}; - -static struct usb_endpoint_descriptor hs_ep_in = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512), -}; - -static struct usb_endpoint_descriptor hs_ep_out = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512), -}; - -static struct usb_interface_descriptor interface_desc = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0x00, - .bAlternateSetting = 0x00, - .bNumEndpoints = 0x02, - .bInterfaceClass = FASTBOOT_INTERFACE_CLASS, - .bInterfaceSubClass
Started by Arseniy Krasnov @
[PATCH v1 02/11] arch: arm: meson: use 'meson_sm_call()' in 'meson_sm_pwrdm_set()'
Use more generic function in 'meson_sm_pwrdm_set()'. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/mach-meson/sm.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c index 53b07e1dfe9..0a781e9c47b 100644 --- a/arch/arm/mach-meson/sm.c +++ b/arch/arm/mach-meson/sm.c @@ -249,22 +249,16 @@ static int meson_sm_call(u32 smc, struct pt_regs *regs, s32 *retval) int meson_sm_pwrdm_set(size_t index, int cmd) { - struct udevice *dev; struct pt_regs regs = { 0 }; int err; - dev = meson_get_sm_device(); - if (IS_ERR(dev)) - return PTR_ERR(dev); - regs.regs[1] = index; regs.regs[2] = cmd; - err = sm_call(dev, MESON_SMC_CMD_PWRDM_SET, NULL, &regs); + err = meson_sm_call(MESON_SMC_CMD_PWRDM_SET, &regs, NULL); if (err) pr_err("Failed to %s power domain ind=%zu (%d)\n", cmd == PWRDM_ON ? "enable" : "disable", index, err); - return err; } -- 2.30.1
Started by Arseniy Krasnov @
[PATCH v1 01/11] arch: arm: meson: sm: add commands to reboot device in different modes
From: Vladimir Mitrofanov <vvmitrofanov@...> There are several commands to reboot device in specific mode (cold, normal, etc.), these commands helps to enter flashing mode and set boot source device: 1) MESON_SMC_CMD_BL1_FIRST_BOOT_SRC_SET This command tells BL1 that it must load BL2 from USB data path. It is used in ADNL protocol logic when burning process is started from the U-Boot command line: when 'adnl' is entered, this command tells BL1 to load BL2 from USB, then board is rebooted. After reboot BL2 and next stage loaders will be loaded from USB, sticky register has value that we are in ADNL mode, thus booted U-Boot enters ADNL mode to start data burning. Used in adnl-based SoC families: a1, s4, c1, с2, sc2, t7, etc. 2) MESON_SMC_CMD_REBOOT_MODE_SET Used in optimus-based SoC families: axg, g12a, g12b, sm1, etc. 3) MESON_SMC_CMD_USB_BOOT_MODE_SET Used in optimus-based SoC families: axg, g12a, g12b, sm1, etc. Signed-off-by: Arseniy Krasnov <avkrasnov@...> Signed-off-by: Vladimir Mitrofanov <vvmitrofanov@...> Signed-off-by: Evgeny Bachinin <EABachinin@...> --- arch/arm/include/asm/arch-meson/sm.h | 98 +++++++++++++++++++++++++++- arch/arm/mach-meson/sm.c | 39 +++++++++++ drivers/sm/meson-sm.c | 3 + include/meson/sm.h | 3 + 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/arch-meson/sm.h b/arch/arm/include/asm/arch-meson/sm.h index 4d614955fc2..087f8b4d5fa 100644 --- a/arch/arm/include/asm/arch-meson/sm.h +++ b/arch/arm/include/asm/arch-meson/sm.h @@ -83,7 +83,7 @@ int meson_sm_get_serial(void *buffer, size_t size); */ int meson_sm_get_chip_id(struct meson_sm_chip_id *chip_id); -enum { +enum meson_reboot_mode { REBOOT_REASON_COLD = 0, REBOOT_REASON_NORMAL = 1, REBOOT_REASON_RECOVERY = 2, @@ -134,4 +134,100 @@ int meson_sm_pwrdm_set(size_t index, int cmd); #define meson_sm_pwrdm_on(index) \ meson_sm_pwrdm_set(index, PWRDM_ON) +/* + * Below is the list of SCPI_CMD commands, issued by U-Boot and passed to SCP + * co-processor via SMC to BL31 (TF-A). BL31 routes these commands to SCP + * via mailbox. + * + * Commands instruct the SCP how to set/control POC pins in order to choose + * first boot source, specified by the particular command below. These POC pins + * are readable by BootROM and used to determine the boot sequence. Usually, + * the normal default boot sequence, seen on production device is + * NAND/eMMC -> SD -> USB + * + * Commands below change the first boot source. + * + * NOTE: + * these commands are used along with meson_sm_set_bl1_first_boot_source() on + * Amlogic SoCs where ADNL burning protocol is utilized. + * Refer to meson_sm_set_usb_boot_mode() for the same functionality but on SoCs + * with Optimus burning protocol. + */ + +/** + * define SCPI_CMD_USB_BOOT - sets the first boot source into USB with timeout + * + * Additionally, force the BootROM (BL1) to wait for the Host's enumeration + * with timeout + */ +#define SCPI_CMD_USB_BOOT 0xB0 + +/** + * define SCPI_CMD_USB_UNBOOT - sets the first boot source into USB w/o timeout + * + * Additionally, force the BootROM to wait for the Host's enumeration with + * uninterruptible wait, i.e. forever + */ +#define SCPI_CMD_USB_UNBOOT 0xB1 + +/** + * define SCPI_CMD_SDCARD_BOOT - sets the first boot source into SD card + */ +#define SCPI_CMD_SDCARD_BOOT 0xB2 + +/** + * define SCPI_CMD_CLEAR_BOOT - sets the first boot source into default one + * + * BootROM follows a pre-defined boot sequence stored in SoC ROM code. + */ +#define SCPI_CMD_CLEAR_BOOT 0xB3 + +/** + * meson_sm_set_bl1_first_boot_source - sets the first boot source for BootROM. + * @cmd: command to set first boot source visible to BootROM during boot. + * Use SCPI_CMD_* as commands. + * + * BootROM checks POC-pins (POC0, POC1, POC2) to determine in which order it + * must probe the various methods of booting the system. The order is usually + * pre-defined. But function changes the first boot source of that pre-defined + * order. + * + * @return: zero on success or error code on failure. + */ +int meson_sm_set_bl1_first_boot_source(u64 cmd); + +/** + * meson_sm
Started by Arseniy Krasnov @
[PATCH v1 11/11] arch: arm: axg: Optimus protocol support
From: Vladimir Mitrofanov <vvmitrofanov@...> During Optimus protocol operations, BootROM may request to enter Optimus mode after boot. So to support this, let's check for values in sticky registers after boot (such registers could be updated earlier by boot ROM, telling U-boot to enter Optimus mode). Signed-off-by: Vladimir Mitrofanov <vvmitrofanov@...> Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/include/asm/arch-meson/axg.h | 12 ++++++++++++ arch/arm/mach-meson/board-axg.c | 12 ++++++++++++ arch/arm/mach-meson/board-common.c | 15 +++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/arch/arm/include/asm/arch-meson/axg.h b/arch/arm/include/asm/arch-meson/axg.h index 12042de9359..e99cd3aa780 100644 --- a/arch/arm/include/asm/arch-meson/axg.h +++ b/arch/arm/include/asm/arch-meson/axg.h @@ -23,6 +23,7 @@ #define AXG_AO_SEC_GP_CFG3 AXG_AO_ADDR(0x93) #define AXG_AO_SEC_GP_CFG4 AXG_AO_ADDR(0x94) #define AXG_AO_SEC_GP_CFG5 AXG_AO_ADDR(0x95) +#define AXG_AO_SEC_GP_CFG7 AXG_AO_ADDR(0x97) #define AXG_AO_BOOT_DEVICE 0xF #define AXG_AO_MEM_SIZE_MASK 0xFFFF0000 @@ -31,4 +32,15 @@ #define AXG_AO_BL31_RSVMEM_SIZE_SHIFT 16 #define AXG_AO_BL32_RSVMEM_SIZE_MASK 0xFFFF +#if CONFIG_IS_ENABLED(CMD_OPTIMUS) +/** + * is_tpl_loaded_from_usb - Checks, that this instance of U-boot was + * loaded from USB during firmware update + * process. + * + * returns: true, if so. + */ +int is_tpl_loaded_from_usb(void); +#endif + #endif /* __AXG_H__ */ diff --git a/arch/arm/mach-meson/board-axg.c b/arch/arm/mach-meson/board-axg.c index 6535539184c..13eb66dfc21 100644 --- a/arch/arm/mach-meson/board-axg.c +++ b/arch/arm/mach-meson/board-axg.c @@ -4,12 +4,14 @@ * (C) Copyright 2018 Neil Armstrong <narmstrong@...> */ +#include <command.h> #include <init.h> #include <net.h> #include <asm/arch/boot.h> #include <asm/arch/eth.h> #include <asm/arch/axg.h> #include <asm/arch/mem.h> +#include <asm/arch-meson/sm.h> #include <asm/global_data.h> #include <asm/io.h> #include <asm/armv8/mmu.h> @@ -62,6 +64,16 @@ phys_size_t get_effective_memsize(void) >> AXG_AO_MEM_SIZE_SHIFT) * SZ_1M; } +#if CONFIG_IS_ENABLED(CMD_OPTIMUS) +int is_tpl_loaded_from_usb(void) +{ + const int boot_id = meson_get_boot_device(); + const unsigned int force_usb_boot = readl(AXG_AO_SEC_GP_CFG7); + + return (boot_id == BOOT_DEVICE_USB || (force_usb_boot & BIT(31))); +} +#endif + static struct mm_region axg_mem_map[] = { { .virt = 0x0UL, diff --git a/arch/arm/mach-meson/board-common.c b/arch/arm/mach-meson/board-common.c index 0624d557e40..639c7a64507 100644 --- a/arch/arm/mach-meson/board-common.c +++ b/arch/arm/mach-meson/board-common.c @@ -16,6 +16,7 @@ #include <linux/libfdt.h> #include <linux/err.h> #include <asm/arch/a1.h> +#include <asm/arch/axg.h> #include <asm/arch/mem.h> #include <asm/arch/sm.h> #include <asm/armv8/mmu.h> @@ -144,6 +145,18 @@ __weak int meson_board_late_init(void) return 0; } +static void meson_board_try_enter_optimus(void) +{ +#if (IS_ENABLED(CONFIG_CMD_OPTIMUS)) + if (!is_tpl_loaded_from_usb()) + return; + + meson_sm_set_usb_boot_mode(CLEAR_USB_BOOT); + + run_command("optimus", 0); +#endif +} + static void meson_board_try_enter_adnl(void) { #if (IS_ENABLED(CONFIG_CMD_ADNL)) @@ -162,6 +175,8 @@ int board_late_init(void) meson_board_try_enter_adnl(); + meson_board_try_enter_optimus(); + return meson_board_late_init(); } -- 2.30.1
Started by Arseniy Krasnov @
[PATCH v1 10/11] usb: gadget: amlogic: implement Optimus protocol
From: Vladimir Mitrofanov <vvmitrofanov@...> Add Amlogic's Optimus protocol support for USB transport. Signed-off-by: Vladimir Mitrofanov <vvmitrofanov@...> Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- cmd/Kconfig | 7 + cmd/meson/Makefile | 1 + cmd/meson/optimus.c | 21 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/amlogic/Kconfig | 1 + drivers/usb/gadget/amlogic/optimus/Kconfig | 12 + drivers/usb/gadget/amlogic/optimus/Makefile | 7 + .../usb/gadget/amlogic/optimus/f_optimus.c | 687 ++++++++++++++++++ .../gadget/amlogic/optimus/optimus_download.c | 188 +++++ .../gadget/amlogic/optimus/optimus_download.h | 86 +++ 10 files changed, 1011 insertions(+) create mode 100644 cmd/meson/optimus.c create mode 100644 drivers/usb/gadget/amlogic/optimus/Kconfig create mode 100644 drivers/usb/gadget/amlogic/optimus/Makefile create mode 100644 drivers/usb/gadget/amlogic/optimus/f_optimus.c create mode 100644 drivers/usb/gadget/amlogic/optimus/optimus_download.c create mode 100644 drivers/usb/gadget/amlogic/optimus/optimus_download.h diff --git a/cmd/Kconfig b/cmd/Kconfig index 2f195d03848..159e52d5298 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1153,6 +1153,13 @@ config CMD_ADNL This command, "adnl", enables the ADNL listen mode, providing the ability to listen in ADNL mode. +config CMD_OPTIMUS + bool "OPTIMUS - Amlogic download protocol" + depends on OPTIMUS + help + This command, "optimus", enables the OPTIMUS listen mode, providing + the ability to communicate with host by OPTIMUS protocol. + config CMD_FLASH bool "flinfo, erase, protect" default y diff --git a/cmd/meson/Makefile b/cmd/meson/Makefile index 1cf984378a3..611d1549736 100644 --- a/cmd/meson/Makefile +++ b/cmd/meson/Makefile @@ -4,3 +4,4 @@ obj-y += sm.o obj-$(CONFIG_CMD_ADNL) += gadget.o adnl.o +obj-$(CONFIG_CMD_OPTIMUS) += gadget.o optimus.o diff --git a/cmd/meson/optimus.c b/cmd/meson/optimus.c new file mode 100644 index 00000000000..97a1435c0ab --- /dev/null +++ b/cmd/meson/optimus.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 SaluteDevices, Inc. + * Author: Vladimir Mitrofanov <vvmitrofanov@...> + */ + +#include <command.h> + +#include "gadget.h" + +static int do_optimus(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + return amlogic_gadget_run("usb_dnl_optimus", argc, argv); +} + +U_BOOT_LONGHELP(optimus, + "- run as an OPTIMUS USB device\n\n"); + +U_BOOT_CMD(optimus, 1, 1, do_optimus, + "OPTIMUS protocol mode", optimus_help_text); diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 2b6705c52be..f5899a96221 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_USB_GADGET_DWC2_OTG) += dwc2_udc_otg.o obj-$(CONFIG_USB_GADGET_DWC2_OTG_PHY) += dwc2_udc_otg_phy.o obj-$(CONFIG_USB_GADGET_MAX3420) += max3420_udc.o obj-$(CONFIG_USB_RENESAS_USBHS) += rcar/ +obj-$(CONFIG_OPTIMUS) += f_fastboot_common.o amlogic/optimus/ ifndef CONFIG_XPL_BUILD obj-$(CONFIG_USB_GADGET_DOWNLOAD) += g_dnl.o obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o diff --git a/drivers/usb/gadget/amlogic/Kconfig b/drivers/usb/gadget/amlogic/Kconfig index 460dc6fe235..5a16fb25998 100644 --- a/drivers/usb/gadget/amlogic/Kconfig +++ b/drivers/usb/gadget/amlogic/Kconfig @@ -7,5 +7,6 @@ choice optional source "drivers/usb/gadget/amlogic/adnl/Kconfig" +source "drivers/usb/gadget/amlogic/optimus/Kconfig" endchoice diff --git a/drivers/usb/gadget/amlogic/optimus/Kconfig b/drivers/usb/gadget/amlogic/optimus/Kconfig new file mode 100644 index 00000000000..6a730670d34 --- /dev/null +++ b/drivers/usb/gadget/amlogic/optimus/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2024 SaluteDevices, Inc. + +config OPTIMUS + bool "Enable OPTIMUS protocol" + depends on USB_GADGET + depends on MESON_AXG + help + This enables usb optimus function protocol + "Optimus" protocol is used to flash Amlogic devices + from bootRom or from U-Boot mode diff --git a/drivers/usb/gadget/amlogic/optimus/Makefile b/drivers/usb/gadget/amlogic/optimus/Makefile new file m
Started by Arseniy Krasnov @
[PATCH v1 08/11] usb: gadget: amlogic: implement ADNL protocol
This adds support for ADNL (Amlogic DowNLoad) protocol. This protocol is supported by some Amlogic SoCs (a1, s4, c1, с2, sc2, t7, etc) in BootRom code (e.g. it is already supported in "out of the box" mode). It has similar goals as fastboot - upload and update firmware images on the device. Difference is that, it is specific for Amlogic SoCs, and for example it allows to upload and run image starting from ROM boot stage, it also uses SoC specific registers and SMC commands. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- cmd/Kconfig | 7 + cmd/meson/Makefile | 1 + cmd/meson/adnl.c | 27 + drivers/usb/gadget/Kconfig | 2 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/amlogic/Kconfig | 11 + drivers/usb/gadget/amlogic/adnl/Kconfig | 29 + drivers/usb/gadget/amlogic/adnl/Makefile | 4 + drivers/usb/gadget/amlogic/adnl/adnl.h | 124 +++ .../gadget/amlogic/adnl/adnl_buff_manager.c | 316 +++++++ drivers/usb/gadget/amlogic/adnl/adnl_media.c | 235 +++++ .../usb/gadget/amlogic/adnl/adnl_storage.c | 140 +++ drivers/usb/gadget/amlogic/adnl/f_adnl.c | 835 ++++++++++++++++++ 13 files changed, 1732 insertions(+) create mode 100644 cmd/meson/adnl.c create mode 100644 drivers/usb/gadget/amlogic/Kconfig create mode 100644 drivers/usb/gadget/amlogic/adnl/Kconfig create mode 100644 drivers/usb/gadget/amlogic/adnl/Makefile create mode 100644 drivers/usb/gadget/amlogic/adnl/adnl.h create mode 100644 drivers/usb/gadget/amlogic/adnl/adnl_buff_manager.c create mode 100644 drivers/usb/gadget/amlogic/adnl/adnl_media.c create mode 100644 drivers/usb/gadget/amlogic/adnl/adnl_storage.c create mode 100644 drivers/usb/gadget/amlogic/adnl/f_adnl.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 9e8a9c3cb3a..2f195d03848 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1146,6 +1146,13 @@ config CMD_FASTBOOT See doc/android/fastboot.rst for more information. +config CMD_ADNL + bool "ADNL - Amlogic download protocol" + depends on ADNL + help + This command, "adnl", enables the ADNL listen mode, providing + the ability to listen in ADNL mode. + config CMD_FLASH bool "flinfo, erase, protect" default y diff --git a/cmd/meson/Makefile b/cmd/meson/Makefile index ee26c175cfe..1cf984378a3 100644 --- a/cmd/meson/Makefile +++ b/cmd/meson/Makefile @@ -3,3 +3,4 @@ # Copyright (c) 2022, SberDevices. All rights reserved. obj-y += sm.o +obj-$(CONFIG_CMD_ADNL) += gadget.o adnl.o diff --git a/cmd/meson/adnl.c b/cmd/meson/adnl.c new file mode 100644 index 00000000000..13aa1f2113e --- /dev/null +++ b/cmd/meson/adnl.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 SaluteDevices, Inc. + * Author: Arseniy Krasnov <avkrasnov@...> + */ + +#include <command.h> + +#include "gadget.h" + +static int do_adnl(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + return amlogic_gadget_run("usb_dnl_adnl", argc, argv); +} + +U_BOOT_LONGHELP(adnl, + "- run as an ADNL USB device\n\n" + "With:\n" + "\t[init timeout]: time between command start and moment when\n" + "\t device enters gadget mode, in ms\n" + "\t[identify timeout]: time between moment when device enters gadget\n" + "\t mode and first 'identify' command from PC, in ms\n"); + +U_BOOT_CMD(adnl, 3, 1, do_adnl, + "ADNL protocol mode", + adnl_help_text); diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index c815764c2bc..6391ceb9cfa 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -289,6 +289,8 @@ config USBNET_HOST_ADDR endif # USB_ETHER +source "drivers/usb/gadget/amlogic/Kconfig" + endif # USB_GADGET if SPL_USB_GADGET diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 6c16ad83f6e..2b6705c52be 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o obj-$(CONFIG_DFU_OVER_USB) += f_dfu.o obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o f_fastboot_common.o +obj-$(CONFIG_ADNL) += f_fastboot_common.o amlogic/adnl/ obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o obj-$(CONFIG_USB_FU
Started by Arseniy Krasnov @
[PATCH v1 05/11] mtd: rawnand: meson: move some defines to dedicated header
We need these values and macro to correctly write "bootloader" partition in Optimus protocol, so let's export them to arch-meson header and also provide more detailed information about each macro. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/include/asm/arch-meson/rawnand.h | 38 +++++++++++++++++++++++ drivers/mtd/nand/raw/meson_nand.c | 13 +------- 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 arch/arm/include/asm/arch-meson/rawnand.h diff --git a/arch/arm/include/asm/arch-meson/rawnand.h b/arch/arm/include/asm/arch-meson/rawnand.h new file mode 100644 index 00000000000..81bf6ef7e37 --- /dev/null +++ b/arch/arm/include/asm/arch-meson/rawnand.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2025 SaluteDevices, Inc. + */ + +#ifndef __MESON_RAWNAND_H__ +#define __MESON_RAWNAND_H__ + +#include <asm/arch/nand.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/rawnand.h> + +/* M2N means 'memory to NAND', e.g. write. */ +#define NFC_CMD_M2N ((0 << 17) | BIT(21)) +/* N2M means 'NAND to memory', e.g. read. */ +#define NFC_CMD_N2M ((1 << 17) | BIT(21)) + +/* + * Macro to create value for read/write command. + * + * 'cmd_dir' - direction, e.g. read or write. + * 'ran' - scrambler mode (enabled or not). + * 'bch' - ECC mode (strength and size). + * 'short_mode' - short mode (enabled or not). + * 'page_size' - size of page. + * 'pages' - number of pages to access. + */ +#define CMDRWGEN(cmd_dir, ran, bch, short_mode, page_size, pages) \ + ( \ + (cmd_dir) | \ + ((ran)) | \ + ((bch) << 14) | \ + ((short_mode) << 13) | \ + (((page_size) & 0x7F) << 6) | \ + ((pages) & 0x3F) \ + ) + +#endif diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 28c851f103b..81122315f45 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -11,6 +11,7 @@ #include <nand.h> #include <asm/io.h> +#include <asm/arch/rawnand.h> #include <dm.h> #include <dm/device_compat.h> #include <dm/ofnode.h> @@ -34,8 +35,6 @@ #define NFC_CMD_AIL ((2 << 16) | (3 << 20)) #define NFC_CMD_AIH ((3 << 16) | (3 << 20)) #define NFC_CMD_SEED ((8 << 16) | (3 << 20)) -#define NFC_CMD_M2N ((0 << 17) | (2 << 20)) -#define NFC_CMD_N2M ((1 << 17) | (2 << 20)) #define NFC_CMD_RB BIT(20) #define NFC_CMD_SCRAMBLER_ENABLE BIT(19) #define NFC_CMD_SCRAMBLER_DISABLE 0 @@ -61,16 +60,6 @@ #define NFC_REG_PINS 0x30 #define NFC_REG_VER 0x38 -#define CMDRWGEN(cmd_dir, ran, bch, short_mode, page_size, pages) \ - ( \ - (cmd_dir) | \ - (ran) | \ - ((bch) << 14) | \ - ((short_mode) << 13) | \ - (((page_size) & 0x7f) << 6) | \ - ((pages) & 0x3f) \ - ) - #define GENCMDDADDRL(adl, addr) ((adl) | ((addr) & 0xffff)) #define GENCMDDADDRH(adh, addr) ((adh) | (((addr) >> 16) & 0xffff)) #define GENCMDIADDRL(ail, addr) ((ail) | ((addr) & 0xffff)) -- 2.30.1
Started by Arseniy Krasnov @
[PATCH v1 04/11] usb: gadget: amlogic: common code for Amlogic flashing commands
Amlogic has Optimus and ADNL protocols to update firmware image. Both are operatable by special commands and such commands use same approaches, so let's implement such code before implementing both protocols. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- cmd/meson/gadget.c | 183 +++++++++++++++++++++++++++++++++++++++++++++ cmd/meson/gadget.h | 28 +++++++ 2 files changed, 211 insertions(+) create mode 100644 cmd/meson/gadget.c create mode 100644 cmd/meson/gadget.h diff --git a/cmd/meson/gadget.c b/cmd/meson/gadget.c new file mode 100644 index 00000000000..6155043ae5a --- /dev/null +++ b/cmd/meson/gadget.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2025 SaluteDevices, Inc. + * Author: Arseniy Krasnov <avkrasnov@...> + */ + +#include <hexdump.h> +#include <command.h> +#include <g_dnl.h> +#include <mtd.h> +#include <time.h> +#include <asm/arch/sm.h> +#include <asm/types.h> +#include <linux/delay.h> + +#define BURN_BOOT_UDELAY (2 * 1000 * 1000) +static unsigned long burn_identify_time_ms; +static unsigned long burn_start_time_ms; + +void amlogic_gadget_set_times(unsigned long start_time, unsigned long identify_time) +{ + burn_start_time_ms = start_time; + burn_identify_time_ms = identify_time; +} + +/* + * This function utilizes serial from inside Amlogic chip_id with one + * distinctive feature that this serial must be in big-endian. + * + * This is needed, because serial string, utilized in BootROM, must match + * the serial string, used inside U-Boot. But BootROM utilizes serial string + * in big-endian: being in BootROM try + * - for new SoCs (a1, s4, etc - those which utilize ADNL protocol): run + * host command 'fastboot devices' + * - for old SoCs (axg, g12a, g12b, etc - those, utilizing optimus protocol): + * send "chipid" command to bootROM + */ +static int amlogic_serial_hex(char serial_str[SM_SERIAL_SIZE * 2 + 1]) +{ + u8 serial[SM_SERIAL_SIZE]; + int ret; + + /* + * ADNL/OPTIMUS uses serial value in big-endian order. + * meson_sm_get_serial() returns exactly such value. + */ + ret = meson_sm_get_serial(serial, sizeof(serial)); + if (ret) + return ret; + + bin2hex(serial_str, serial, sizeof(serial)); + return ret; +} + +int amlogic_gadget_run(const char *mode, int argc, char *const argv[]) +{ + char serial_string[SM_SERIAL_SIZE * 2 + 1] = { 0 }; + unsigned long identify_timeout_ms; + unsigned long start_timeout_ms; + struct udevice *udc; + char *saved_serial; + int ret; + + if (mtd_probe_devices()) { + pr_err("Mtd devices probe failed\n"); + return CMD_RET_FAILURE; + } + + /* + * During ADNL/OPTIMUS burning process, device enters USB gadget mode + * twice: first time when it was stopped in ROM boot, second - + * here, after ROM and BL2 stages are done and we are ready + * to run BL33 (U-boot) stage. From the PC side, client waits + * reentering to USB gadget mode (in BL33 stage). Without delay + * below, PC client waits for USB device forever with the + * following message. + * + * OPTIMUS do not use timeout described below + * MSG[TLS]Waiting for DNL[<serial>] with timeout 0 + * + * At the same time, there is no difference (from the PC point + * of view) between USB device state with or w/o this delay, so + * seems this delay is needed only to make PC client work + * correctly due to is internal logic. + */ + udelay(BURN_BOOT_UDELAY); + + ret = amlogic_serial_hex(serial_string); + if (ret) + return CMD_RET_FAILURE; + + saved_serial = env_get("serial#"); + if (saved_serial) { + saved_serial = strdup(saved_serial); + if (!saved_serial) + return CMD_RET_FAILURE; + } + + /* + * Use "force" flag, because 'serial#' is protected + * from both delete and rewrite. This variable is used + * by USB gadget code as serial number of USB device. + */ + ret = run_commandf("env set -f serial# %s", serial_string); + if (ret) { + ret = CMD_RET_FAILURE; + goto exit_ret; + } + + amlogic_gadget_set_times(get_timer(0), 0); + + ret = udc_device_get_by_index(0, &udc); + if (ret) { + pr_err("Failed to get UDC device: %d\n", ret); + ret = CMD_RET_FAILURE; + goto exit_ret; + } + + g_dnl_clear_detach()
Started by Arseniy Krasnov @
[PATCH v1 09/11] arm: meson: a1: ADNL protocol support
During ADNL protocol operations, BootROM may request to enter ADNL mode after boot. So to support this, let's check for values in sticky registers after boot (such registers could be updated earlier by boot ROM, telling U-boot to enter ADNL mode. Signed-off-by: Arseniy Krasnov <avkrasnov@...> --- arch/arm/include/asm/arch-meson/a1.h | 13 +++++++++++ arch/arm/mach-meson/board-a1.c | 32 +++++++++++++++++++++++++++- arch/arm/mach-meson/board-common.c | 17 +++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/arch-meson/a1.h b/arch/arm/include/asm/arch-meson/a1.h index 16e209ed932..4a22aaf5627 100644 --- a/arch/arm/include/asm/arch-meson/a1.h +++ b/arch/arm/include/asm/arch-meson/a1.h @@ -12,6 +12,7 @@ /* SYSCTRL registers */ #define A1_SYSCTRL_ADDR(off) (A1_SYSCTRL_BASE + ((off) << 2)) +#define A1_SYSCTRL_SEC_STATUS_REG1 A1_SYSCTRL_ADDR(0xc1) #define A1_SYSCTRL_SEC_STATUS_REG4 A1_SYSCTRL_ADDR(0xc4) /* * Checked during boot. Tells, that previous code, e.g. @@ -20,7 +21,19 @@ */ #define A1_SYSCTRL_SEC_STICKY_REG2 A1_SYSCTRL_ADDR(0xe2) +#define A1_AO_BOOT_DEVICE 0xF #define A1_SYSCTRL_MEM_SIZE_MASK 0xFFFF0000 #define A1_SYSCTRL_MEM_SIZE_SHIFT 16 +#if CONFIG_IS_ENABLED(ADNL) +/** + * is_tpl_loaded_from_usb - Checks, that this instance of U-boot was + * loaded from USB during firmware update + * process. + * + * returns: true, if so. + */ +int is_tpl_loaded_from_usb(void); +#endif + #endif /* __MESON_A1_H__ */ diff --git a/arch/arm/mach-meson/board-a1.c b/arch/arm/mach-meson/board-a1.c index f848c0f068e..9cc410f1e57 100644 --- a/arch/arm/mach-meson/board-a1.c +++ b/arch/arm/mach-meson/board-a1.c @@ -3,6 +3,7 @@ * (C) Copyright 2023 SberDevices, Inc. */ +#include <command.h> #include <asm/arch/a1.h> #include <asm/arch/boot.h> #include <asm/armv8/mmu.h> @@ -23,9 +24,38 @@ void meson_init_reserved_memory(__maybe_unused void *fdt) int meson_get_boot_device(void) { - return -ENOSYS; + return readl(A1_SYSCTRL_SEC_STATUS_REG4) & A1_AO_BOOT_DEVICE; } +#if CONFIG_IS_ENABLED(ADNL) + +static bool is_boot_device_usb(void) +{ + return meson_get_boot_device() == BOOT_DEVICE_USB; +} + +#define MESON_ADNL_BL1_USB_PROTO_DNL_BIT BIT(12) + +static bool is_bl1_usb_protocol_DNL(void) +{ + u32 val = readl(A1_SYSCTRL_SEC_STATUS_REG1); + + return !(val & MESON_ADNL_BL1_USB_PROTO_DNL_BIT); +} + +int is_tpl_loaded_from_usb(void) +{ + if (!is_boot_device_usb()) + return false; + + if (!is_bl1_usb_protocol_DNL()) + return false; + + return true; +} + +#endif + static struct mm_region a1_mem_map[] = { { .virt = 0x00000000UL, diff --git a/arch/arm/mach-meson/board-common.c b/arch/arm/mach-meson/board-common.c index 39774c43049..0624d557e40 100644 --- a/arch/arm/mach-meson/board-common.c +++ b/arch/arm/mach-meson/board-common.c @@ -3,6 +3,7 @@ * (C) Copyright 2016 Beniamino Galvani <b.galvani@...> */ +#include <command.h> #include <cpu_func.h> #include <fastboot.h> #include <init.h> @@ -14,9 +15,11 @@ #include <asm/ptrace.h> #include <linux/libfdt.h> #include <linux/err.h> +#include <asm/arch/a1.h> #include <asm/arch/mem.h> #include <asm/arch/sm.h> #include <asm/armv8/mmu.h> +#include <asm/io.h> #include <asm/unaligned.h> #include <efi_loader.h> #include <u-boot/crc.h> @@ -141,10 +144,24 @@ __weak int meson_board_late_init(void) return 0; } +static void meson_board_try_enter_adnl(void) +{ +#if (IS_ENABLED(CONFIG_CMD_ADNL)) + if (!is_tpl_loaded_from_usb()) + return; + + meson_sm_set_bl1_first_boot_source(SCPI_CMD_CLEAR_BOOT); + + run_command("adnl", 0); +#endif +} + int board_late_init(void) { meson_set_boot_source(); + meson_board_try_enter_adnl(); + return meson_board_late_init(); } -- 2.30.1
Started by Arseniy Krasnov @
Current Image
Image Name
Sat 8:39am