From cf9dd1423d2af1d68bedc843ce93c7b89f52d0cc Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Thu, 19 Jul 2018 13:04:15 +0200 Subject: [PATCH] nrhw20: cleanup file access module --- board/nm/nrhw20/fileaccess.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/board/nm/nrhw20/fileaccess.c b/board/nm/nrhw20/fileaccess.c index 13768b032e..f296704637 100644 --- a/board/nm/nrhw20/fileaccess.c +++ b/board/nm/nrhw20/fileaccess.c @@ -1,6 +1,7 @@ #include #include +#define BLOCK_DEVICE "mmc" #define OVERLAY_PART "1:3" int read_file(const char* filename, char *buf, int size) @@ -9,14 +10,12 @@ int read_file(const char* filename, char *buf, int size) loff_t len; int ret; - /* If consoldev is set take this as productive conosle instead of default console */ - if (fs_set_blk_dev("mmc", OVERLAY_PART, FS_TYPE_EXT) != 0) { + if (fs_set_blk_dev(BLOCK_DEVICE, OVERLAY_PART, FS_TYPE_EXT) != 0) { puts("Error, can not set blk device\n"); return -1; } - - /* File does not exist, do not print an error message */ + /* Read at most file size bytes */ if (fs_size(filename, &filesize)) { return -1; } @@ -24,13 +23,12 @@ int read_file(const char* filename, char *buf, int size) if (filesize < size) size = filesize; - /* If consoldev is set take this as productive conosle instead of default console */ - if (fs_set_blk_dev("mmc", OVERLAY_PART, FS_TYPE_EXT) != 0) { + /* For very unclear reasons the block device needs to be set again after the call to fs_size() */ + if (fs_set_blk_dev(BLOCK_DEVICE, OVERLAY_PART, FS_TYPE_EXT) != 0) { puts("Error, can not set blk device\n"); return -1; } - if ((ret = fs_read(filename, (ulong)buf, 0, size, &len))) { printf("Can't read file %s (size %d, len %lld, ret %d)\n", filename, size, len, ret); return -1;