{
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;
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);
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);
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;
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;
part_name = mtd_part->name;
part_found = true;
}
-#endif
+
if (!part_found) {
stm32prog_err("%s (0x%x): Invalid partition",
part->name, part->id);
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;
run_command("mtd list", 0);
#endif
free(buf);
-#endif
return 0;
}
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);
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) {
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;
pr_debug("%s: result %i\n", __func__, result);
return result;
-#endif
}
int stm32prog_pmic_write(struct stm32prog_data *data, u32 offset, u8 *buffer,
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);
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",
part->name, part->id, cmdbuf);
}
break;
-#endif
case STM32PROG_RAM:
printf("on ram: ");
memset((void *)(uintptr_t)part->addr, 0, (size_t)part->size);
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++) {