diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/environment.c | 9 | ||||
-rw-r--r-- | common/memtest.c | 39 | ||||
-rw-r--r-- | common/startup.c | 52 |
3 files changed, 80 insertions, 20 deletions
diff --git a/common/environment.c b/common/environment.c index 0edf34b661..56a030eda0 100644 --- a/common/environment.c +++ b/common/environment.c @@ -256,9 +256,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) struct action_data data = {}; void *buf = NULL, *wbuf; struct envfs_entry *env; + const char *defenv_path = default_environment_path_get(); if (!filename) - filename = default_environment_path_get(); + filename = defenv_path; + if (!filename) + return -ENOENT; if (!dirname) dirname = "/env"; @@ -365,7 +368,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags) ret = 0; #ifdef CONFIG_NVVAR - if (!strcmp(filename, default_environment_path_get())) + if (defenv_path && !strcmp(filename, defenv_path)) nv_var_set_clean(); #endif out: @@ -558,6 +561,8 @@ int envfs_load(const char *filename, const char *dir, unsigned flags) if (!filename) filename = default_environment_path_get(); + if (!filename) + return -ENOENT; if (!dir) dir = "/env"; diff --git a/common/memtest.c b/common/memtest.c index 0fc2046758..44ddedd3d4 100644 --- a/common/memtest.c +++ b/common/memtest.c @@ -131,8 +131,8 @@ void mem_test_release_regions(struct list_head *list) /* * Ensure to leave with a cached on non used sdram regions. */ - remap_range((void *)r->r->start, r->r->end - - r->r->start + 1, MAP_DEFAULT); + remap_range((void *)r->r->start, resource_size(r->r), + MAP_DEFAULT); release_sdram_region(r->r); free(r); @@ -160,24 +160,29 @@ static void mem_test_report_failure(const char *failure_description, resource_size_t actual_value, volatile resource_size_t *address) { + /* + * expected_value and actual_value below are not really + * pointers, but we want them to be printed exactly the same + * as pointers would, so we use %pa regardless + */ printf("FAILURE (%s): " - "expected 0x%08x, actual 0x%08x at address 0x%08x.\n", - failure_description, expected_value, actual_value, - (resource_size_t)address); + "expected %pa, actual %pa at address %pa.\n", + failure_description, &expected_value, &actual_value, + &address); } int mem_test_bus_integrity(resource_size_t _start, resource_size_t _end) { - static const resource_size_t bitpattern[] = { - 0x00000001, /* single bit */ - 0x00000003, /* two adjacent bits */ - 0x00000007, /* three adjacent bits */ - 0x0000000F, /* four adjacent bits */ - 0x00000005, /* two non-adjacent bits */ - 0x00000015, /* three non-adjacent bits */ - 0x00000055, /* four non-adjacent bits */ - 0xAAAAAAAA, /* alternating 1/0 */ + static const uint64_t bitpattern[] = { + 0x0000000000000001ULL, /* single bit */ + 0x0000000000000003ULL, /* two adjacent bits */ + 0x0000000000000007ULL, /* three adjacent bits */ + 0x000000000000000FULL, /* four adjacent bits */ + 0x0000000000000005ULL, /* two non-adjacent bits */ + 0x0000000000000015ULL, /* three non-adjacent bits */ + 0x0000000000000055ULL, /* four non-adjacent bits */ + 0xAAAAAAAAAAAAAAAAULL, /* alternating 1/0 */ }; volatile resource_size_t *start, *dummy, num_words, val, readback, offset, @@ -217,7 +222,7 @@ int mem_test_bus_integrity(resource_size_t _start, * pattern and ~pattern). */ for (i = 0; i < ARRAY_SIZE(bitpattern); i++) { - val = bitpattern[i]; + val = (resource_size_t)bitpattern[i]; for (; val != 0; val <<= 1) { *start = val; @@ -282,8 +287,8 @@ int mem_test_bus_integrity(resource_size_t _start, * 01ffffff is perfect. */ - pattern = 0xAAAAAAAA; - anti_pattern = 0x55555555; + pattern = (resource_size_t)0xAAAAAAAAAAAAAAAAULL; + anti_pattern = (resource_size_t)0x5555555555555555ULL; /* * Write the default pattern at each of the diff --git a/common/startup.c b/common/startup.c index 8553849cb3..832d3262fe 100644 --- a/common/startup.c +++ b/common/startup.c @@ -73,16 +73,66 @@ fs_initcall(mount_root); #endif #ifdef CONFIG_ENV_HANDLING +static int check_overlap(const char *path) +{ + struct cdev *cenv, *cdisk, *cpart; + const char *name; + + name = devpath_to_name(path); + + if (name == path) + /* + * no /dev/ in front, so *path is some file. No need to + * check further. + */ + return 0; + + cenv = cdev_by_name(name); + if (!cenv) + return -EINVAL; + + cdisk = cenv->master; + + if (!cdisk) + return 0; + + list_for_each_entry(cpart, &cdisk->partitions, partition_entry) { + if (cpart == cenv) + continue; + + if (lregion_overlap(cpart->offset, cpart->size, + cenv->offset, cenv->size)) + goto conflict; + } + + return 0; + +conflict: + pr_err("Environment partition (0x%08llx-0x%08llx) " + "overlaps with partition %s (0x%08llx-0x%08llx), not using it\n", + cenv->offset, cenv->offset + cenv->offset + cenv->size - 1, + cpart->name, + cpart->offset, cpart->offset + cpart->offset + cpart->size - 1); + + return -EINVAL; +} + static int load_environment(void) { const char *default_environment_path; + int ret; default_environment_path = default_environment_path_get(); if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT)) defaultenv_load("/env", 0); - envfs_load(default_environment_path, "/env", 0); + ret = check_overlap(default_environment_path); + if (ret) + default_environment_path_set(NULL); + else + envfs_load(default_environment_path, "/env", 0); + nvvar_load(); return 0; |