-
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.
Implement device tree support needed for Bamboo emulation
To implement the -kernel, -initrd, and -append options, 4xx board emulation must load the guest kernel as if firmware had loaded it. Where u-boot would be the firmware, we must load the flat device tree into memory and set key fields such as /chosen/bootargs. This patch introduces a dependency on libfdt for flat device tree support. Signed-off-by: Hollis Blanchard <[email protected]> Signed-off-by: Aurelien Jarno <[email protected]> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6064 c046a42c-6fe2-441c-8c8c-71466251a162
- Loading branch information
aurel32
committed
Dec 16, 2008
1 parent
b7da58f
commit f652e6a
Showing
5 changed files
with
203 additions
and
0 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,114 @@ | ||
/* | ||
* Functions to help device tree manipulation using libfdt. | ||
* It also provides functions to read entries from device tree proc | ||
* interface. | ||
* | ||
* Copyright 2008 IBM Corporation. | ||
* Authors: Jerone Young <[email protected]> | ||
* Hollis Blanchard <[email protected]> | ||
* | ||
* This work is licensed under the GNU GPL license version 2 or later. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
|
||
#include "config.h" | ||
#include "qemu-common.h" | ||
#include "sysemu.h" | ||
#include "device_tree.h" | ||
|
||
#include <libfdt.h> | ||
|
||
void *load_device_tree(const char *filename_path, void *load_addr) | ||
{ | ||
int dt_file_size; | ||
int dt_file_load_size; | ||
int new_dt_size; | ||
int ret; | ||
void *dt_file = NULL; | ||
void *fdt; | ||
|
||
dt_file_size = get_image_size(filename_path); | ||
if (dt_file_size < 0) { | ||
printf("Unable to get size of device tree file '%s'\n", | ||
filename_path); | ||
goto fail; | ||
} | ||
|
||
/* First allocate space in qemu for device tree */ | ||
dt_file = qemu_mallocz(dt_file_size); | ||
if (dt_file == NULL) { | ||
printf("Unable to allocate memory in qemu for device tree\n"); | ||
goto fail; | ||
} | ||
|
||
dt_file_load_size = load_image(filename_path, dt_file); | ||
|
||
/* Second we place new copy of 2x size in guest memory | ||
* This give us enough room for manipulation. | ||
*/ | ||
new_dt_size = dt_file_size * 2; | ||
|
||
fdt = load_addr; | ||
ret = fdt_open_into(dt_file, fdt, new_dt_size); | ||
if (ret) { | ||
printf("Unable to copy device tree in memory\n"); | ||
goto fail; | ||
} | ||
|
||
/* Check sanity of device tree */ | ||
if (fdt_check_header(fdt)) { | ||
printf ("Device tree file loaded into memory is invalid: %s\n", | ||
filename_path); | ||
goto fail; | ||
} | ||
/* free qemu memory with old device tree */ | ||
qemu_free(dt_file); | ||
return fdt; | ||
|
||
fail: | ||
qemu_free(dt_file); | ||
return NULL; | ||
} | ||
|
||
int qemu_devtree_setprop(void *fdt, const char *node_path, | ||
const char *property, uint32_t *val_array, int size) | ||
{ | ||
int offset; | ||
|
||
offset = fdt_path_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
|
||
return fdt_setprop(fdt, offset, property, val_array, size); | ||
} | ||
|
||
int qemu_devtree_setprop_cell(void *fdt, const char *node_path, | ||
const char *property, uint32_t val) | ||
{ | ||
int offset; | ||
|
||
offset = fdt_path_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
|
||
return fdt_setprop_cell(fdt, offset, property, val); | ||
} | ||
|
||
int qemu_devtree_setprop_string(void *fdt, const char *node_path, | ||
const char *property, const char *string) | ||
{ | ||
int offset; | ||
|
||
offset = fdt_path_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
|
||
return fdt_setprop_string(fdt, offset, property, string); | ||
} |
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,26 @@ | ||
/* | ||
* Header with function prototypes to help device tree manipulation using | ||
* libfdt. It also provides functions to read entries from device tree proc | ||
* interface. | ||
* | ||
* Copyright 2008 IBM Corporation. | ||
* Authors: Jerone Young <[email protected]> | ||
* Hollis Blanchard <[email protected]> | ||
* | ||
* This work is licensed under the GNU GPL license version 2 or later. | ||
* | ||
*/ | ||
|
||
#ifndef __DEVICE_TREE_H__ | ||
#define __DEVICE_TREE_H__ | ||
|
||
void *load_device_tree(const char *filename_path, void *load_addr); | ||
|
||
int qemu_devtree_setprop(void *fdt, const char *node_path, | ||
const char *property, uint32_t *val_array, int size); | ||
int qemu_devtree_setprop_cell(void *fdt, const char *node_path, | ||
const char *property, uint32_t val); | ||
int qemu_devtree_setprop_string(void *fdt, const char *node_path, | ||
const char *property, const char *string); | ||
|
||
#endif /* __DEVICE_TREE_H__ */ |
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,41 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License, version 2, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright IBM Corp. 2008 | ||
* Authors: Hollis Blanchard <[email protected]> | ||
* | ||
*/ | ||
|
||
#ifndef _LIBFDT_ENV_H | ||
#define _LIBFDT_ENV_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <endian.h> | ||
#include <byteswap.h> | ||
|
||
#if __BYTE_ORDER == __BIG_ENDIAN | ||
#define fdt32_to_cpu(x) (x) | ||
#define cpu_to_fdt32(x) (x) | ||
#define fdt64_to_cpu(x) (x) | ||
#define cpu_to_fdt64(x) (x) | ||
#else | ||
#define fdt32_to_cpu(x) (bswap_32((x))) | ||
#define cpu_to_fdt32(x) (bswap_32((x))) | ||
#define fdt64_to_cpu(x) (bswap_64((x))) | ||
#define cpu_to_fdt64(x) (bswap_64((x))) | ||
#endif | ||
|
||
#endif /* _LIBFDT_ENV_H */ |