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

Commit 84385f1

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 84385f1

2 files changed

Lines changed: 83 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: 79 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,71 @@ 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+
ret = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i], &DiskIoProtocol, (VOID *)&gpart->dio);
487+
if (EFI_ERROR(ret))
488+
continue;
489+
490+
gpart->handle = handles[i];
491+
gpart->bio = bio;
492+
gpart->part.starting_lba = 0;
493+
gpart->part.ending_lba = bio->Media->LastBlock;
494+
break;
495+
}
496+
FreePool(handles);
497+
498+
if (gpart->handle == 0)
499+
return EFI_NOT_FOUND;
500+
501+
debug(L"dedicated data parition blocks: 0x%X", gpart->part.ending_lba + 1);
502+
return EFI_SUCCESS;
503+
}
504+
#endif
505+
440506
EFI_STATUS gpt_get_partition_by_label(const CHAR16 *label,
441507
struct gpt_partition_interface *gpart,
442508
logical_unit_t log_unit)
@@ -447,6 +513,19 @@ EFI_STATUS gpt_get_partition_by_label(const CHAR16 *label,
447513
if (!label || !gpart)
448514
return EFI_INVALID_PARAMETER;
449515

516+
#ifdef USE_DEDICATED_DATA_PARTITION
517+
/* if dynamic partition enabled, data partition's name is "userdata";
518+
* if dynamic partition disabled, data partition's name is "data"
519+
*/
520+
if (!StrCmp(label, L"userdata") || !StrCmp(label, L"data")) {
521+
ret = get_dedicated_disk(gpart);
522+
if (ret == EFI_SUCCESS) {
523+
CopyMem(gpart->part.name, label, sizeof(gpart->part.name));
524+
return EFI_SUCCESS;
525+
}
526+
}
527+
#endif
528+
450529
ret = gpt_cache_partition(log_unit);
451530
if (EFI_ERROR(ret))
452531
return ret;

0 commit comments

Comments
 (0)