blk: Use a function for whether block devices are available
At present we use HAVE_BLOCK_DEVICE to indicate when block devices are available. This is a very strange option, since it partially duplicates the BLK option used by driver model. It also covers both U-Boot proper and SPL, even though one might have block devices and another not. As a first step towards correcting this, create a new inline function called blk_enabled() which indicates if block devices are available. This cannot be used in Makefiles, or #if clauses, but can be used in C code. A function is useful because we cannot use CONFIG_IS_ENABLED(BLK) to decide if block devices are needed, since we must consider the legacy block interface, enabled by HAVE_BLOCK_DEVICE Update a few places where it can be used and drop some unnecessary #if checks around some functions in disk/part.c - rely on the compiler's dead-code elimination instead. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
fc614d2044
commit
a51eb8de31
80
disk/part.c
80
disk/part.c
@ -54,12 +54,13 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_BLOCK_DEVICE
|
|
||||||
static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
|
static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
|
||||||
{
|
{
|
||||||
struct blk_desc *dev_desc;
|
struct blk_desc *dev_desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (!blk_enabled())
|
||||||
|
return NULL;
|
||||||
dev_desc = blk_get_devnum_by_typename(ifname, dev);
|
dev_desc = blk_get_devnum_by_typename(ifname, dev);
|
||||||
if (!dev_desc) {
|
if (!dev_desc) {
|
||||||
debug("%s: No device for iface '%s', dev %d\n", __func__,
|
debug("%s: No device for iface '%s', dev %d\n", __func__,
|
||||||
@ -78,21 +79,11 @@ static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
|
|||||||
|
|
||||||
struct blk_desc *blk_get_dev(const char *ifname, int dev)
|
struct blk_desc *blk_get_dev(const char *ifname, int dev)
|
||||||
{
|
{
|
||||||
|
if (!blk_enabled())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return get_dev_hwpart(ifname, dev, 0);
|
return get_dev_hwpart(ifname, dev, 0);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct blk_desc *blk_get_dev(const char *ifname, int dev)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_BLOCK_DEVICE
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/*
|
/*
|
||||||
@ -228,9 +219,6 @@ void dev_print (struct blk_desc *dev_desc)
|
|||||||
puts (" Capacity: not available\n");
|
puts (" Capacity: not available\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_BLOCK_DEVICE
|
|
||||||
|
|
||||||
void part_init(struct blk_desc *dev_desc)
|
void part_init(struct blk_desc *dev_desc)
|
||||||
{
|
{
|
||||||
@ -325,38 +313,36 @@ void part_print(struct blk_desc *dev_desc)
|
|||||||
drv->print(dev_desc);
|
drv->print(dev_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_HAVE_BLOCK_DEVICE */
|
|
||||||
|
|
||||||
int part_get_info(struct blk_desc *dev_desc, int part,
|
int part_get_info(struct blk_desc *dev_desc, int part,
|
||||||
struct disk_partition *info)
|
struct disk_partition *info)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_HAVE_BLOCK_DEVICE
|
|
||||||
struct part_driver *drv;
|
struct part_driver *drv;
|
||||||
|
|
||||||
|
if (blk_enabled()) {
|
||||||
#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
|
#if CONFIG_IS_ENABLED(PARTITION_UUIDS)
|
||||||
/* The common case is no UUID support */
|
/* The common case is no UUID support */
|
||||||
info->uuid[0] = 0;
|
info->uuid[0] = 0;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_PARTITION_TYPE_GUID
|
#ifdef CONFIG_PARTITION_TYPE_GUID
|
||||||
info->type_guid[0] = 0;
|
info->type_guid[0] = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
drv = part_driver_lookup_type(dev_desc);
|
drv = part_driver_lookup_type(dev_desc);
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
debug("## Unknown partition table type %x\n",
|
debug("## Unknown partition table type %x\n",
|
||||||
dev_desc->part_type);
|
dev_desc->part_type);
|
||||||
return -EPROTONOSUPPORT;
|
return -EPROTONOSUPPORT;
|
||||||
|
}
|
||||||
|
if (!drv->get_info) {
|
||||||
|
PRINTF("## Driver %s does not have the get_info() method\n",
|
||||||
|
drv->name);
|
||||||
|
return -ENOSYS;
|
||||||
|
}
|
||||||
|
if (drv->get_info(dev_desc, part, info) == 0) {
|
||||||
|
PRINTF("## Valid %s partition found ##\n", drv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!drv->get_info) {
|
|
||||||
PRINTF("## Driver %s does not have the get_info() method\n",
|
|
||||||
drv->name);
|
|
||||||
return -ENOSYS;
|
|
||||||
}
|
|
||||||
if (drv->get_info(dev_desc, part, info) == 0) {
|
|
||||||
PRINTF("## Valid %s partition found ##\n", drv->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_HAVE_BLOCK_DEVICE */
|
|
||||||
|
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
@ -424,15 +410,15 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_BLOCK_DEVICE
|
if (blk_enabled()) {
|
||||||
/*
|
/*
|
||||||
* Updates the partition table for the specified hw partition.
|
* Updates the partition table for the specified hw partition.
|
||||||
* Always should be done, otherwise hw partition 0 will return stale
|
* Always should be done, otherwise hw partition 0 will return
|
||||||
* data after displaying a non-zero hw partition.
|
* stale data after displaying a non-zero hw partition.
|
||||||
*/
|
*/
|
||||||
if ((*dev_desc)->if_type == IF_TYPE_MMC)
|
if ((*dev_desc)->if_type == IF_TYPE_MMC)
|
||||||
part_init(*dev_desc);
|
part_init(*dev_desc);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(dup_str);
|
free(dup_str);
|
||||||
|
@ -743,8 +743,7 @@ int blk_unbind_all(int if_type)
|
|||||||
|
|
||||||
static int blk_post_probe(struct udevice *dev)
|
static int blk_post_probe(struct udevice *dev)
|
||||||
{
|
{
|
||||||
if (CONFIG_IS_ENABLED(PARTITIONS) &&
|
if (CONFIG_IS_ENABLED(PARTITIONS) && blk_enabled()) {
|
||||||
IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
|
|
||||||
struct blk_desc *desc = dev_get_uclass_plat(dev);
|
struct blk_desc *desc = dev_get_uclass_plat(dev);
|
||||||
|
|
||||||
part_init(desc);
|
part_init(desc);
|
||||||
|
@ -1144,7 +1144,7 @@ int file_fat_detectfs(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
|
if (blk_enabled()) {
|
||||||
printf("Interface: %s\n", blk_get_if_type_name(cur_dev->if_type));
|
printf("Interface: %s\n", blk_get_if_type_name(cur_dev->if_type));
|
||||||
printf(" Device %d: ", cur_dev->devnum);
|
printf(" Device %d: ", cur_dev->devnum);
|
||||||
dev_print(cur_dev);
|
dev_print(cur_dev);
|
||||||
|
@ -21,6 +21,11 @@ typedef ulong lbaint_t;
|
|||||||
|
|
||||||
struct udevice;
|
struct udevice;
|
||||||
|
|
||||||
|
static inline bool blk_enabled(void)
|
||||||
|
{
|
||||||
|
return CONFIG_IS_ENABLED(BLK) || IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Interface types: */
|
/* Interface types: */
|
||||||
enum if_type {
|
enum if_type {
|
||||||
IF_TYPE_UNKNOWN = 0,
|
IF_TYPE_UNKNOWN = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user