diff --git a/src/hal/ambarella_test.c b/src/hal/ambarella_test.c index d8c6518..63ca1c7 100644 --- a/src/hal/ambarella_test.c +++ b/src/hal/ambarella_test.c @@ -8,6 +8,7 @@ #include #include "hal/ambarella.h" +#include "hal/common.h" int chip_generation; char chip_name[128]; @@ -93,6 +94,13 @@ int main() { unlink(path); CHECK(!ambarella_iavmem_from_dt(path, &start, &size)); + /* ram.c rounds the total up to a power of two; on this board the total + * already is one and must stay 512M, not become 1024M. */ + CHECK(rounded_num((0x07800000u + 0x18800000u) / 1024 / 1024) == 512); + CHECK(rounded_num(112) == 128); /* a MemTotal of 114940 kB */ + CHECK(rounded_num(513) == 1024); + CHECK(rounded_num(1) == 1); + if (failures) return EXIT_FAILURE; puts("ambarella_test: all cases passed"); diff --git a/src/hal/common.c b/src/hal/common.c index b449d94..20fa94e 100644 --- a/src/hal/common.c +++ b/src/hal/common.c @@ -268,6 +268,9 @@ unsigned long kernel_mem() { } uint32_t rounded_num(uint32_t n) { + if (n && !(n & (n - 1))) + return n; + int i; for (i = 0; n; i++) { n /= 2;