Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / lib / efi_loader / efi_disk.c
index fc0682b..fd3df80 100644 (file)
@@ -13,6 +13,8 @@
 #include <part.h>
 #include <malloc.h>
 
+struct efi_system_partition efi_system_partition;
+
 const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
 
 /**
@@ -108,6 +110,21 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this,
        return EFI_SUCCESS;
 }
 
+/**
+ * efi_disk_read_blocks() - reads blocks from device
+ *
+ * This function implements the ReadBlocks service of the EFI_BLOCK_IO_PROTOCOL.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @this:                      pointer to the BLOCK_IO_PROTOCOL
+ * @media_id:                  id of the medium to be read from
+ * @lba:                       starting logical block for reading
+ * @buffer_size:               size of the read buffer
+ * @buffer:                    pointer to the destination buffer
+ * Return:                     status code
+ */
 static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this,
                        u32 media_id, u64 lba, efi_uintn_t buffer_size,
                        void *buffer)
@@ -157,6 +174,22 @@ static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this,
        return EFI_EXIT(r);
 }
 
+/**
+ * efi_disk_write_blocks() - writes blocks to device
+ *
+ * This function implements the WriteBlocks service of the
+ * EFI_BLOCK_IO_PROTOCOL.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @this:                      pointer to the BLOCK_IO_PROTOCOL
+ * @media_id:                  id of the medium to be written to
+ * @lba:                       starting logical block for writing
+ * @buffer_size:               size of the write buffer
+ * @buffer:                    pointer to the source buffer
+ * Return:                     status code
+ */
 static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this,
                        u32 media_id, u64 lba, efi_uintn_t buffer_size,
                        void *buffer)
@@ -208,9 +241,22 @@ static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this,
        return EFI_EXIT(r);
 }
 
+/**
+ * efi_disk_flush_blocks() - flushes modified data to the device
+ *
+ * This function implements the FlushBlocks service of the
+ * EFI_BLOCK_IO_PROTOCOL.
+ *
+ * As we always write synchronously nothing is done here.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @this:                      pointer to the BLOCK_IO_PROTOCOL
+ * Return:                     status code
+ */
 static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this)
 {
-       /* We always write synchronously */
        EFI_ENTRY("%p", this);
        return EFI_EXIT(EFI_SUCCESS);
 }
@@ -286,7 +332,7 @@ static int efi_fs_exists(struct blk_desc *desc, int part)
        return 1;
 }
 
-/*
+/**
  * efi_disk_add_dev() - create a handle for a partition or disk
  *
  * @parent:            parent handle
@@ -295,6 +341,8 @@ static int efi_fs_exists(struct blk_desc *desc, int part)
  * @desc:              internal block device
  * @dev_index:         device index for block device
  * @offset:            offset into disk for simple partitions
+ * @part:              partition
+ * @disk:              pointer to receive the created handle
  * Return:             disk object
  */
 static efi_status_t efi_disk_add_dev(
@@ -372,6 +420,24 @@ static efi_status_t efi_disk_add_dev(
        diskobj->ops.media = &diskobj->media;
        if (disk)
                *disk = diskobj;
+
+       /* Store first EFI system partition */
+       if (part && !efi_system_partition.if_type) {
+               int r;
+               disk_partition_t info;
+
+               r = part_get_info(desc, part, &info);
+               if (r)
+                       return EFI_DEVICE_ERROR;
+               if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+                       efi_system_partition.if_type = desc->if_type;
+                       efi_system_partition.devnum = desc->devnum;
+                       efi_system_partition.part = part;
+                       EFI_PRINT("EFI system partition: %s %d:%d\n",
+                                 blk_get_if_type_name(desc->if_type),
+                                 desc->devnum, part);
+               }
+       }
        return EFI_SUCCESS;
 }
 
@@ -381,7 +447,7 @@ static efi_status_t efi_disk_add_dev(
  * Create handles and protocols for the partitions of a block device.
  *
  * @parent:            handle of the parent disk
- * @blk_desc:          block device
+ * @desc:              block device
  * @if_typename:       interface type
  * @diskid:            device number
  * @pdevname:          device name