]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: stm32mp: stm32prog: use IS_ENABLED to prevent ifdef
authorPatrick Delaunay <patrick.delaunay@st.com>
Fri, 31 Jul 2020 14:31:52 +0000 (16:31 +0200)
committerPatrice Chotard <patrice.chotard@st.com>
Thu, 13 Aug 2020 07:52:49 +0000 (09:52 +0200)
Use IS_ENABLED to prevent ifdef in stm32prog command.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c

index cbf0120adcb8bcdec1e58f967ff414a821522242..49dd25b28f486af4f4b5506063930061b4d75ca9 100644 (file)
@@ -14,7 +14,6 @@ struct stm32prog_data *stm32prog_data;
 
 static void enable_vidconsole(void)
 {
-#ifdef CONFIG_DM_VIDEO
        char *stdname;
        char buf[64];
 
@@ -35,7 +34,6 @@ static void enable_vidconsole(void)
                        snprintf(buf, sizeof(buf), "%s,vidconsole", stdname);
                env_set("stderr", buf);
        }
-#endif
 }
 
 static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -86,7 +84,8 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
                                                   "script@1");
        }
 
-       enable_vidconsole();
+       if (IS_ENABLED(CONFIG_DM_VIDEO))
+               enable_vidconsole();
 
        data = (struct stm32prog_data *)malloc(sizeof(*data));
 
