Mukesh Ojha | 82911f8 | 2018-04-30 16:45:07 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | /* Supporting function of UpdateDeviceTree() |
| 30 | * Function adds memory map entries to the device tree binary |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 31 | * dev_tree_add_mem_info() is called at every time when memory type matches |
| 32 | * conditions */ |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 33 | |
| 34 | #include "UpdateDeviceTree.h" |
lijuang | f0bbcad | 2017-08-16 16:59:18 +0800 | [diff] [blame] | 35 | #include "AutoGen.h" |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 36 | #include <Library/UpdateDeviceTree.h> |
| 37 | #include <Protocol/EFIChipInfoTypes.h> |
| 38 | #include <Protocol/EFIRng.h> |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 39 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 40 | #define DTB_PAD_SIZE 2048 |
| 41 | #define NUM_SPLASHMEM_PROP_ELEM 4 |
Mayank Grover | abfc353 | 2018-05-03 14:52:32 +0530 | [diff] [blame] | 42 | #define DEFAULT_CELL_SIZE 2 |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 43 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 44 | STATIC struct FstabNode FstabTable = {"/firmware/android/fstab", "dev", |
| 45 | "/soc/"}; |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 46 | STATIC struct DisplaySplashBufferInfo splashBuf; |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 47 | STATIC UINTN splashBufSize = sizeof (splashBuf); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 48 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 49 | STATIC VOID |
| 50 | PrintSplashMemInfo (CONST CHAR8 *data, INT32 datalen) |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 51 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 52 | UINT32 i, val[NUM_SPLASHMEM_PROP_ELEM] = {0}; |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 53 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 54 | for (i = 0; (i < NUM_SPLASHMEM_PROP_ELEM) && datalen; i++) { |
| 55 | memcpy (&val[i], data, sizeof (UINT32)); |
| 56 | val[i] = fdt32_to_cpu (val[i]); |
| 57 | data += sizeof (UINT32); |
| 58 | datalen -= sizeof (UINT32); |
| 59 | } |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 60 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 61 | DEBUG ((EFI_D_VERBOSE, "reg = <0x%08x 0x%08x 0x%08x 0x%08x>\n", val[0], |
| 62 | val[1], val[2], val[3])); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 65 | STATIC EFI_STATUS |
| 66 | GetKaslrSeed (UINT64 *KaslrSeed) |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 67 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 68 | EFI_QCOM_RNG_PROTOCOL *RngIf; |
| 69 | EFI_STATUS Status; |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 70 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 71 | Status = gBS->LocateProtocol (&gQcomRngProtocolGuid, NULL, (VOID **)&RngIf); |
| 72 | if (Status != EFI_SUCCESS) { |
| 73 | DEBUG ((EFI_D_VERBOSE, |
| 74 | "Error locating PRNG protocol. Fail to generate Kaslr seed:%r\n", |
| 75 | Status)); |
| 76 | return Status; |
| 77 | } |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 78 | |
Jeevan Shriram | f039efb | 2018-08-24 12:42:23 -0700 | [diff] [blame^] | 79 | Status = RngIf->GetRNG (RngIf, |
| 80 | &gEfiRNGAlgRawGuid, |
| 81 | sizeof (UINTN), |
| 82 | (UINT8 *)KaslrSeed); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 83 | if (Status != EFI_SUCCESS) { |
| 84 | DEBUG ((EFI_D_VERBOSE, |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 85 | "Error getting PRNG random number. Fail to generate Kaslr seed:%r\n", |
| 86 | Status)); |
| 87 | *KaslrSeed = 0; |
| 88 | return Status; |
| 89 | } |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 90 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 91 | return Status; |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 94 | STATIC EFI_STATUS |
| 95 | UpdateSplashMemInfo (VOID *fdt) |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 96 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 97 | EFI_STATUS Status; |
| 98 | CONST struct fdt_property *Prop = NULL; |
| 99 | INT32 PropLen = 0; |
| 100 | INT32 ret = 0; |
| 101 | UINT32 offset; |
| 102 | CHAR8 *tmp = NULL; |
| 103 | UINT32 CONST SplashMemPropSize = NUM_SPLASHMEM_PROP_ELEM * sizeof (UINT32); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 104 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 105 | Status = |
| 106 | gRT->GetVariable ((CHAR16 *)L"DisplaySplashBufferInfo", |
| 107 | &gQcomTokenSpaceGuid, NULL, &splashBufSize, &splashBuf); |
| 108 | if (Status != EFI_SUCCESS) { |
| 109 | DEBUG ((EFI_D_ERROR, "Unable to get splash buffer info, %r\n", Status)); |
| 110 | goto error; |
| 111 | } |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 112 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 113 | DEBUG ((EFI_D_VERBOSE, "Version=%d\nAddr=0x%08x\nSize=0x%08x\n", |
| 114 | splashBuf.uVersion, splashBuf.uFrameAddr, splashBuf.uFrameSize)); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 115 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 116 | /* Get offset of the splash memory reservation node */ |
| 117 | ret = fdt_path_offset (fdt, "/reserved-memory/splash_region"); |
| 118 | if (ret < 0) { |
| 119 | DEBUG ((EFI_D_ERROR, "ERROR: Could not get splash memory region node\n")); |
| 120 | return EFI_NOT_FOUND; |
| 121 | } |
| 122 | offset = ret; |
| 123 | DEBUG ((EFI_D_VERBOSE, "FB mem node name: %a\n", |
| 124 | fdt_get_name (fdt, offset, NULL))); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 125 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 126 | /* Get the property that specifies the splash memory details */ |
| 127 | Prop = fdt_get_property (fdt, offset, "reg", &PropLen); |
| 128 | if (!Prop) { |
| 129 | DEBUG ((EFI_D_ERROR, "ERROR: Could not find the splash reg property\n")); |
| 130 | return EFI_NOT_FOUND; |
| 131 | } |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 132 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 133 | /* |
| 134 | * The format of the "reg" field is as follows: |
| 135 | * <0x0 FBAddress 0x0 FBSize> |
| 136 | * The expected size of this property is 4 * sizeof(UINT32) |
| 137 | */ |
| 138 | if (PropLen != SplashMemPropSize) { |
| 139 | DEBUG ( |
| 140 | (EFI_D_ERROR, |
| 141 | "ERROR: splash mem reservation node size. Expected: %d, Actual: %d\n", |
| 142 | SplashMemPropSize, PropLen)); |
| 143 | return EFI_BAD_BUFFER_SIZE; |
| 144 | } |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 145 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 146 | DEBUG ((EFI_D_VERBOSE, "Splash memory region before updating:\n")); |
| 147 | PrintSplashMemInfo (Prop->data, PropLen); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 148 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 149 | /* First, update the FBAddress */ |
| 150 | if (CHECK_ADD64 ((UINT64)Prop->data, sizeof (UINT32))) { |
Mukesh Ojha | 82911f8 | 2018-04-30 16:45:07 +0530 | [diff] [blame] | 151 | DEBUG ((EFI_D_ERROR, "ERROR: integer Overflow while updating FBAddress")); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 152 | return EFI_BAD_BUFFER_SIZE; |
| 153 | } |
| 154 | tmp = (CHAR8 *)Prop->data + sizeof (UINT32); |
| 155 | splashBuf.uFrameAddr = cpu_to_fdt32 (splashBuf.uFrameAddr); |
| 156 | memcpy (tmp, &splashBuf.uFrameAddr, sizeof (UINT32)); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 157 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 158 | /* Next, update the FBSize */ |
| 159 | if (CHECK_ADD64 ((UINT64)tmp, (2 * sizeof (UINT32)))) { |
Mukesh Ojha | 82911f8 | 2018-04-30 16:45:07 +0530 | [diff] [blame] | 160 | DEBUG ((EFI_D_ERROR, "ERROR: integer Overflow while updating FBSize")); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 161 | return EFI_BAD_BUFFER_SIZE; |
| 162 | } |
| 163 | tmp += (2 * sizeof (UINT32)); |
| 164 | splashBuf.uFrameSize = cpu_to_fdt32 (splashBuf.uFrameSize); |
| 165 | memcpy (tmp, &splashBuf.uFrameSize, sizeof (UINT32)); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 166 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 167 | /* Update the property value in place */ |
| 168 | ret = fdt_setprop_inplace (fdt, offset, "reg", Prop->data, PropLen); |
| 169 | if (ret < 0) { |
| 170 | DEBUG ((EFI_D_ERROR, "ERROR: Could not update splash mem info\n")); |
| 171 | return EFI_NO_MAPPING; |
| 172 | } |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 173 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 174 | DEBUG ((EFI_D_VERBOSE, "Splash memory region after updating:\n")); |
| 175 | PrintSplashMemInfo (Prop->data, PropLen); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 176 | error: |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 177 | return Status; |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 178 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 179 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 180 | UINT32 |
| 181 | fdt_check_header_ext (VOID *fdt) |
Runmin Wang | e74d804 | 2016-07-19 18:09:07 -0700 | [diff] [blame] | 182 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 183 | UINT64 fdt_start, fdt_end; |
| 184 | UINT32 sum; |
| 185 | fdt_start = (UINT64)fdt; |
Runmin Wang | e74d804 | 2016-07-19 18:09:07 -0700 | [diff] [blame] | 186 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 187 | if (fdt_start + fdt_totalsize (fdt) <= fdt_start) { |
| 188 | return FDT_ERR_BADOFFSET; |
| 189 | } |
| 190 | fdt_end = fdt_start + fdt_totalsize (fdt); |
Runmin Wang | e74d804 | 2016-07-19 18:09:07 -0700 | [diff] [blame] | 191 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 192 | if (!(sum = ADD_OF (fdt_off_dt_struct (fdt), fdt_size_dt_struct (fdt)))) { |
| 193 | return FDT_ERR_BADOFFSET; |
| 194 | } else { |
| 195 | if (CHECK_ADD64 (fdt_start, sum)) |
| 196 | return FDT_ERR_BADOFFSET; |
| 197 | else if (fdt_start + sum > fdt_end) |
| 198 | return FDT_ERR_BADOFFSET; |
| 199 | } |
| 200 | if (!(sum = ADD_OF (fdt_off_dt_strings (fdt), fdt_size_dt_strings (fdt)))) { |
| 201 | return FDT_ERR_BADOFFSET; |
| 202 | } else { |
| 203 | if (CHECK_ADD64 (fdt_start, sum)) |
| 204 | return FDT_ERR_BADOFFSET; |
| 205 | else if (fdt_start + sum > fdt_end) |
| 206 | return FDT_ERR_BADOFFSET; |
| 207 | } |
| 208 | if (fdt_start + fdt_off_mem_rsvmap (fdt) > fdt_end) |
| 209 | return FDT_ERR_BADOFFSET; |
| 210 | return 0; |
Runmin Wang | e74d804 | 2016-07-19 18:09:07 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 213 | STATIC |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 214 | VOID |
| 215 | UpdateGranuleInfo (VOID *fdt) |
| 216 | { |
| 217 | EFI_STATUS Status = EFI_SUCCESS; |
Bhanuprakash Modem | 7ee0312 | 2018-06-12 19:47:36 +0530 | [diff] [blame] | 218 | INT32 GranuleNodeOffset; |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 219 | UINT32 GranuleSize; |
| 220 | INT32 Ret; |
| 221 | |
Bhanuprakash Modem | 7ee0312 | 2018-06-12 19:47:36 +0530 | [diff] [blame] | 222 | GranuleNodeOffset = fdt_path_offset (fdt, "/mem-offline"); |
| 223 | if (GranuleNodeOffset < 0) { |
| 224 | DEBUG ((EFI_D_ERROR, "WARNING: Could not find mem-offline node.\n")); |
| 225 | return; |
| 226 | } |
| 227 | |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 228 | Status = GetGranuleSize (&GranuleSize); |
| 229 | if (EFI_ERROR (Status)) { |
| 230 | DEBUG ((EFI_D_ERROR, |
| 231 | "Update Granule Size failed!!! Status = %r\r\n", |
| 232 | Status)); |
| 233 | return; |
| 234 | } |
| 235 | |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 236 | Ret = fdt_setprop_u32 (fdt, GranuleNodeOffset, "granule", GranuleSize); |
| 237 | if (Ret) { |
| 238 | DEBUG ((EFI_D_ERROR, "WARNING: Granule size update failed.\n")); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | STATIC |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 243 | EFI_STATUS |
Mayank Grover | abfc353 | 2018-05-03 14:52:32 +0530 | [diff] [blame] | 244 | QueryMemoryCellSize (IN VOID *Fdt, OUT UINT32 *MemoryCellLen) |
| 245 | { |
| 246 | INT32 RootOffset; |
| 247 | INT32 PropLen; |
| 248 | UINT32 AddrCellSize = 0; |
| 249 | UINT32 SizeCellSize = 0; |
| 250 | UINT32 *Prop = NULL; |
| 251 | |
| 252 | RootOffset = fdt_path_offset (Fdt, "/"); |
| 253 | if (RootOffset < 0) { |
| 254 | DEBUG ((EFI_D_ERROR, "Error finding root offset\n")); |
| 255 | return EFI_NOT_FOUND; |
| 256 | } |
| 257 | |
| 258 | /* Find address-cells size */ |
| 259 | Prop = (UINT32 *) fdt_getprop (Fdt, RootOffset, "#address-cells", &PropLen); |
| 260 | if (Prop && |
| 261 | PropLen > 0) { |
| 262 | AddrCellSize = fdt32_to_cpu (*Prop); |
| 263 | } else { |
| 264 | DEBUG ((EFI_D_ERROR, "Error finding #address-cells property\n")); |
| 265 | return EFI_NOT_FOUND; |
| 266 | } |
| 267 | |
| 268 | /* Find size-cells size */ |
| 269 | Prop =(UINT32 *) fdt_getprop (Fdt, RootOffset, "#size-cells", &PropLen); |
| 270 | if (Prop && |
| 271 | PropLen > 0) { |
| 272 | SizeCellSize = fdt32_to_cpu (*Prop); |
| 273 | } else { |
| 274 | DEBUG ((EFI_D_ERROR, "Error finding #size-cells property\n")); |
| 275 | return EFI_NOT_FOUND; |
| 276 | } |
| 277 | |
| 278 | if (AddrCellSize > DEFAULT_CELL_SIZE || |
| 279 | SizeCellSize > DEFAULT_CELL_SIZE || |
| 280 | SizeCellSize == 0 || |
| 281 | AddrCellSize == 0) { |
| 282 | DEBUG ((EFI_D_ERROR, "Error unsupported cell size value: #address-cell %d" \ |
| 283 | "#size-cell\n", AddrCellSize, SizeCellSize)); |
| 284 | return EFI_INVALID_PARAMETER; |
| 285 | } |
| 286 | |
| 287 | /* Make sure memory cell size and address cell size are same */ |
| 288 | if (AddrCellSize == SizeCellSize) { |
| 289 | *MemoryCellLen = AddrCellSize; |
| 290 | } else { |
| 291 | DEBUG ((EFI_D_ERROR, "Mismatch memory address cell and size cell size\n")); |
| 292 | return EFI_INVALID_PARAMETER; |
| 293 | } |
| 294 | |
| 295 | return EFI_SUCCESS; |
| 296 | } |
| 297 | |
| 298 | STATIC |
| 299 | EFI_STATUS |
| 300 | AddMemMap (VOID *Fdt, UINT32 MemNodeOffset, BOOLEAN BootWith32Bit) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 301 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 302 | EFI_STATUS Status = EFI_NOT_FOUND; |
| 303 | INT32 ret = 0; |
| 304 | RamPartitionEntry *RamPartitions = NULL; |
| 305 | UINT32 NumPartitions = 0; |
| 306 | UINT32 i = 0; |
Mayank Grover | abfc353 | 2018-05-03 14:52:32 +0530 | [diff] [blame] | 307 | UINT32 MemoryCellLen = 0; |
| 308 | |
| 309 | Status = QueryMemoryCellSize (Fdt, &MemoryCellLen); |
| 310 | if (EFI_ERROR (Status)) { |
| 311 | DEBUG ((EFI_D_ERROR, "ERROR: Not a valid memory node found!\n")); |
| 312 | return Status; |
| 313 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 314 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 315 | Status = GetRamPartitions (&RamPartitions, &NumPartitions); |
| 316 | if (EFI_ERROR (Status)) { |
| 317 | DEBUG ((EFI_D_ERROR, "Error returned from GetRamPartitions %r\n", Status)); |
| 318 | return Status; |
| 319 | } |
| 320 | if (!RamPartitions) { |
| 321 | DEBUG ((EFI_D_ERROR, "RamPartitions is NULL\n")); |
| 322 | return EFI_NOT_FOUND; |
| 323 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 324 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 325 | DEBUG ((EFI_D_INFO, "RAM Partitions\r\n")); |
| 326 | for (i = 0; i < NumPartitions; i++) { |
| 327 | DEBUG ((EFI_D_INFO, "Add Base: 0x%016lx Available Length: 0x%016lx \n", |
| 328 | RamPartitions[i].Base, RamPartitions[i].AvailableLength)); |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 329 | |
Mayank Grover | abfc353 | 2018-05-03 14:52:32 +0530 | [diff] [blame] | 330 | if (MemoryCellLen == 1) { |
| 331 | ret = dev_tree_add_mem_info (Fdt, MemNodeOffset, RamPartitions[i].Base, |
| 332 | RamPartitions[i].AvailableLength); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 333 | } else { |
Mayank Grover | abfc353 | 2018-05-03 14:52:32 +0530 | [diff] [blame] | 334 | ret = dev_tree_add_mem_infoV64 (Fdt, MemNodeOffset, |
| 335 | RamPartitions[i].Base, |
| 336 | RamPartitions[i].AvailableLength); |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 339 | if (ret) { |
| 340 | DEBUG ((EFI_D_ERROR, "Add Base: 0x%016lx Length: 0x%016lx Fail\n", |
| 341 | RamPartitions[i].Base, RamPartitions[i].AvailableLength)); |
| 342 | } |
| 343 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 344 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 345 | FreePool (RamPartitions); |
| 346 | RamPartitions = NULL; |
| 347 | |
| 348 | return EFI_SUCCESS; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Supporting function of UpdateDeviceTree() |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 352 | * Function first gets the RAM partition table, then passes the pointer to |
| 353 | * AddMemMap() */ |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 354 | STATIC |
| 355 | EFI_STATUS |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 356 | target_dev_tree_mem (VOID *fdt, UINT32 MemNodeOffset, BOOLEAN BootWith32Bit) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 357 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 358 | EFI_STATUS Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 359 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 360 | /* Get Available memory from partition table */ |
| 361 | Status = AddMemMap (fdt, MemNodeOffset, BootWith32Bit); |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 362 | if (EFI_ERROR (Status)) { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 363 | DEBUG ((EFI_D_ERROR, |
| 364 | "Invalid memory configuration, check memory partition table: %r\n", |
| 365 | Status)); |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 366 | goto out; |
| 367 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 368 | |
Jeevan Shriram | 067bbb5 | 2018-05-08 17:48:47 -0700 | [diff] [blame] | 369 | UpdateGranuleInfo (fdt); |
| 370 | |
| 371 | out: |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 372 | return Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /* Supporting function of target_dev_tree_mem() |
| 376 | * Function to add the subsequent RAM partition info to the device tree */ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 377 | INT32 |
| 378 | dev_tree_add_mem_info (VOID *fdt, UINT32 offset, UINT32 addr, UINT32 size) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 379 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 380 | STATIC INT32 mem_info_cnt = 0; |
| 381 | INT32 ret = 0; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 382 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 383 | if (!mem_info_cnt) { |
| 384 | /* Replace any other reg prop in the memory node. */ |
| 385 | ret = fdt_setprop_u32 (fdt, offset, "reg", addr); |
| 386 | mem_info_cnt = 1; |
| 387 | } else { |
| 388 | /* Append the mem info to the reg prop for subsequent nodes. */ |
| 389 | ret = fdt_appendprop_u32 (fdt, offset, "reg", addr); |
| 390 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 391 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 392 | if (ret) { |
| 393 | DEBUG ( |
| 394 | (EFI_D_ERROR, "Failed to add the memory information addr: %d\n", ret)); |
| 395 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 396 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 397 | ret = fdt_appendprop_u32 (fdt, offset, "reg", size); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 398 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 399 | if (ret) { |
| 400 | DEBUG ( |
| 401 | (EFI_D_ERROR, "Failed to add the memory information size: %d\n", ret)); |
| 402 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 403 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 404 | return ret; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 407 | INT32 |
| 408 | dev_tree_add_mem_infoV64 (VOID *fdt, UINT32 offset, UINT64 addr, UINT64 size) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 409 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 410 | STATIC INT32 mem_info_cnt = 0; |
| 411 | INT32 ret = 0; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 412 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 413 | if (!mem_info_cnt) { |
| 414 | /* Replace any other reg prop in the memory node. */ |
| 415 | ret = fdt_setprop_u64 (fdt, offset, "reg", addr); |
| 416 | mem_info_cnt = 1; |
| 417 | } else { |
| 418 | /* Append the mem info to the reg prop for subsequent nodes. */ |
| 419 | ret = fdt_appendprop_u64 (fdt, offset, "reg", addr); |
| 420 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 421 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 422 | if (ret) { |
| 423 | DEBUG ( |
| 424 | (EFI_D_ERROR, "Failed to add the memory information addr: %d\n", ret)); |
| 425 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 426 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 427 | ret = fdt_appendprop_u64 (fdt, offset, "reg", size); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 428 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 429 | if (ret) { |
| 430 | DEBUG ( |
| 431 | (EFI_D_ERROR, "Failed to add the memory information size: %d\n", ret)); |
| 432 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 433 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 434 | return ret; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Top level function that updates the device tree. */ |
Jeevan Shriram | 27c8faa | 2017-09-27 12:05:53 -0700 | [diff] [blame] | 438 | EFI_STATUS |
| 439 | UpdateDeviceTree (VOID *fdt, |
| 440 | CONST CHAR8 *cmdline, |
| 441 | VOID *ramdisk, |
| 442 | UINT32 RamDiskSize, |
| 443 | BOOLEAN BootWith32Bit) |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 444 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 445 | INT32 ret = 0; |
| 446 | UINT32 offset; |
| 447 | UINT32 PaddSize = 0; |
| 448 | UINT64 KaslrSeed = 0; |
| 449 | EFI_STATUS Status; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 450 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 451 | /* Check the device tree header */ |
| 452 | ret = fdt_check_header (fdt) || fdt_check_header_ext (fdt); |
| 453 | if (ret) { |
| 454 | DEBUG ((EFI_D_ERROR, "ERROR: Invalid device tree header ...\n")); |
| 455 | return EFI_NOT_FOUND; |
| 456 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 457 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 458 | /* Add padding to make space for new nodes and properties. */ |
lijuang | fd6fa91 | 2017-11-16 18:08:22 +0800 | [diff] [blame] | 459 | PaddSize = ADD_OF (fdt_totalsize (fdt), |
| 460 | DTB_PAD_SIZE + AsciiStrLen (cmdline)); |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 461 | if (!PaddSize) { |
Mukesh Ojha | 82911f8 | 2018-04-30 16:45:07 +0530 | [diff] [blame] | 462 | DEBUG ((EFI_D_ERROR, "ERROR: Integer Overflow: fdt size = %u\n", |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 463 | fdt_totalsize (fdt))); |
| 464 | return EFI_BAD_BUFFER_SIZE; |
| 465 | } |
| 466 | ret = fdt_open_into (fdt, fdt, PaddSize); |
| 467 | if (ret != 0) { |
| 468 | DEBUG ((EFI_D_ERROR, "ERROR: Failed to move/resize dtb buffer ...\n")); |
| 469 | return EFI_BAD_BUFFER_SIZE; |
| 470 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 471 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 472 | /* Get offset of the memory node */ |
| 473 | ret = fdt_path_offset (fdt, "/memory"); |
| 474 | if (ret < 0) { |
| 475 | DEBUG ((EFI_D_ERROR, "ERROR: Could not find memory node ...\n")); |
| 476 | return EFI_NOT_FOUND; |
| 477 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 478 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 479 | offset = ret; |
| 480 | Status = target_dev_tree_mem (fdt, offset, BootWith32Bit); |
| 481 | if (Status != EFI_SUCCESS) { |
| 482 | DEBUG ((EFI_D_ERROR, "ERROR: Cannot update memory node\n")); |
| 483 | return Status; |
| 484 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 485 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 486 | UpdateSplashMemInfo (fdt); |
Aravind Venkateswaran | c004803 | 2016-07-22 14:28:03 -0700 | [diff] [blame] | 487 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 488 | /* Get offset of the chosen node */ |
| 489 | ret = fdt_path_offset (fdt, "/chosen"); |
| 490 | if (ret < 0) { |
| 491 | DEBUG ((EFI_D_ERROR, "ERROR: Could not find chosen node ...\n")); |
| 492 | return EFI_NOT_FOUND; |
| 493 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 494 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 495 | offset = ret; |
| 496 | if (cmdline) { |
| 497 | /* Adding the cmdline to the chosen node */ |
| 498 | ret = fdt_appendprop_string (fdt, offset, (CONST char *)"bootargs", |
| 499 | (CONST VOID *)cmdline); |
| 500 | if (ret) { |
| 501 | DEBUG ((EFI_D_ERROR, |
| 502 | "ERROR: Cannot update chosen node [bootargs] - 0x%x\n", ret)); |
| 503 | return EFI_LOAD_ERROR; |
| 504 | } |
| 505 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 506 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 507 | Status = GetKaslrSeed (&KaslrSeed); |
| 508 | if (Status == EFI_SUCCESS) { |
| 509 | /* Adding Kaslr Seed to the chosen node */ |
| 510 | ret = fdt_appendprop_u64 (fdt, offset, (CONST char *)"kaslr-seed", |
| 511 | (UINT64)KaslrSeed); |
| 512 | if (ret) { |
| 513 | DEBUG ((EFI_D_INFO, |
| 514 | "ERROR: Cannot update chosen node [kaslr-seed] - 0x%x\n", ret)); |
| 515 | } else { |
| 516 | DEBUG ((EFI_D_INFO, "kaslr-Seed is added to chosen node\n")); |
| 517 | } |
| 518 | } else { |
| 519 | DEBUG ((EFI_D_INFO, "ERROR: Cannot generate Kaslr Seed - %r\n", Status)); |
| 520 | } |
Runmin Wang | 8ecc3f6 | 2016-12-09 14:03:05 -0800 | [diff] [blame] | 521 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 522 | if (RamDiskSize) { |
| 523 | /* Adding the initrd-start to the chosen node */ |
| 524 | ret = fdt_setprop_u64 (fdt, offset, "linux,initrd-start", (UINT64)ramdisk); |
| 525 | if (ret) { |
| 526 | DEBUG ((EFI_D_ERROR, |
| 527 | "ERROR: Cannot update chosen node [linux,initrd-start] - 0x%x\n", |
| 528 | ret)); |
| 529 | return EFI_NOT_FOUND; |
| 530 | } |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 531 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 532 | /* Adding the initrd-end to the chosen node */ |
| 533 | ret = fdt_setprop_u64 (fdt, offset, "linux,initrd-end", |
| 534 | ((UINT64)ramdisk + RamDiskSize)); |
| 535 | if (ret) { |
| 536 | DEBUG ((EFI_D_ERROR, |
| 537 | "ERROR: Cannot update chosen node [linux,initrd-end] - 0x%x\n", |
| 538 | ret)); |
| 539 | return EFI_NOT_FOUND; |
| 540 | } |
| 541 | } |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 542 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 543 | /* Update fstab node */ |
| 544 | DEBUG ((EFI_D_VERBOSE, "Start DT fstab node update: %lu ms\n", |
| 545 | GetTimerCountms ())); |
| 546 | UpdateFstabNode (fdt); |
| 547 | DEBUG ((EFI_D_VERBOSE, "End DT fstab node update: %lu ms\n", |
| 548 | GetTimerCountms ())); |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 549 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 550 | fdt_pack (fdt); |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 551 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 552 | return ret; |
Sridhar Parasuram | c8f5002 | 2015-12-05 10:36:04 -0800 | [diff] [blame] | 553 | } |
Channagoud Kadabi | 9be68a7 | 2016-02-08 15:18:24 -0800 | [diff] [blame] | 554 | |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 555 | /* Update device tree for fstab node */ |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 556 | EFI_STATUS |
| 557 | UpdateFstabNode (VOID *fdt) |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 558 | { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 559 | INT32 ParentOffset = 0; |
| 560 | INT32 SubNodeOffset = 0; |
| 561 | CONST struct fdt_property *Prop = NULL; |
| 562 | INT32 PropLen = 0; |
| 563 | char *NodeName = NULL; |
| 564 | EFI_STATUS Status = EFI_SUCCESS; |
| 565 | CHAR8 *BootDevBuf = NULL; |
| 566 | CHAR8 *ReplaceStr = NULL; |
| 567 | CHAR8 *NextStr = NULL; |
| 568 | struct FstabNode Table = FstabTable; |
| 569 | UINT32 DevNodeBootDevLen = 0; |
| 570 | UINT32 Index = 0; |
| 571 | UINT32 PaddingEnd = 0; |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 572 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 573 | /* Find the parent node */ |
| 574 | ParentOffset = fdt_path_offset (fdt, Table.ParentNode); |
| 575 | if (ParentOffset < 0) { |
| 576 | DEBUG ((EFI_D_VERBOSE, "Failed to Get parent node: fstab\terror: %d\n", |
| 577 | ParentOffset)); |
| 578 | return EFI_NOT_FOUND; |
| 579 | } |
| 580 | DEBUG ((EFI_D_VERBOSE, "Node: %a found.\n", |
| 581 | fdt_get_name (fdt, ParentOffset, NULL))); |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 582 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 583 | /* Get boot device type */ |
| 584 | BootDevBuf = AllocatePool (sizeof (CHAR8) * BOOT_DEV_MAX_LEN); |
| 585 | if (BootDevBuf == NULL) { |
| 586 | DEBUG ((EFI_D_ERROR, "Boot device buffer: Out of resources\n")); |
| 587 | return EFI_OUT_OF_RESOURCES; |
| 588 | } |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 589 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 590 | Status = GetBootDevice (BootDevBuf, BOOT_DEV_MAX_LEN); |
| 591 | if (Status != EFI_SUCCESS) { |
| 592 | DEBUG ((EFI_D_ERROR, "Failed to get Boot Device: %r\n", Status)); |
| 593 | FreePool (BootDevBuf); |
| 594 | BootDevBuf = NULL; |
| 595 | return Status; |
| 596 | } |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 597 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 598 | /* Get properties of all sub nodes */ |
| 599 | for (SubNodeOffset = fdt_first_subnode (fdt, ParentOffset); |
| 600 | SubNodeOffset >= 0; |
| 601 | SubNodeOffset = fdt_next_subnode (fdt, SubNodeOffset)) { |
| 602 | Prop = fdt_get_property (fdt, SubNodeOffset, Table.Property, &PropLen); |
| 603 | NodeName = (char *)(uintptr_t)fdt_get_name (fdt, SubNodeOffset, NULL); |
| 604 | if (!Prop) { |
| 605 | DEBUG ((EFI_D_VERBOSE, "Property:%a is not found for sub-node:%a\n", |
| 606 | Table.Property, NodeName)); |
| 607 | } else { |
| 608 | DEBUG ((EFI_D_VERBOSE, "Property:%a found for sub-node:%a\tProperty:%a\n", |
| 609 | Table.Property, NodeName, Prop->data)); |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 610 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 611 | /* Pointer to fdt 'dev' property string that needs to update based on the |
| 612 | * 'androidboot.bootdevice' */ |
| 613 | ReplaceStr = (CHAR8 *)Prop->data; |
| 614 | ReplaceStr = AsciiStrStr (ReplaceStr, Table.DevicePathId); |
| 615 | if (!ReplaceStr) { |
| 616 | DEBUG ((EFI_D_VERBOSE, "Update property:%a value is not proper to " |
| 617 | "update for sub-node:%a\n", |
| 618 | Table.Property, NodeName)); |
| 619 | continue; |
| 620 | } |
| 621 | ReplaceStr += AsciiStrLen (Table.DevicePathId); |
| 622 | NextStr = AsciiStrStr ((ReplaceStr + 1), "/"); |
| 623 | DevNodeBootDevLen = NextStr - ReplaceStr; |
| 624 | if (DevNodeBootDevLen >= AsciiStrLen (BootDevBuf)) { |
Mukesh Ojha | 323c940 | 2017-10-03 23:49:05 +0530 | [diff] [blame] | 625 | gBS->CopyMem (ReplaceStr, BootDevBuf, AsciiStrLen (BootDevBuf)); |
| 626 | PaddingEnd = DevNodeBootDevLen - AsciiStrLen (BootDevBuf); |
| 627 | /* Update the property with new value */ |
| 628 | if (PaddingEnd) { |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 629 | gBS->CopyMem (ReplaceStr + AsciiStrLen (BootDevBuf), NextStr, |
| 630 | AsciiStrLen (NextStr)); |
| 631 | for (Index = 0; Index < PaddingEnd; Index++) { |
| 632 | ReplaceStr[AsciiStrLen (BootDevBuf) + AsciiStrLen (NextStr) + |
| 633 | Index] = ' '; |
| 634 | } |
Mukesh Ojha | 323c940 | 2017-10-03 23:49:05 +0530 | [diff] [blame] | 635 | } |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 636 | } else { |
Mukesh Ojha | 323c940 | 2017-10-03 23:49:05 +0530 | [diff] [blame] | 637 | DEBUG ((EFI_D_ERROR, "String length mismatch b/w DT Bootdevice string" |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 638 | " (%d) and expected Bootdevice strings (%d)\n", |
| 639 | DevNodeBootDevLen, AsciiStrLen (BootDevBuf))); |
| 640 | } |
Mukesh Ojha | 323c940 | 2017-10-03 23:49:05 +0530 | [diff] [blame] | 641 | } |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 642 | } |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 643 | |
Jeevan Shriram | 17f173d | 2017-10-24 22:11:07 -0700 | [diff] [blame] | 644 | FreePool (BootDevBuf); |
| 645 | BootDevBuf = NULL; |
| 646 | return Status; |
Bhanuprakash Modem | 0450e9b | 2017-06-09 11:58:51 +0530 | [diff] [blame] | 647 | } |