nrhw20: cleanup file access module
This commit is contained in:
parent
88720cc579
commit
cf9dd1423d
|
|
@ -1,6 +1,7 @@
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
|
|
||||||
|
#define BLOCK_DEVICE "mmc"
|
||||||
#define OVERLAY_PART "1:3"
|
#define OVERLAY_PART "1:3"
|
||||||
|
|
||||||
int read_file(const char* filename, char *buf, int size)
|
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;
|
loff_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* If consoldev is set take this as productive conosle instead of default console */
|
if (fs_set_blk_dev(BLOCK_DEVICE, OVERLAY_PART, FS_TYPE_EXT) != 0) {
|
||||||
if (fs_set_blk_dev("mmc", OVERLAY_PART, FS_TYPE_EXT) != 0) {
|
|
||||||
puts("Error, can not set blk device\n");
|
puts("Error, can not set blk device\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read at most file size bytes */
|
||||||
/* File does not exist, do not print an error message */
|
|
||||||
if (fs_size(filename, &filesize)) {
|
if (fs_size(filename, &filesize)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -24,13 +23,12 @@ int read_file(const char* filename, char *buf, int size)
|
||||||
if (filesize < size)
|
if (filesize < size)
|
||||||
size = filesize;
|
size = filesize;
|
||||||
|
|
||||||
/* If consoldev is set take this as productive conosle instead of default console */
|
/* For very unclear reasons the block device needs to be set again after the call to fs_size() */
|
||||||
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");
|
puts("Error, can not set blk device\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((ret = fs_read(filename, (ulong)buf, 0, size, &len))) {
|
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);
|
printf("Can't read file %s (size %d, len %lld, ret %d)\n", filename, size, len, ret);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue