Updates BootOrder by adding new boot option BootNumNew at index BootIndexNew. */
| 371 | |
| 372 | /** Updates BootOrder by adding new boot option BootNumNew at index BootIndexNew. */ |
| 373 | EFI_STATUS |
| 374 | AddToBootOrder ( |
| 375 | IN UINT16 BootNumNew, |
| 376 | IN UINTN BootIndexNew |
| 377 | ) |
| 378 | { |
| 379 | EFI_STATUS Status; |
| 380 | UINT16 *BootOrder = NULL; |
| 381 | UINT16 *BootOrderNew = NULL; |
| 382 | UINTN BootOrderLen = 0; |
| 383 | UINTN Index; |
| 384 | |
| 385 | |
| 386 | DBG("AddToBootOrder: Boot%04hX at index %llu\n", BootNumNew, BootIndexNew); |
| 387 | Status = GetBootOrder (&BootOrder, &BootOrderLen); |
| 388 | if (EFI_ERROR(Status)) { |
| 389 | return Status; |
| 390 | } |
| 391 | |
| 392 | if (BootIndexNew > BootOrderLen) { |
| 393 | BootIndexNew = BootOrderLen; |
| 394 | DBG("AddToBootOrder: Index too big. Setting to: %llu\n", BootIndexNew); |
| 395 | } |
| 396 | |
| 397 | // |
| 398 | // Make new order buffer with space for our option |
| 399 | // |
| 400 | BootOrderNew = (__typeof__(BootOrderNew))AllocateZeroPool((BootOrderLen + 1) * sizeof(UINT16)); |
| 401 | if (BootOrderNew == NULL) { |
| 402 | DBG("AddToBootOrder: EFI_OUT_OF_RESOURCES\n"); |
| 403 | if (BootOrder) { |
| 404 | FreePool(BootOrder); |
| 405 | } |
| 406 | return EFI_OUT_OF_RESOURCES; |
| 407 | } |
| 408 | BootOrderLen += 1; |
| 409 | |
| 410 | |
| 411 | // |
| 412 | // Make BootOrderNew array |
| 413 | // |
| 414 | |
| 415 | // copy all before BootIndex first |
| 416 | for (Index = 0; Index < BootIndexNew; Index++) { |
| 417 | BootOrderNew[Index] = BootOrder[Index]; |
| 418 | } |
| 419 | |
| 420 | // then add our new BootNumNew |
| 421 | BootOrderNew[BootIndexNew] = BootNumNew; |
| 422 | |
| 423 | // then add the rest of previous indexes |
| 424 | for (Index = BootIndexNew + 1; Index < BootOrderLen; Index++) { |
| 425 | BootOrderNew[Index] = BootOrder[Index - 1]; |
| 426 | } |
| 427 | |
| 428 | // |
| 429 | // Save it |
| 430 | // |
no test coverage detected