100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
/*
|
|||
|
|
* SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
|
||
|
|
*
|
||
|
|
* Copyright 2020-2023 Unisoc (Shanghai) Technologies Co., Ltd.
|
||
|
|
*
|
||
|
|
* Licensed under the Unisoc General Software License, version 1.0 (the License);
|
||
|
|
* you may not use this file except in compliance with the License.
|
||
|
|
* You may obtain a copy of the License at
|
||
|
|
* https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
|
||
|
|
*
|
||
|
|
* Software distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
|
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
|
||
|
|
* See the Unisoc General Software License, version 1.0 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include <part.h>
|
||
|
|
#include <common.h>
|
||
|
|
extern block_dev_desc_t sprd_mmc_dev;
|
||
|
|
extern block_dev_desc_t sprd_ufs_dev;
|
||
|
|
extern block_dev_desc_t sprd_sd_dev;
|
||
|
|
|
||
|
|
#ifdef CONFIG_UFS_LOGICAL_SET
|
||
|
|
struct partition_table {
|
||
|
|
uint32_t lu_index;
|
||
|
|
uchar * partitions;
|
||
|
|
};
|
||
|
|
|
||
|
|
#ifdef AB_PARTITIONS
|
||
|
|
struct partition_table lu_partition_table[] = {
|
||
|
|
{3, "uboot_a,uboot_b,teecfg_a,teecfg_b,sml_a,sml_b,trustos_a,trustos_b,"}
|
||
|
|
};
|
||
|
|
#else
|
||
|
|
struct partition_table lu_partition_table[] = {
|
||
|
|
{3, "uboot,uboot_bak,teecfg,teecfg_bak,sml,sml_bak,trustos,trustos_bak,"}
|
||
|
|
};
|
||
|
|
#endif /* AB_PARTITIONS */
|
||
|
|
|
||
|
|
#define sprd_strspilt(src, dst, spilt_char) \
|
||
|
|
do { \
|
||
|
|
for(; *src && *src != spilt_char; src++, dst++) { \
|
||
|
|
*dst = *src; \
|
||
|
|
} \
|
||
|
|
} while(0)
|
||
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||
|
|
|
||
|
|
static int lun_match(uchar *partition_name)
|
||
|
|
{
|
||
|
|
int i;
|
||
|
|
char *src_str, *dst_str;
|
||
|
|
char tmp_str[16];
|
||
|
|
dst_str = tmp_str;
|
||
|
|
for(i = 0; i < ARRAY_SIZE(lu_partition_table); i++) {
|
||
|
|
src_str = lu_partition_table[i].partitions;
|
||
|
|
for(; *src_str; src_str++) {
|
||
|
|
sprd_strspilt(src_str, dst_str, ',');
|
||
|
|
*dst_str = '\0';
|
||
|
|
if (!sprd_strcmp(tmp_str, partition_name))
|
||
|
|
return lu_partition_table[i].lu_index;
|
||
|
|
dst_str = tmp_str;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
block_dev_desc_t *get_dev_by_partition(uchar *partition_name)
|
||
|
|
{
|
||
|
|
sprd_ufs_dev.dev = lun_match(partition_name);
|
||
|
|
return ufs_get_dev();
|
||
|
|
}
|
||
|
|
#endif /* CONFIG_UFS_LOGICAL_SET */
|
||
|
|
|
||
|
|
block_dev_desc_t *get_dev()
|
||
|
|
{
|
||
|
|
#ifdef CONFIG_EMMC_BOOT
|
||
|
|
return mmc_get_dev();
|
||
|
|
#elif defined(CONFIG_UFS_BOOT)
|
||
|
|
return ufs_get_dev();
|
||
|
|
#elif defined(CONFIG_SD_CARD_BOOT)
|
||
|
|
return sd_get_dev();
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
int get_partition_info_by_name (block_dev_desc_t *dev_desc, uchar * partition_name,
|
||
|
|
disk_partition_t *info)
|
||
|
|
{
|
||
|
|
switch(dev_desc->part_type){
|
||
|
|
#ifdef CONFIG_EFI_PARTITION
|
||
|
|
case PART_TYPE_EFI:
|
||
|
|
if (get_partition_info_by_name_efi(dev_desc, partition_name, info)== 0) {
|
||
|
|
//PRINTF ("## Valid EFI partition found ##\n");
|
||
|
|
return (0);
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
#endif
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return (-1);
|
||
|
|
}
|