MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / SetVariablesFromNvram

Function SetVariablesFromNvram

rEFIt_UEFI/refit/main.cpp:1630–1705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1628}
1629
1630VOID SetVariablesFromNvram()
1631{
1632 CHAR8 *tmpString;
1633 UINTN Size = 0;
1634 UINTN index = 0, index2, i;
1635 CHAR8 *arg = NULL;
1636
1637// DbgHeader("SetVariablesFromNvram");
1638
1639 tmpString = (__typeof__(tmpString))GetNvramVariable(L"boot-args", &gEfiAppleBootGuid, NULL, &Size);
1640 if (tmpString && (Size <= 0x1000) && (Size > 0)) {
1641 DBG("found boot-args in NVRAM:%s, size=%llu\n", tmpString, Size);
1642 // use and forget old one
1643// DeleteNvramVariable(L"boot-args", &gEfiAppleBootGuid);
1644 Size = AsciiStrLen(tmpString); // some EFI implementations include '\0' in Size, and others don't, so update Size to string length
1645 arg = (__typeof__(arg))AllocatePool(Size+1);
1646
1647/* if (AsciiStrStr(tmpString, "nvda_drv=1")) { //found substring
1648 gSettings.NvidiaWeb = TRUE;
1649 } */
1650 //first we will find new args that is not present in main args
1651 index = 0;
1652 while ((index < Size) && (tmpString[index] != 0x0)) {
1653 ZeroMem(arg, Size+1);
1654 index2 = 0;
1655 if (tmpString[index] != '\"') {
1656 // DBG("search space index=%d\n", index);
1657 while ((index < Size) && (tmpString[index] != 0x20) && (tmpString[index] != 0x0)) {
1658 arg[index2++] = tmpString[index++];
1659 }
1660 DBG("...found arg:%s\n", arg);
1661 } else {
1662 index++;
1663// DBG("search quote index=%d\n", index);
1664 while ((index < Size) && (tmpString[index] != '\"') && (tmpString[index] != 0x0)) {
1665 arg[index2++] = tmpString[index++];
1666 }
1667 if (tmpString[index] == '\"') {
1668 index++;
1669 }
1670 DBG("...found quoted arg:\n"/*, arg*/);
1671 }
1672 while (tmpString[index] == 0x20) {
1673 index++;
1674 }
1675 // For the moment only arg -s must be ignored
1676 if (AsciiStrCmp(arg, "-s") == 0) {
1677 DBG("...ignoring arg:%s\n", arg);
1678 continue;
1679 }
1680 if (!gSettings.BootArgs.contains(arg)) {
1681 //this arg is not present will add
1682 DBG("...adding arg:%s\n", arg);
1683 gSettings.BootArgs.trim();
1684 gSettings.BootArgs += ' ';
1685 for (i = 0; i < index2; i++) {
1686 gSettings.BootArgs += arg[i];
1687 }

Callers 1

RefitMainFunction · 0.85

Calls 8

GetNvramVariableFunction · 0.85
AsciiStrLenFunction · 0.85
AsciiStrCmpFunction · 0.85
trimMethod · 0.80
AllocatePoolFunction · 0.50
ZeroMemFunction · 0.50
FreePoolFunction · 0.50
containsMethod · 0.45

Tested by

no test coverage detected