|
1 | 1 | #include <asm/setup.h> |
2 | 2 | #include <libfdt.h> |
3 | 3 |
|
| 4 | +#if defined(CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND) |
| 5 | +#define do_extend_cmdline 1 |
| 6 | +#else |
| 7 | +#define do_extend_cmdline 0 |
| 8 | +#endif |
| 9 | + |
4 | 10 | static int node_offset(void *fdt, const char *node_path) |
5 | 11 | { |
6 | 12 | int offset = fdt_path_offset(fdt, node_path); |
@@ -36,6 +42,48 @@ static int setprop_cell(void *fdt, const char *node_path, |
36 | 42 | return fdt_setprop_cell(fdt, offset, property, val); |
37 | 43 | } |
38 | 44 |
|
| 45 | +static const void *getprop(const void *fdt, const char *node_path, |
| 46 | + const char *property, int *len) |
| 47 | +{ |
| 48 | + int offset = fdt_path_offset(fdt, node_path); |
| 49 | + |
| 50 | + if (offset == -FDT_ERR_NOTFOUND) |
| 51 | + return NULL; |
| 52 | + |
| 53 | + return fdt_getprop(fdt, offset, property, len); |
| 54 | +} |
| 55 | + |
| 56 | +static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline) |
| 57 | +{ |
| 58 | + char cmdline[COMMAND_LINE_SIZE]; |
| 59 | + const char *fdt_bootargs; |
| 60 | + char *ptr = cmdline; |
| 61 | + int len = 0; |
| 62 | + |
| 63 | + /* copy the fdt command line into the buffer */ |
| 64 | + fdt_bootargs = getprop(fdt, "/chosen", "bootargs", &len); |
| 65 | + if (fdt_bootargs) |
| 66 | + if (len < COMMAND_LINE_SIZE) { |
| 67 | + memcpy(ptr, fdt_bootargs, len); |
| 68 | + /* len is the length of the string |
| 69 | + * including the NULL terminator */ |
| 70 | + ptr += len - 1; |
| 71 | + } |
| 72 | + |
| 73 | + /* and append the ATAG_CMDLINE */ |
| 74 | + if (fdt_cmdline) { |
| 75 | + len = strlen(fdt_cmdline); |
| 76 | + if (ptr - cmdline + len + 2 < COMMAND_LINE_SIZE) { |
| 77 | + *ptr++ = ' '; |
| 78 | + memcpy(ptr, fdt_cmdline, len); |
| 79 | + ptr += len; |
| 80 | + } |
| 81 | + } |
| 82 | + *ptr = '\0'; |
| 83 | + |
| 84 | + setprop_string(fdt, "/chosen", "bootargs", cmdline); |
| 85 | +} |
| 86 | + |
39 | 87 | /* |
40 | 88 | * Convert and fold provided ATAGs into the provided FDT. |
41 | 89 | * |
@@ -72,8 +120,18 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) |
72 | 120 |
|
73 | 121 | for_each_tag(atag, atag_list) { |
74 | 122 | if (atag->hdr.tag == ATAG_CMDLINE) { |
75 | | - setprop_string(fdt, "/chosen", "bootargs", |
76 | | - atag->u.cmdline.cmdline); |
| 123 | + /* Append the ATAGS command line to the device tree |
| 124 | + * command line. |
| 125 | + * NB: This means that if the same parameter is set in |
| 126 | + * the device tree and in the tags, the one from the |
| 127 | + * tags will be chosen. |
| 128 | + */ |
| 129 | + if (do_extend_cmdline) |
| 130 | + merge_fdt_bootargs(fdt, |
| 131 | + atag->u.cmdline.cmdline); |
| 132 | + else |
| 133 | + setprop_string(fdt, "/chosen", "bootargs", |
| 134 | + atag->u.cmdline.cmdline); |
77 | 135 | } else if (atag->hdr.tag == ATAG_MEM) { |
78 | 136 | if (memcount >= sizeof(mem_reg_property)/4) |
79 | 137 | continue; |
|
0 commit comments