-
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.
ARM: zImage: allow supplementing appended DTB with traditional ATAG data
Some old bootloaders can't be updated to a device tree capable one, yet they provide ATAGs with memory configuration, the ramdisk address, the kernel cmdline string, etc. To allow a device tree enabled kernel to be used with such bootloaders, it is necessary to convert those ATAGs into FDT properties and fold them into the DTB appended to zImage. Currently the following ATAGs are converted: ATAG_CMDLINE ATAG_MEM ATAG_INITRD2 If the corresponding information already exists in the appended DTB, it is replaced, otherwise the required node is created to hold it. The code looks for ATAGs at the location pointed by the value of r2 upon entry into the zImage code. If no ATAGs are found there, an attempt at finding ATAGs at the typical 0x100 offset from start of RAM is made. Otherwise the DTB is left unchanged. Thisstarted from an older patch from John Bonesio <bones@secretlab.ca>, with contributions from David Brown <davidb@codeaurora.org>. Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org> Tested-by: Shawn Guo <shawn.guo@linaro.org> Tested-by: Dave Martin <dave.martin@linaro.org> Tested-by: Thomas Abraham <thomas.abraham@linaro.org>
- Loading branch information
Nicolas Pitre
authored and
Nicolas Pitre
committed
Sep 14, 2011
1 parent
df4879f
commit b90b9a3
Showing
6 changed files
with
184 additions
and
2 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
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,97 @@ | ||
#include <asm/setup.h> | ||
#include <libfdt.h> | ||
|
||
static int node_offset(void *fdt, const char *node_path) | ||
{ | ||
int offset = fdt_path_offset(fdt, node_path); | ||
if (offset == -FDT_ERR_NOTFOUND) | ||
offset = fdt_add_subnode(fdt, 0, node_path); | ||
return offset; | ||
} | ||
|
||
static int setprop(void *fdt, const char *node_path, const char *property, | ||
uint32_t *val_array, int size) | ||
{ | ||
int offset = node_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
return fdt_setprop(fdt, offset, property, val_array, size); | ||
} | ||
|
||
static int setprop_string(void *fdt, const char *node_path, | ||
const char *property, const char *string) | ||
{ | ||
int offset = node_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
return fdt_setprop_string(fdt, offset, property, string); | ||
} | ||
|
||
static int setprop_cell(void *fdt, const char *node_path, | ||
const char *property, uint32_t val) | ||
{ | ||
int offset = node_offset(fdt, node_path); | ||
if (offset < 0) | ||
return offset; | ||
return fdt_setprop_cell(fdt, offset, property, val); | ||
} | ||
|
||
/* | ||
* Convert and fold provided ATAGs into the provided FDT. | ||
* | ||
* REturn values: | ||
* = 0 -> pretend success | ||
* = 1 -> bad ATAG (may retry with another possible ATAG pointer) | ||
* < 0 -> error from libfdt | ||
*/ | ||
int atags_to_fdt(void *atag_list, void *fdt, int total_space) | ||
{ | ||
struct tag *atag = atag_list; | ||
uint32_t mem_reg_property[2 * NR_BANKS]; | ||
int memcount = 0; | ||
int ret; | ||
|
||
/* make sure we've got an aligned pointer */ | ||
if ((u32)atag_list & 0x3) | ||
return 1; | ||
|
||
/* if we get a DTB here we're done already */ | ||
if (*(u32 *)atag_list == fdt32_to_cpu(FDT_MAGIC)) | ||
return 0; | ||
|
||
/* validate the ATAG */ | ||
if (atag->hdr.tag != ATAG_CORE || | ||
(atag->hdr.size != tag_size(tag_core) && | ||
atag->hdr.size != 2)) | ||
return 1; | ||
|
||
/* let's give it all the room it could need */ | ||
ret = fdt_open_into(fdt, fdt, total_space); | ||
if (ret < 0) | ||
return ret; | ||
|
||
for_each_tag(atag, atag_list) { | ||
if (atag->hdr.tag == ATAG_CMDLINE) { | ||
setprop_string(fdt, "/chosen", "bootargs", | ||
atag->u.cmdline.cmdline); | ||
} else if (atag->hdr.tag == ATAG_MEM) { | ||
if (memcount >= sizeof(mem_reg_property)/4) | ||
continue; | ||
mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.start); | ||
mem_reg_property[memcount++] = cpu_to_fdt32(atag->u.mem.size); | ||
} else if (atag->hdr.tag == ATAG_INITRD2) { | ||
uint32_t initrd_start, initrd_size; | ||
initrd_start = atag->u.initrd.start; | ||
initrd_size = atag->u.initrd.size; | ||
setprop_cell(fdt, "/chosen", "linux,initrd-start", | ||
initrd_start); | ||
setprop_cell(fdt, "/chosen", "linux,initrd-end", | ||
initrd_start + initrd_size); | ||
} | ||
} | ||
|
||
if (memcount) | ||
setprop(fdt, "/memory", "reg", mem_reg_property, 4*memcount); | ||
|
||
return fdt_pack(fdt); | ||
} |
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,15 @@ | ||
#ifndef _ARM_LIBFDT_ENV_H | ||
#define _ARM_LIBFDT_ENV_H | ||
|
||
#include <linux/types.h> | ||
#include <linux/string.h> | ||
#include <asm/byteorder.h> | ||
|
||
#define fdt16_to_cpu(x) be16_to_cpu(x) | ||
#define cpu_to_fdt16(x) cpu_to_be16(x) | ||
#define fdt32_to_cpu(x) be32_to_cpu(x) | ||
#define cpu_to_fdt32(x) cpu_to_be32(x) | ||
#define fdt64_to_cpu(x) be64_to_cpu(x) | ||
#define cpu_to_fdt64(x) cpu_to_be64(x) | ||
|
||
#endif |