UFS固件升级来袭,QCOM/UEFI平台都懂的,发现西数提供一个工具叫ufs-utils,里面提到了FFU:

The following options may work with the SCSI BSG device
using sg v4 structure (e.g. /dev/0:0:0:0)
or via a SCSI Generic interface using sg v3 struct (e.g. /dev/block/sda)
d) Error History
e) FFU - Field Firmware Update

What is sg v4? sg v3? ok,让我们先了解下sg。

SCSI设备驱动主要有四类:sd(disk), st(tape), sr(CDROM), sg(generic)。

menuconfig:

   *** SCSI support type (dis, tape, SD-ROM) ***
<> SCSI disk support
<> SCSI tape support
<> SCSI CDROM support
<> SCSI generic support

sg: 顾名思义就是更通用的了,大概看下sg v3和v4,以下参考kernel 5.x。

v4的Kconfig定义:

config BLK_DEV_BSG
        bool "Block layer SG support v4"
        default y
        select BLK_SCSI_REQUEST
        help
          Saying Y here will enable generic SG (SCSI generic) v4 support
          for any block device.

          Unlike SG v3 (aka block/scsi_ioctl.c drivers/scsi/sg.c), SG v4
          can handle complicated SCSI commands: tagged variable length cdbs
          with bidirectional data transfers and generic request/response
          protocols (e.g. Task Management Functions and SMP in Serial
          Attached SCSI).

          This option is required by recent UDEV versions to properly
          access device serial numbers, etc.

          If unsure, say Y.
block/Makefile:15:obj-$(CONFIG_BLK_DEV_BSG)   += bsg.o

ok, sg v3的code:block/scsi_ioctl.c + drivers/scsi/sg.c (CONFIG_CHR_DEV_SG)

sg v4的code:block/bsg.c (CONFIG_BLK_DEV_BSG)

v3的interface: include/scsi/sg.h:

typedef struct sg_io_hdr
{
    int interface_id;           /* [i] 'S' for SCSI generic (required) */

v4的interface: include/uapi/linux/bsg.h:

struct sg_io_v4 {
        __s32 guard;            /* [i] 'Q' to differentiate from v3 */

block layer来源于driver/scsi,bsg是block layer sg, bsg只支持sg v4。

当前qcom平台只能看到/dev/block/sda,用sg v3就能FFU for UFS? to be continue.

refer