All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@st.com>
To: u-boot@lists.denx.de
Subject: [PATCH 11/11] arm: stm32mp: stm32prog: use IS_ENABLED to prevent ifdef
Date: Thu, 13 Aug 2020 07:25:12 +0000	[thread overview]
Message-ID: <cf7bd4e1-702c-2143-e4f9-e0e73cf997c1@st.com> (raw)
In-Reply-To: <20200731143152.8812-11-patrick.delaunay@st.com>

Hi Patrick

On 7/31/20 4:31 PM, Patrick Delaunay wrote:
> Use IS_ENABLED to prevent ifdef in stm32prog command.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  .../cmd_stm32prog/cmd_stm32prog.c             |   5 +-
>  .../mach-stm32mp/cmd_stm32prog/stm32prog.c    | 100 ++++++++++--------
>  2 files changed, 58 insertions(+), 47 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> index cbf0120adc..49dd25b28f 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> @@ -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 at 1");
>  	}
>  
> -	enable_vidconsole();
> +	if (IS_ENABLED(CONFIG_DM_VIDEO))
> +		enable_vidconsole();
>  
>  	data = (struct stm32prog_data *)malloc(sizeof(*data));
>  
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> index e4199dbaa5..ec3355d816 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> @@ -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++) {

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks

Patrice

  reply	other threads:[~2020-08-13  7:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 14:31 [PATCH 01/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in board_key_check Patrick Delaunay
2020-07-31 14:31 ` [PATCH 02/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in g_dnl_board_usb_cable_connected Patrick Delaunay
2020-08-13  7:22   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:49     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 03/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in board_check_usb_power Patrick Delaunay
2020-08-13  7:22   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  7:22   ` Patrice CHOTARD
2020-08-13  9:49     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 04/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in sysconf_init Patrick Delaunay
2020-08-13  7:23   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:50     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 05/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in set_dfu_alt_inf Patrick Delaunay
2020-08-13  7:23   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:51     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 06/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in dk2_i2c1_fix Patrick Delaunay
2020-08-13  7:23   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:51     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 07/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in board_late_init Patrick Delaunay
2020-08-13  7:24   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:52     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 08/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in env functions Patrick Delaunay
2020-08-13  7:24   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:53     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 09/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in ft_board_setup Patrick Delaunay
2020-08-13  7:24   ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  9:53     ` Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 10/11] arm: stm32mp: bsec: use IS_ENABLED to prevent ifdef Patrick Delaunay
2020-08-13  7:24   ` Patrice CHOTARD
2020-08-13  9:54     ` [Uboot-stm32] " Patrice CHOTARD
2020-07-31 14:31 ` [PATCH 11/11] arm: stm32mp: stm32prog: " Patrick Delaunay
2020-08-13  7:25   ` Patrice CHOTARD [this message]
2020-08-13  9:55     ` [Uboot-stm32] " Patrice CHOTARD
2020-08-13  7:51 ` [Uboot-stm32] [PATCH 01/11] board: stm32mp1: use IS_ENABLED to prevent ifdef in board_key_check Patrice CHOTARD
2020-08-13  9:49   ` Patrice CHOTARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf7bd4e1-702c-2143-e4f9-e0e73cf997c1@st.com \
    --to=patrice.chotard@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.