-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
um: Extract load file helper from initrd.c
The file loading support in initrd.c can be re-used for loading devicetrees. Move it out of initrd.c. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Signed-off-by: Richard Weinberger <richard@nod.at>
- Loading branch information
Vincent Whitchurch
authored and
Richard Weinberger
committed
Dec 22, 2021
1 parent
8bb227a
commit 361640b
Showing
4 changed files
with
75 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) | ||
*/ | ||
#include <linux/memblock.h> | ||
#include <os.h> | ||
|
||
#include "um_arch.h" | ||
|
||
static int __init __uml_load_file(const char *filename, void *buf, int size) | ||
{ | ||
int fd, n; | ||
|
||
fd = os_open_file(filename, of_read(OPENFLAGS()), 0); | ||
if (fd < 0) { | ||
printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename, | ||
-fd); | ||
return -1; | ||
} | ||
n = os_read_file(fd, buf, size); | ||
if (n != size) { | ||
printk(KERN_ERR "Read of %d bytes from '%s' failed, " | ||
"err = %d\n", size, | ||
filename, -n); | ||
return -1; | ||
} | ||
|
||
os_close_file(fd); | ||
return 0; | ||
} | ||
|
||
void *uml_load_file(const char *filename, unsigned long long *size) | ||
{ | ||
void *area; | ||
int err; | ||
|
||
*size = 0; | ||
|
||
if (!filename) | ||
return NULL; | ||
|
||
err = os_file_size(filename, size); | ||
if (err) | ||
return NULL; | ||
|
||
if (*size == 0) { | ||
printk(KERN_ERR "\"%s\" is empty\n", filename); | ||
return NULL; | ||
} | ||
|
||
area = memblock_alloc(*size, SMP_CACHE_BYTES); | ||
if (!area) | ||
panic("%s: Failed to allocate %llu bytes\n", __func__, *size); | ||
|
||
if (__uml_load_file(filename, area, *size)) { | ||
memblock_free(area, *size); | ||
return NULL; | ||
} | ||
|
||
return area; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
|
||
#ifndef __UML_ARCH_H__ | ||
#define __UML_ARCH_H__ | ||
|
||
extern void * __init uml_load_file(const char *filename, unsigned long long *size); | ||
|
||
#endif |