cgpt: Support non-standard (smaller) entries table

The standard says that entries table must be at least 16384 bytes. On
some of our devices, the NOR section is only 8 KiB and used to store
both primary and secondary tables. On this device, we can only store 24
entries.

Therefore, this CL adds support for non-standard entry table. It adjusts
the MIN_NUMBER_OF_ENTRIES to 16, and replaces GPT_ENTRIES_SECTORS with
CalculateEntriesSectors.

BUG=chromium:441812
BRANCH=none
TEST=unittest

Change-Id: I6b85b35ce5612c7abb22142f8252bd0d45b676c5
Reviewed-on: https://chromium-review.googlesource.com/234996
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
diff --git a/tests/run_cgpt_tests.sh b/tests/run_cgpt_tests.sh
index 6619a6b..7170eef 100755
--- a/tests/run_cgpt_tests.sh
+++ b/tests/run_cgpt_tests.sh
@@ -291,12 +291,17 @@
 
 # Enable write access again to test boundary in off device storage
 chmod 600 ${DEV}
+# Create a small 8K file to simulate Flash NOR section
+dd if=/dev/zero of=${DEV} bs=8K count=1
 # Drive size is not multiple of 512
 assert_fail $CGPT create -D 511 ${DEV}
 assert_fail $CGPT create -D 513 ${DEV}
 MTD="-D 1024"
 # Create a GPT table for a device of 1024 bytes (2 sectors)
 $CGPT create $MTD ${DEV}
+# Make sure number of entries is reasonable for 8KiB GPT
+X=$($CGPT show -D 1024 -d ${DEV} | grep -c "Number of entries: 24")
+[ "$X" = "2" ] || error
 # This fails because header verification is off due to different drive size
 assert_fail $CGPT show ${DEV}
 # But this passes because we pass in correct drive size
@@ -306,6 +311,7 @@
 # This fails because partition size is over the size of the device
 assert_fail $CGPT add $MTD -b 0 -s 3 -t data ${DEV}
 
+
 echo "Done."
 
 happy "All tests passed."