diff --git a/common/cmd_flash.c b/common/cmd_flash.c
index bc651fa1fd48259f9cda4f984f5f0f89a78b6ad2..3773412549bd66c7d2238b3e93a65bfc27154de5 100644
--- a/common/cmd_flash.c
+++ b/common/cmd_flash.c
@@ -467,8 +467,10 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	flash_info_t *info;
 	ulong bank;
 	int i, n, sect_first, sect_last;
-	ulong addr_first, addr_last;
 #endif /* CONFIG_SYS_NO_FLASH */
+#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
+	ulong addr_first, addr_last;
+#endif
 #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)
 	struct mtd_device *dev;
 	struct part_info *part;