Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 107ad28

Browse files
committed
support dedicated data partition
If USE_DEDICATED_DATA_PARTITION set to true, will use the largest storage except the boot storage as data partition. Signed-off-by: JianFeng,Zhou <jianfeng.zhou@intel.com>
1 parent 40e6878 commit 107ad28

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

libkernelflinger/Android.mk

100755100644
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ ifneq ($(KERNELFLINGER_FIXED_RPMB_KEY),)
9898
LOCAL_CFLAGS += -DFIXED_RPMB_KEY=$(KERNELFLINGER_FIXED_RPMB_KEY)
9999
endif
100100

101+
ifeq ($(KERNELFLINGER_USE_DEDICATED_DATA_PARTITION),true)
102+
LOCAL_CFLAGS += -DUSE_DEDICATED_DATA_PARTITION
103+
endif
104+
101105
LOCAL_SRC_FILES := \
102106
android.c \
103107
efilinux.c \

libkernelflinger/gpt.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "gpt.h"
4040
#include "gpt_bin.h"
4141
#include "storage.h"
42+
#include "pci.h"
4243

4344
#define PROTECTIVE_MBR 0xEE
4445

@@ -437,6 +438,75 @@ static void copy_part(struct gpt_partition *in, struct gpt_partition *out)
437438
sizeof(out->name) - PREFIX_LEN * sizeof(CHAR16));
438439
}
439440

441+
#ifdef USE_DEDICATED_DATA_PARTITION
442+
EFI_STATUS get_dedicated_disk(struct gpt_partition_interface *gpart)
443+
{
444+
EFI_STATUS ret;
445+
EFI_HANDLE *handles;
446+
UINTN nb_handle = 0;
447+
PCI_DEVICE_PATH *exclude_device;
448+
EFI_DEVICE_PATH *device;
449+
PCI_DEVICE_PATH *pci;
450+
EFI_BLOCK_IO *bio;
451+
UINTN i;
452+
453+
device = DevicePathFromHandle(sdisk.handle);
454+
if (!device)
455+
return EFI_NOT_FOUND;
456+
457+
exclude_device = get_pci_device_path(device);
458+
if (exclude_device == NULL)
459+
return EFI_NOT_FOUND;
460+
461+
ret = uefi_call_wrapper(BS->LocateHandleBuffer, 5, ByProtocol,
462+
&BlockIoProtocol, NULL, &nb_handle, &handles);
463+
if (EFI_ERROR(ret))
464+
return EFI_NOT_FOUND;
465+
466+
gpart->bio = NULL;
467+
gpart->handle = 0;
468+
memset(&gpart->part, 0, sizeof(gpart->part));
469+
for (i = 0; i < nb_handle; i++) {
470+
device = DevicePathFromHandle(handles[i]);
471+
if (device == NULL)
472+
continue;
473+
474+
pci = get_pci_device_path(device);
475+
if (pci == NULL)
476+
continue;
477+
478+
if (exclude_device->Function == pci->Function &&
479+
exclude_device->Device == pci->Device)
480+
continue;
481+
482+
ret = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i], &BlockIoProtocol, (VOID *)&bio);
483+
if (EFI_ERROR(ret))
484+
continue;
485+
486+
if (bio->Media != NULL && gpart->bio != NULL)
487+
if (bio->Media->BlockSize * bio->Media->LastBlock
488+
<= gpart->bio->Media->BlockSize * gpart->bio->Media->LastBlock)
489+
continue;
490+
491+
ret = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i], &DiskIoProtocol, (VOID *)&gpart->dio);
492+
if (EFI_ERROR(ret))
493+
continue;
494+
495+
gpart->handle = handles[i];
496+
gpart->bio = bio;
497+
gpart->part.starting_lba = 0;
498+
gpart->part.ending_lba = bio->Media->LastBlock;
499+
}
500+
FreePool(handles);
501+
502+
if (gpart->handle == 0)
503+
return EFI_NOT_FOUND;
504+
505+
debug(L"dedicated data parition blocks: 0x%X", gpart->part.ending_lba + 1);
506+
return EFI_SUCCESS;
507+
}
508+
#endif
509+
440510
EFI_STATUS gpt_get_partition_by_label(const CHAR16 *label,
441511
struct gpt_partition_interface *gpart,
442512
logical_unit_t log_unit)
@@ -447,6 +517,16 @@ EFI_STATUS gpt_get_partition_by_label(const CHAR16 *label,
447517
if (!label || !gpart)
448518
return EFI_INVALID_PARAMETER;
449519

520+
#ifdef USE_DEDICATED_DATA_PARTITION
521+
if (!StrCmp(label, L"userdata") || !StrCmp(label, L"data")) {
522+
ret = get_dedicated_disk(gpart);
523+
if (ret == EFI_SUCCESS) {
524+
CopyMem(gpart->part.name, label, sizeof(gpart->part.name));
525+
return EFI_SUCCESS;
526+
}
527+
}
528+
#endif
529+
450530
ret = gpt_cache_partition(log_unit);
451531
if (EFI_ERROR(ret))
452532
return ret;

0 commit comments

Comments
 (0)