Refine image size calculation.

The image size is the expanded space taken in memory rather than just
the binary size. This is the value that should be used in the image
header when conforming the the Linux header for aarch64.

Change-Id: Icbba83b466ea311a72862104878b1a4b50ec38ce
diff --git a/build/image/image.ld b/build/image/image.ld
index 427ec9c..4686261 100644
--- a/build/image/image.ld
+++ b/build/image/image.ld
@@ -146,6 +146,8 @@
 	.dynamic : {
 		*(.dynamic.*)
 	}
+	/* Everything beyond this point will not be included in the binary. */
+	bin_end = .;
 	/* The entry point code assumes that .bss is 16-byte aligned. */
 	. = ALIGN(16);
 	bss_begin = .;
@@ -178,11 +180,15 @@
 
 	/* Note the first page not used in the image. */
 	. = ALIGN(4096);
-	bin_end = .;
+	image_end = .;
 
 	/*
-	 * Note the size of the image. This includes everything up to the .bss
-	 * as that is initialized to zero by the entry code.
+	 * Calculate sizes of the the binary file and image loaded into memory
+	 * as well as the text, read-only and read-write data sections.
 	 */
-	image_size = ABSOLUTE(bss_begin - ORIGIN_ADDRESS);
+	bin_size = ABSOLUTE(bin_end - ORIGIN_ADDRESS);
+	image_size = ABSOLUTE(image_end - ORIGIN_ADDRESS);
+	text_size = ABSOLUTE(text_end - text_begin);
+	rodata_size = ABSOLUTE(rodata_end - rodata_begin);
+	data_size = ABSOLUTE(data_end - data_begin);
 }
diff --git a/inc/hf/layout.h b/inc/hf/layout.h
index 7345fb0..4193abf 100644
--- a/inc/hf/layout.h
+++ b/inc/hf/layout.h
@@ -33,6 +33,6 @@
 paddr_t layout_fdt_begin(void);
 paddr_t layout_fdt_end(void);
 
-paddr_t layout_bin_end(void);
+paddr_t layout_image_end(void);
 
 paddr_t layout_primary_begin(void);
diff --git a/src/layout.c b/src/layout.c
index e53361b..5414fe4 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -121,11 +121,11 @@
 /**
  * Get the address the loaded image ends at.
  */
-paddr_t layout_bin_end(void)
+paddr_t layout_image_end(void)
 {
-	extern uint8_t bin_end[];
+	extern uint8_t image_end[];
 
-	return pa_init((uintpaddr_t)bin_end);
+	return pa_init((uintpaddr_t)image_end);
 }
 
 /**
@@ -136,7 +136,7 @@
 paddr_t layout_primary_begin(void)
 {
 	/* TODO: This is a hack. We must read the alignment from the binary. */
-	paddr_t bin_end = layout_bin_end();
+	paddr_t image_end = layout_image_end();
 
-	return pa_init(align_up(pa_addr(bin_end), 0x80000));
+	return pa_init(align_up(pa_addr(image_end), 0x80000));
 }
diff --git a/src/layout_fake.c b/src/layout_fake.c
index 18e090b..542f92a 100644
--- a/src/layout_fake.c
+++ b/src/layout_fake.c
@@ -46,7 +46,7 @@
 	return pa_init(500);
 }
 
-paddr_t layout_bin_end(void)
+paddr_t layout_image_end(void)
 {
 	return pa_init(600);
 }