index e4199dbaa59862c5c62fc15544701da38af76b30..ec3355d8160534889655f17177a889804cd1b149 100644 (file)
@@ -544,10 +544,8 @@ static int init_device(struct stm32prog_data *data,
 {
        struct mmc *mmc = NULL;
        struct blk_desc *block_dev = NULL;
-#ifdef CONFIG_MTD
        struct mtd_info *mtd = NULL;
        char mtd_id[16];
-#endif
        int part_id;
        int ret;
        u64 first_addr = 0, last_addr = 0;
@@ -557,8 +555,11 @@ static int init_device(struct stm32prog_data *data,
        const char *part_name;
 
        switch (dev->target) {
-#ifdef CONFIG_MMC
        case STM32PROG_MMC:
+               if (!IS_ENABLED(CONFIG_MMC)) {
+                       stm32prog_err("unknown device type = %d", dev->target);
+                       return -ENODEV;
+               }
                mmc = find_mmc_device(dev->dev_id);
                if (!mmc || mmc_init(mmc)) {
                        stm32prog_err("mmc device %d not found", dev->dev_id);
@@ -589,11 +590,13 @@ static int init_device(struct stm32prog_data *data,
                         first_addr, last_addr);
                pr_debug(" full_update = %d\n", dev->full_update);
                break;
-#endif
-#ifdef CONFIG_MTD
        case STM32PROG_NOR:
        case STM32PROG_NAND:
        case STM32PROG_SPI_NAND:
+               if (!IS_ENABLED(CONFIG_MTD)) {
+                       stm32prog_err("unknown device type = %d", dev->target);
+                       return -ENODEV;
+               }
                get_mtd_by_target(mtd_id, dev->target, dev->dev_id);
                pr_debug("%s\n", mtd_id);
 
@@ -612,7 +615,6 @@ static int init_device(struct stm32prog_data *data,
                         first_addr, last_addr);
                dev->mtd = mtd;
                break;
-#endif
        case STM32PROG_RAM:
                first_addr = gd->bd->bi_dram[0].start;
                last_addr = first_addr + gd->bd->bi_dram[0].size;
@@ -744,8 +746,7 @@ static int init_device(struct stm32prog_data *data,
                        part_found = true;
                }
 
-#ifdef CONFIG_MTD
-               if (mtd) {
+               if (IS_ENABLED(CONFIG_MTD) && mtd) {
                        char mtd_part_id[32];
                        struct part_info *mtd_part;
                        struct mtd_device *mtd_dev;
@@ -766,7 +767,7 @@ static int init_device(struct stm32prog_data *data,
                        part_name = mtd_part->name;
                        part_found = true;
                }
-#endif
+
                if (!part_found) {
                        stm32prog_err("%s (0x%x): Invalid partition",
                                      part->name, part->id);
@@ -873,9 +874,8 @@ static int treat_partition_list(struct stm32prog_data *data)
        return 0;
 }
 
-static int create_partitions(struct stm32prog_data *data)
+static int create_gpt_partitions(struct stm32prog_data *data)
 {
-#ifdef CONFIG_MMC
        int offset = 0;
        const int buflen = SZ_8K;
        char *buf;
@@ -991,7 +991,6 @@ static int create_partitions(struct stm32prog_data *data)
        run_command("mtd list", 0);
 #endif
        free(buf);
-#endif
 
        return 0;
 }
@@ -1070,28 +1069,35 @@ static int stm32prog_alt_add(struct stm32prog_data *data,
                offset += snprintf(buf + offset, ALT_BUF_LEN - offset,
                                   " %d;", part->part_id);
        }
+       ret = -ENODEV;
        switch (part->target) {
-#ifdef CONFIG_MMC
        case STM32PROG_MMC:
-               sprintf(dfustr, "mmc");
-               sprintf(devstr, "%d", part->dev_id);
+               if (IS_ENABLED(CONFIG_MMC)) {
+                       ret = 0;
+                       sprintf(dfustr, "mmc");
+                       sprintf(devstr, "%d", part->dev_id);
+               }
                break;
-#endif
-#ifdef CONFIG_MTD
        case STM32PROG_NAND:
        case STM32PROG_NOR:
        case STM32PROG_SPI_NAND:
-               sprintf(dfustr, "mtd");
-               get_mtd_by_target(devstr, part->target, part->dev_id);
+               if (IS_ENABLED(CONFIG_MTD)) {
+                       ret = 0;
+                       sprintf(dfustr, "mtd");
+                       get_mtd_by_target(devstr, part->target, part->dev_id);
+               }
                break;
-#endif
        case STM32PROG_RAM:
+               ret = 0;
                sprintf(dfustr, "ram");
                sprintf(devstr, "0");
                break;
        default:
+               break;
+       }
+       if (ret) {
                stm32prog_err("invalid target: %d", part->target);
-               return -ENODEV;
+               return ret;
        }
        pr_debug("dfu_alt_add(%s,%s,%s)\n", dfustr, devstr, buf);
        ret = dfu_alt_add(dfu, dfustr, devstr, buf);
@@ -1213,13 +1219,14 @@ int stm32prog_otp_write(struct stm32prog_data *data, u32 offset, u8 *buffer,
 int stm32prog_otp_read(struct stm32prog_data *data, u32 offset, u8 *buffer,
                       long *size)
 {
-#ifndef CONFIG_ARM_SMCCC
-       stm32prog_err("OTP update not supported");
-
-       return -1;
-#else
        int result = 0;
 
+       if (!IS_ENABLED(CONFIG_ARM_SMCCC)) {
+               stm32prog_err("OTP update not supported");
+
+               return -1;
+       }
+
        pr_debug("%s: %x %lx\n", __func__, offset, *size);
        /* alway read for first packet */
        if (!offset) {
@@ -1255,19 +1262,19 @@ end_otp_read:
        pr_debug("%s: result %i\n", __func__, result);
 
        return result;
-#endif
 }
 
 int stm32prog_otp_start(struct stm32prog_data *data)
 {
-#ifndef CONFIG_ARM_SMCCC
-       stm32prog_err("OTP update not supported");
-
-       return -1;
-#else
        int result = 0;
        struct arm_smccc_res res;
 
+       if (!IS_ENABLED(CONFIG_ARM_SMCCC)) {
+               stm32prog_err("OTP update not supported");
+
+               return -1;
+       }
+
        if (!data->otp_part) {
                stm32prog_err("start OTP without data");
                return -1;
@@ -1302,7 +1309,6 @@ int stm32prog_otp_start(struct stm32prog_data *data)
        pr_debug("%s: result %i\n", __func__, result);
 
        return result;
-#endif
 }
 
 int stm32prog_pmic_write(struct stm32prog_data *data, u32 offset, u8 *buffer,
@@ -1538,19 +1544,20 @@ static int part_delete(struct stm32prog_data *data,
                       struct stm32prog_part_t *part)
 {
        int ret = 0;
-#ifdef CONFIG_MMC
        unsigned long blks, blks_offset, blks_size;
        struct blk_desc *block_dev = NULL;
- #endif
-#ifdef CONFIG_MTD
        char cmdbuf[40];
        char devstr[10];
-#endif
 
        printf("Erasing %s ", part->name);
        switch (part->target) {
-#ifdef CONFIG_MMC
        case STM32PROG_MMC:
+               if (!IS_ENABLED(CONFIG_MMC)) {
+                       ret = -1;
+                       stm32prog_err("%s (0x%x): erase invalid",
+                                     part->name, part->id);
+                       break;
+               }
                printf("on mmc %d: ", part->dev->dev_id);
                block_dev = mmc_get_blk_desc(part->dev->mmc);
                blks_offset = lldiv(part->addr, part->dev->mmc->read_bl_len);
@@ -1576,11 +1583,15 @@ static int part_delete(struct stm32prog_data *data,
                                      part->name, part->id);
                }
                break;
-#endif
-#ifdef CONFIG_MTD
        case STM32PROG_NOR:
        case STM32PROG_NAND:
        case STM32PROG_SPI_NAND:
+               if (!IS_ENABLED(CONFIG_MTD)) {
+                       ret = -1;
+                       stm32prog_err("%s (0x%x): erase invalid",
+                                     part->name, part->id);
+                       break;
+               }
                get_mtd_by_target(devstr, part->target, part->dev->dev_id);
                printf("on %s: ", devstr);
                sprintf(cmdbuf, "mtd erase %s 0x%llx 0x%llx",
@@ -1591,7 +1602,6 @@ static int part_delete(struct stm32prog_data *data,
                                      part->name, part->id, cmdbuf);
                }
                break;
-#endif
        case STM32PROG_RAM:
                printf("on ram: ");
                memset((void *)(uintptr_t)part->addr, 0, (size_t)part->size);
@@ -1639,9 +1649,11 @@ static void stm32prog_devices_init(struct stm32prog_data *data)
                        goto error;
        }
 
-       ret = create_partitions(data);
-       if (ret)
-               goto error;
+       if (IS_ENABLED(CONFIG_MMC)) {
+               ret = create_gpt_partitions(data);
+               if (ret)
+                       goto error;
+       }
 
        /* delete partition GPT or MTD */
        for (i = 0; i < data->part_nb; i++) {