C语言编译报:warning: variable ‘XXX’ set but not used [-Wunused-but-set-variable], 如何消除warning?
board/novatek/nvt-na51023/na51023_utils.c: In function ‘nvt_flash_mtdpart_config’:
board/novatek/nvt-na51023/na51023_utils.c:317:27: warning: variable ‘pst_part_num’ set but not used [-Wunused-but-set-variable]
uint32_t i, j, part_num, pst_part_num;
int nvt_flash_mtdpart_config(char *p_cmdline, EMB_PARTITION *partition_ptr)
{
MODELEXT_HEADER* header;
EMB_PARTITION *p_partition;
uint32_t i, j, part_num, pst_part_num;
int ret = 0;
char cmd[1024];
char buf[1024];
//struct spi_flash *flash = board_init_spi_flash;
#if defined(CONFIG_NVT_LINUX_RAMDISK_BOOT) || defined(CONFIG_NVT_LINUX_AUTOLOAD)
#if defined(CONFIG_NVT_SPI_NAND)
nand_info_t *nand = &nand_info[0];
#elif defined(CONFIG_NVT_SPI_NOR)
struct spi_flash *spi_flash = board_init_spi_flash;
#elif defined(CONFIG_NVT_IVOT_EMMC)
struct mmc *mmc = find_mmc_device(CONFIG_NVT_IVOT_EMMC);
#else
return 0;
#endif
#elif defined(CONFIG_NVT_LINUX_SPINAND_BOOT)
nand_info_t *nand = &nand_info[0];
#elif defined(CONFIG_NVT_LINUX_EMMC_BOOT)
struct mmc *mmc = find_mmc_device(CONFIG_NVT_IVOT_EMMC);
#else
struct spi_flash *spi_flash = board_init_spi_flash;
#endif
#if defined(CONFIG_NVT_LINUX_EMMC_BOOT)
/* MMC device doesn't need to init mtdparts parameter */
if (p_cmdline == NULL) {
return 0;
}
#endif /* CONFIG_NVT_LINUX_EMMC_BOOT */
if (partition_ptr == NULL) {
p_partition = (EMB_PARTITION*)modelext_get_cfg((unsigned char*)CONFIG_MODELEXT_SDRAM_BASE, MODELEXT_TYPE_EMB_PARTITION, &header);
if(!p_partition || !header){
printf("partition//header is null\n");
return -1;
}
} else {
/* Receive partition table from argu */
p_partition = partition_ptr;
}
#if defined(CONFIG_NVT_LINUX_SPINAND_BOOT)
sprintf(cmd, "nand0=spi_nand.0");
ret = setenv("mtdids",cmd);
if (ret) {
printf("%s: error set\n", __func__);
return ret;
}
sprintf(cmd,"mtdparts=spi_nand.0:");
if (p_cmdline != NULL) {
/* To find if mtdparts string existed. If yes, it needs to expand mtdparts environment */
char *mtdparts_off = NULL;
mtdparts_off = strstr ((char *)p_cmdline, "mtdparts=");
if (mtdparts_off) {
p_cmdline = mtdparts_off;
*p_cmdline = '\0';
}
strcat(p_cmdline, "mtdparts=spi_nand.0:");
}
#elif defined(CONFIG_NVT_IVOT_EMMC)
if (p_cmdline != NULL) {
/* To find if mtdparts string existed. If yes, it needs to expand mtdparts environment */
char *nvtemmcpart_off = NULL;
nvtemmcpart_off = strstr((char *)p_cmdline, "nvtemmcpart=");
if (nvtemmcpart_off) {
p_cmdline = nvtemmcpart_off;
*p_cmdline = '\0';
}
strcat(p_cmdline, "nvtemmcpart=");
}
#else
sprintf(cmd, "sf0=spi_nor.0");
ret = setenv("mtdids",cmd);
if (ret) {
printf("%s: error set\n", __func__);
return ret;
}
sprintf(cmd,"mtdparts=spi_nor.0:");
if (p_cmdline != NULL) {
/* To find if mtdparts string existed. If yes, it needs to expand mtdparts environment */
char *mtdparts_off = NULL;
mtdparts_off = strstr ((char *)p_cmdline, "mtdparts=");
if (mtdparts_off) {
p_cmdline = mtdparts_off;
*p_cmdline = '\0';
}
strcat(p_cmdline, "mtdparts=spi_nor.0:");
}
#endif
j = 0;
part_num = 0;
pst_part_num = 0;
/* To parse mtdparts for rootfs partition table */
for (i = 0 ; i < EMB_PARTITION_INFO_COUNT ; i++) {
const EMB_PARTITION* p = p_partition + i;
unsigned int PartitionSize = 0, PartitionOffset = 0;
#if defined(CONFIG_NVT_SPI_NAND)
PartitionSize = p->PartitionSize * nand->erasesize;
PartitionOffset = p->PartitionOffset * nand->erasesize;
#elif defined(CONFIG_NVT_IVOT_EMMC)
PartitionSize = p->PartitionSize;
PartitionOffset = p->PartitionOffset;
#else
PartitionSize = p->PartitionSize * CONFIG_ENV_SECT_SIZE;
PartitionOffset = p->PartitionOffset * CONFIG_ENV_SECT_SIZE;
#endif
if(p->PartitionSize == 0)
continue;
switch(p->EmbType)
{
case EMBTYPE_LOADER:
sprintf(buf, "0x%x@0x%x(loader),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(loader),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_MODELEXT:
sprintf(buf, "0x%x@0x%x(modelext),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(modelext),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_UITRON:
sprintf(buf, "0x%x@0x%x(uitron),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(uitron),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_ECOS:
sprintf(buf, "0x%x@0x%x(ecos),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(ecos),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_UBOOT:
sprintf(buf, "0x%x@0x%x(uboot),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(uboot),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_UENV:
sprintf(buf, "0x%x@0x%x(uenv),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_LINUX:
sprintf(buf, "0x%x@0x%x(linux),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(linux),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_RAMFS:
sprintf(buf, "0x%x@0x%x(ramfs),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_ROOTFS:
sprintf(buf, "0x%x@0x%x(rootfs),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
strcat(p_cmdline, buf);
if (part_num == 0) {
#if !defined(CONFIG_NVT_IVOT_EMMC)
part_num = j;
#else
if (p->OrderIdx == 0)
part_num = ++j;
#endif
}
}
break;
case EMBTYPE_FAT:
sprintf(buf, "0x%x@0x%x(fat),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_DSP:
sprintf(buf, "0x%x@0x%x(dsp%d),", PartitionSize, PartitionOffset, p->OrderIdx);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(dsp%d),", PartitionSize, PartitionOffset, p->OrderIdx);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_PSTORE:
sprintf(buf, "0x%x@0x%x(pstore),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(pstore),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if defined(CONFIG_NVT_IVOT_EMMC)
pst_part_num = ++j;
#else
j++;
#endif
}
break;
#if (defined(_UITRON_DUAL_IMAGE_ON_))
case EMBTYPE_UITRON_BACKUP:
sprintf(buf, "0x%x@0x%x(uitron_backup),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(uitron_backup),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
case EMBTYPE_MODELEXT_BACKUP:
sprintf(buf, "0x%x@0x%x(modelext_backup),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(modelext_backup),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
#endif
default:
sprintf(buf, "0x%x@0x%x(user),", PartitionSize, PartitionOffset);
strcat(cmd, buf);
if (p_cmdline != NULL) {
sprintf(buf, "0x%x@0x%x(user),", PartitionSize, PartitionOffset);
strcat(p_cmdline, buf);
#if !defined(CONFIG_NVT_IVOT_EMMC)
j++;
#endif
}
break;
}
}
if (p_cmdline != NULL) {
/* To add entire nand mtd device */
#if defined(CONFIG_NVT_SPI_NAND)
sprintf(buf, "0x%llx@0(total),", nand->size);
#elif defined(CONFIG_NVT_SPI_NOR)
sprintf(buf, "0x%x@0(total),", spi_flash->size);
#elif defined(CONFIG_NVT_IVOT_EMMC)
sprintf(buf, "0x%llx@0(total),", mmc->capacity/MMC_MAX_BLOCK_LEN);
#endif
strcat(p_cmdline, buf);
/*
* Add bootarg rootfs extension parameter
*/
p_cmdline[strlen(p_cmdline) - 1] = ' ';
#if defined(CONFIG_NVT_UBIFS_SUPPORT)
sprintf(buf," ubi.mtd=%d ", part_num);
strcat(p_cmdline, buf);
#elif defined(CONFIG_NVT_EXT4_SUPPORT)
sprintf(buf," root=/dev/mmcblk2p%d nvt_pst=/dev/mmcblk2p%d ", part_num, pst_part_num);
strcat(p_cmdline, buf);
#else
/*
* To handle non-ubifs rootfs type (squashfs/jffs2)
*/
sprintf(buf," root=/dev/mtdblock%d ", part_num);
strcat(p_cmdline, buf);
#endif /* _NVT_ROOTFS_TYPE_ */
}
/* To handle uboot mtd env config */
cmd[strlen(cmd) - 1] = '\0';
ret = setenv("mtdparts",cmd);
return ret;
}