From 57d4114d689d7903c64f8ee755b20b44d207a459 Mon Sep 17 00:00:00 2001 From: Venkata Rao Kakani Date: Thu, 29 Apr 2021 12:42:38 +0530 Subject: [PATCH] drivers: rename_block: Enable A/B support Enable A/B support by appending slot suffix based on androidboot.slot_suffix. Change-Id: I7bdc798f6203ba026606d56cf0bc76e0cfbb6b4a Signed-off-by: Venkata Rao Kakani --- drivers/soc/qcom/rename_block_device.c | 41 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/soc/qcom/rename_block_device.c b/drivers/soc/qcom/rename_block_device.c index 917482077b6b..81500f1650bf 100644 --- a/drivers/soc/qcom/rename_block_device.c +++ b/drivers/soc/qcom/rename_block_device.c @@ -10,6 +10,39 @@ #include #include #define PATH_SIZE 32 +#define SLOT_STR_LENGTH 3 +#define MAX_STR_SIZE 255 + +static char active_slot[SLOT_STR_LENGTH]; +static char backup_slot[SLOT_STR_LENGTH]; +static int dp_enabled; +static char final_name[MAX_STR_SIZE]; +static int __init set_slot_suffix(char *str) +{ + if (str) { + strlcpy(active_slot, str, SLOT_STR_LENGTH); + strcmp(active_slot, "_a") ? + strlcpy(backup_slot, "_a", SLOT_STR_LENGTH) : + strlcpy(backup_slot, "_b", SLOT_STR_LENGTH); + dp_enabled = 1; + } + return 1; +} +__setup("androidboot.slot_suffix=", set_slot_suffix); + +static void get_slot_updated_name(char *name) +{ + int length = strlen(name); + + memset(final_name, '\0', MAX_STR_SIZE); + strlcpy(final_name, name, MAX_STR_SIZE); + if (dp_enabled && (final_name[length-2] == '_')) { + if (final_name[length-1] == 'a') + final_name[length-1] = active_slot[1]; + else if (final_name[length-1] == 'b') + final_name[length-1] = backup_slot[1]; + } +} static int rename_blk_dev_init(void) { @@ -18,7 +51,8 @@ static int rename_blk_dev_init(void) struct gendisk *disk; struct device_node *node; char dev_path[PATH_SIZE]; - const char *actual_name, *modified_name; + const char *actual_name; + char *modified_name; node = of_find_compatible_node(NULL, NULL, "qcom,blkdev-rename"); if (!node) { @@ -40,8 +74,9 @@ static int rename_blk_dev_init(void) return -ENXIO; } if (!of_property_read_string_index(node, "rename-dev", index, - &modified_name)) { - device_rename(disk_to_dev(disk), modified_name); + (const char **)&modified_name)) { + get_slot_updated_name(modified_name); + device_rename(disk_to_dev(disk), final_name); } else { pr_err("rename-dev for actual-dev = %s is missing\n", actual_name);