FIT: Fix an off by one error when allocating space for the memory node.

The code which calculated how much space we need for the memory node reg
property had an off by one error where it would allocate too much space if
the size of the region fell right on the boundary. This change replaces the
calculation with a more intuitive version which uses the ALIGN_UP macro and
which corrects the error.

BUG=None
TEST=Built and booted on big and verified that the phantom memory region was
no longer present. Booted in circumstances which had previous caused a kernel
panic and saw that the panic no longer happened.
BRANCH=None

Change-Id: I9698243d6c91936458f265a73443c329761c1709
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://chromium-review.googlesource.com/197377
Reviewed-by: Julius Werner <jwerner@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
diff --git a/src/boot/fit.c b/src/boot/fit.c
index 8b51bce..5c46b8f 100644
--- a/src/boot/fit.c
+++ b/src/boot/fit.c
@@ -224,12 +224,12 @@
 	void *data;
 } EntryParams;
 
-static uint64_t max_range_shift(unsigned size_cells)
+static uint64_t max_range(unsigned size_cells)
 {
 	// Split up ranges who's sizes are too large to fit in #size-cells.
 	// The largest value we can store isn't a power of two, so we'll round
 	// down to make the math easier.
-	return size_cells * 32 - 1;
+	return 0x1ULL << (size_cells * 32 - 1);
 }
 
 static void count_entries(uint64_t start, uint64_t end, void *pdata)
@@ -237,8 +237,8 @@
 	EntryParams *params = (EntryParams *)pdata;
 	unsigned *count = (unsigned *)params->data;
 	uint64_t size = end - start;
-	*count += 1;
-	*count += size >> max_range_shift(params->size_cells);
+	uint64_t max_size = max_range(params->size_cells);
+	*count += ALIGN_UP(size, max_size) / max_size;
 }
 
 static void update_mem_property(uint64_t start, uint64_t end, void *pdata)
@@ -247,8 +247,7 @@
 	uint8_t *data = (uint8_t *)params->data;
 	uint64_t size = end - start;
 	while (size) {
-		const uint64_t max_size =
-			0x1ULL << max_range_shift(params->size_cells);
+		const uint64_t max_size = max_range(params->size_cells);
 		const uint32_t range_size = MIN(max_size, size);
 
 		if (params->addr_cells == 2)