drivers: partition: support different block size
authorHaojian Zhuang <haojian.zhuang@linaro.org>
Sat, 14 Sep 2019 10:01:16 +0000 (18:01 +0800)
committerHaojian Zhuang <haojian.zhuang@linaro.org>
Wed, 18 Sep 2019 10:18:20 +0000 (18:18 +0800)
The block size of some storage device is 4096-byte long, such as UFS. But
PARTITION_BLOCK_SIZE is defined as 512-byte long. So replace it by
PLAT_PARTITION_BLOCK_SIZE. Make it configurable in platform.

Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
Change-Id: Iada05f7c646d0a0f2c0d3b8545540b3cb7153de3

docs/getting_started/porting-guide.rst
drivers/partition/gpt.c
drivers/partition/partition.c
include/drivers/partition/gpt.h
include/drivers/partition/partition.h

index 5786dd38495f69323dd3ff6ee4a9ee5c9a8c4ce3..97ed1fa43a107667702765a2070010c2ffd77fd3 100644 (file)
@@ -546,6 +546,13 @@ optionally be defined:
    PLAT_PARTITION_MAX_ENTRIES := 12
    $(eval $(call add_define,PLAT_PARTITION_MAX_ENTRIES))
 
+-  **PLAT_PARTITION_BLOCK_SIZE**
+   The size of partition block. It could be either 512 bytes or 4096 bytes.
+   The default value is 512.
+   `For example, define the build flag in platform.mk`_:
+   PLAT_PARTITION_BLOCK_SIZE := 4096
+   $(eval $(call add_define,PLAT_PARTITION_BLOCK_SIZE))
+
 The following constant is optional. It should be defined to override the default
 behaviour of the ``assert()`` function (for example, to save memory).
 
index 4577f06a20bf468e359e9eba31fe4bde9b9eb32c..1b804deef6d8e2b43d7dff874f4620a4d08e5717 100644 (file)
@@ -52,9 +52,10 @@ int parse_gpt_entry(gpt_entry_t *gpt_entry, partition_entry_t *entry)
        if (result != 0) {
                return result;
        }
-       entry->start = (uint64_t)gpt_entry->first_lba * PARTITION_BLOCK_SIZE;
+       entry->start = (uint64_t)gpt_entry->first_lba *
+                      PLAT_PARTITION_BLOCK_SIZE;
        entry->length = (uint64_t)(gpt_entry->last_lba -
                                   gpt_entry->first_lba + 1) *
-                       PARTITION_BLOCK_SIZE;
+                       PLAT_PARTITION_BLOCK_SIZE;
        return 0;
 }
index 7fdbf5385aa7fe10ea62422133094d6abdf26ffc..68133eaf4f1b7951c33e11b4c23ebfdc79598ec0 100644 (file)
@@ -15,7 +15,7 @@
 #include <drivers/partition/mbr.h>
 #include <plat/common/platform.h>
 
-static uint8_t mbr_sector[PARTITION_BLOCK_SIZE];
+static uint8_t mbr_sector[PLAT_PARTITION_BLOCK_SIZE];
 static partition_entry_list_t list;
 
 #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
@@ -57,15 +57,15 @@ static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry)
                return result;
        }
        result = io_read(image_handle, (uintptr_t)&mbr_sector,
-                        PARTITION_BLOCK_SIZE, &bytes_read);
+                        PLAT_PARTITION_BLOCK_SIZE, &bytes_read);
        if (result != 0) {
                WARN("Failed to read data (%i)\n", result);
                return result;
        }
 
        /* Check MBR boot signature. */
-       if ((mbr_sector[PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
-           (mbr_sector[PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
+       if ((mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
+           (mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
                return -ENOENT;
        }
        offset = (uintptr_t)&mbr_sector + MBR_PRIMARY_ENTRY_OFFSET;
@@ -120,15 +120,15 @@ static int load_mbr_entry(uintptr_t image_handle, mbr_entry_t *mbr_entry,
                return result;
        }
        result = io_read(image_handle, (uintptr_t)&mbr_sector,
-                        PARTITION_BLOCK_SIZE, &bytes_read);
+                        PLAT_PARTITION_BLOCK_SIZE, &bytes_read);
        if (result != 0) {
                WARN("Failed to read data (%i)\n", result);
                return result;
        }
 
        /* Check MBR boot signature. */
-       if ((mbr_sector[PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
-           (mbr_sector[PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
+       if ((mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 2] != MBR_SIGNATURE_FIRST) ||
+           (mbr_sector[LEGACY_PARTITION_BLOCK_SIZE - 1] != MBR_SIGNATURE_SECOND)) {
                return -ENOENT;
        }
        offset = (uintptr_t)&mbr_sector +
index 3ae160fdc1e1bd28465c0f072c13748bd67d6b0f..d923e9535f3771de647256368fc3c86d3db3e3b2 100644 (file)
@@ -10,9 +10,9 @@
 #include <drivers/partition/partition.h>
 
 #define PARTITION_TYPE_GPT             0xee
-#define GPT_HEADER_OFFSET              PARTITION_BLOCK_SIZE
+#define GPT_HEADER_OFFSET              PLAT_PARTITION_BLOCK_SIZE
 #define GPT_ENTRY_OFFSET               (GPT_HEADER_OFFSET +            \
-                                        PARTITION_BLOCK_SIZE)
+                                        PLAT_PARTITION_BLOCK_SIZE)
 #define GUID_LEN                       16
 
 #define GPT_SIGNATURE                  "EFI PART"
index d94c7824a63f6cba6c233e7195c736be982566fa..5f6483373f3da2ab55b7ed5cc00e6e01952a4172 100644 (file)
 
 CASSERT(PLAT_PARTITION_MAX_ENTRIES <= 128, assert_plat_partition_max_entries);
 
-#define PARTITION_BLOCK_SIZE           512
+#if !PLAT_PARTITION_BLOCK_SIZE
+# define PLAT_PARTITION_BLOCK_SIZE     512
+#endif /* PLAT_PARTITION_BLOCK_SIZE */
+
+CASSERT((PLAT_PARTITION_BLOCK_SIZE == 512) ||
+       (PLAT_PARTITION_BLOCK_SIZE == 4096),
+       assert_plat_partition_block_size);
+
+#define LEGACY_PARTITION_BLOCK_SIZE    512
 
 #define EFI_NAMELEN                    36