Use #ifdef for IMAGE_BL* instead of #if

One nasty part of ATF is some of boolean macros are always defined
as 1 or 0, and the rest of them are only defined under certain
conditions.

For the former group, "#if FOO" or "#if !FOO" must be used because
"#ifdef FOO" is always true.  (Options passed by $(call add_define,)
are the cases.)

For the latter, "#ifdef FOO" or "#ifndef FOO" should be used because
checking the value of an undefined macro is strange.

Here, IMAGE_BL* is handled by make_helpers/build_macro.mk like
follows:

  $(eval IMAGE := IMAGE_BL$(call uppercase,$(3)))

  $(OBJ): $(2)
          @echo "  CC      $$<"
          $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@

This means, IMAGE_BL* is defined when building the corresponding
image, but *undefined* for the other images.

So, IMAGE_BL* belongs to the latter group where we should use #ifdef
or #ifndef.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
diff --git a/include/common/aarch32/el3_common_macros.S b/include/common/aarch32/el3_common_macros.S
index dcb4edd..463a080 100644
--- a/include/common/aarch32/el3_common_macros.S
+++ b/include/common/aarch32/el3_common_macros.S
@@ -228,7 +228,7 @@
 	 * ---------------------------------------------------------------------
 	 */
 	.if \_init_c_runtime
-#if IMAGE_BL32
+#ifdef IMAGE_BL32
 		/* -----------------------------------------------------------------
 		 * Invalidate the RW memory used by the BL32 (SP_MIN) image. This
 		 * includes the data and NOBITS sections. This is done to
@@ -253,7 +253,7 @@
 		bl	zeromem
 #endif
 
-#if IMAGE_BL1
+#ifdef IMAGE_BL1
 		/* -----------------------------------------------------
 		 * Copy data from ROM to RAM.
 		 * -----------------------------------------------------
diff --git a/include/common/aarch64/el3_common_macros.S b/include/common/aarch64/el3_common_macros.S
index a418911..cbfa6ee 100644
--- a/include/common/aarch64/el3_common_macros.S
+++ b/include/common/aarch64/el3_common_macros.S
@@ -49,7 +49,7 @@
 	msr	sctlr_el3, x0
 	isb
 
-#if IMAGE_BL31
+#ifdef IMAGE_BL31
 	/* ---------------------------------------------------------------------
 	 * Initialise the per-cpu cache pointer to the CPU.
 	 * This is done early to enable crash reporting to have access to crash
@@ -235,7 +235,7 @@
 	 * ---------------------------------------------------------------------
 	 */
 	.if \_init_c_runtime
-#if IMAGE_BL31
+#ifdef IMAGE_BL31
 		/* -------------------------------------------------------------
 		 * Invalidate the RW memory used by the BL31 image. This
 		 * includes the data and NOBITS sections. This is done to
@@ -260,7 +260,7 @@
 		bl	zeromem16
 #endif
 
-#if IMAGE_BL1
+#ifdef IMAGE_BL1
 		ldr	x0, =__DATA_RAM_START__
 		ldr	x1, =__DATA_ROM_START__
 		ldr	x2, =__DATA_SIZE__
diff --git a/include/common/bl_common.h b/include/common/bl_common.h
index 5076dfd..66c20fc 100644
--- a/include/common/bl_common.h
+++ b/include/common/bl_common.h
@@ -170,13 +170,13 @@
 extern uintptr_t __RO_END__;
 #endif
 
-#if IMAGE_BL2
+#if defined(IMAGE_BL2)
 extern uintptr_t __BL2_END__;
-#elif IMAGE_BL2U
+#elif defined(IMAGE_BL2U)
 extern uintptr_t __BL2U_END__;
-#elif IMAGE_BL31
+#elif defined(IMAGE_BL31)
 extern uintptr_t __BL31_END__;
-#elif IMAGE_BL32
+#elif defined(IMAGE_BL32)
 extern uintptr_t __BL32_END__;
 #endif /* IMAGE_BLX */
 
diff --git a/include/lib/cpus/aarch32/cpu_macros.S b/include/lib/cpus/aarch32/cpu_macros.S
index 17dd258..64df236 100644
--- a/include/lib/cpus/aarch32/cpu_macros.S
+++ b/include/lib/cpus/aarch32/cpu_macros.S
@@ -51,11 +51,11 @@
 CPU_MIDR: /* cpu_ops midr */
 	.space  4
 /* Reset fn is needed during reset */
-#if IMAGE_BL1 || IMAGE_BL32
+#if defined(IMAGE_BL1) || defined(IMAGE_BL32)
 CPU_RESET_FUNC: /* cpu_ops reset_func */
 	.space  4
 #endif
-#if IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */
+#ifdef IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */
 CPU_PWR_DWN_OPS: /* cpu_ops power down functions */
 	.space  (4 * CPU_MAX_PWR_DWN_OPS)
 #endif
@@ -117,10 +117,10 @@
 	.align 2
 	.type cpu_ops_\_name, %object
 	.word \_midr
-#if IMAGE_BL1 || IMAGE_BL32
+#if defined(IMAGE_BL1) || defined(IMAGE_BL32)
 	.word \_resetfunc
 #endif
-#if IMAGE_BL32
+#ifdef IMAGE_BL32
 1:
 	/* Insert list of functions */
 	fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
diff --git a/include/lib/cpus/aarch64/cpu_macros.S b/include/lib/cpus/aarch64/cpu_macros.S
index 570ef88..5012877 100644
--- a/include/lib/cpus/aarch64/cpu_macros.S
+++ b/include/lib/cpus/aarch64/cpu_macros.S
@@ -51,15 +51,15 @@
 CPU_MIDR: /* cpu_ops midr */
 	.space  8
 /* Reset fn is needed in BL at reset vector */
-#if IMAGE_BL1 || IMAGE_BL31
+#if defined(IMAGE_BL1) || defined(IMAGE_BL31)
 CPU_RESET_FUNC: /* cpu_ops reset_func */
 	.space  8
 #endif
-#if IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */
+#ifdef IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */
 CPU_PWR_DWN_OPS: /* cpu_ops power down functions */
 	.space  (8 * CPU_MAX_PWR_DWN_OPS)
 #endif
-#if (IMAGE_BL31 && CRASH_REPORTING)
+#if defined(IMAGE_BL31) && CRASH_REPORTING
 CPU_REG_DUMP: /* cpu specific register dump for crash reporting */
 	.space  8
 #endif
@@ -121,10 +121,10 @@
 	.align 3
 	.type cpu_ops_\_name, %object
 	.quad \_midr
-#if IMAGE_BL1 || IMAGE_BL31
+#if defined(IMAGE_BL1) || defined(IMAGE_BL31)
 	.quad \_resetfunc
 #endif
-#if IMAGE_BL31
+#ifdef IMAGE_BL31
 1:
 	/* Insert list of functions */
 	fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
@@ -141,7 +141,7 @@
 	  .endif
 	.endif
 #endif
-#if (IMAGE_BL31 && CRASH_REPORTING)
+#if defined(IMAGE_BL31) && CRASH_REPORTING
 	.quad \_name\()_cpu_reg_dump
 #endif
 	.endm
diff --git a/include/plat/arm/board/common/board_arm_def.h b/include/plat/arm/board/common/board_arm_def.h
index ad82923..dee868f 100644
--- a/include/plat/arm/board/common/board_arm_def.h
+++ b/include/plat/arm/board/common/board_arm_def.h
@@ -39,23 +39,23 @@
  */
 
 /* Size of cacheable stacks */
-#if IMAGE_BL1
+#if defined(IMAGE_BL1)
 #if TRUSTED_BOARD_BOOT
 # define PLATFORM_STACK_SIZE 0x1000
 #else
 # define PLATFORM_STACK_SIZE 0x440
 #endif
-#elif IMAGE_BL2
+#elif defined(IMAGE_BL2)
 # if TRUSTED_BOARD_BOOT
 #  define PLATFORM_STACK_SIZE 0x1000
 # else
 #  define PLATFORM_STACK_SIZE 0x400
 # endif
-#elif IMAGE_BL2U
+#elif defined(IMAGE_BL2U)
 # define PLATFORM_STACK_SIZE 0x200
-#elif IMAGE_BL31
+#elif defined(IMAGE_BL31)
 # define PLATFORM_STACK_SIZE 0x400
-#elif IMAGE_BL32
+#elif defined(IMAGE_BL32)
 # define PLATFORM_STACK_SIZE 0x440
 #endif
 
@@ -73,7 +73,7 @@
  * Optimisation is less important for the other, transient boot images so a
  * common, maximum value is used across these images.
  */
-#if IMAGE_BL31 || IMAGE_BL32
+#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
 # define PLAT_ARM_MMAP_ENTRIES		6
 # define MAX_XLAT_TABLES		4
 #else
diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h
index c167aa2..e878f9e 100644
--- a/include/plat/arm/common/plat_arm.h
+++ b/include/plat/arm/common/plat_arm.h
@@ -64,7 +64,7 @@
 #endif
 );
 
-#if IMAGE_BL31
+#ifdef IMAGE_BL31
 /*
  * Use this macro to instantiate lock before it is used in below
  * arm_lock_xxx() macros