Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

970 lines
26 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. protid.c
  5. Abstract:
  6. Shell environment protocol id information management
  7. Revision History
  8. --*/
  9. #include "shelle.h"
  10. #include "efivar.h"
  11. #include "LegacyBoot.h"
  12. #include "VgaClass.h"
  13. #include "EfiConSplit.h"
  14. #include "intload.h"
  15. #define PROTOCOL_INFO_SIGNATURE EFI_SIGNATURE_32('s','p','i','n')
  16. typedef struct {
  17. UINTN Signature;
  18. LIST_ENTRY Link;
  19. /* parsing info for the protocol */
  20. EFI_GUID ProtocolId;
  21. CHAR16 *IdString;
  22. SHELLENV_DUMP_PROTOCOL_INFO DumpToken;
  23. SHELLENV_DUMP_PROTOCOL_INFO DumpInfo;
  24. /* database info on which handles are supporting this protocol */
  25. UINTN NoHandles;
  26. EFI_HANDLE *Handles;
  27. } PROTOCOL_INFO;
  28. struct {
  29. CHAR16 *IdString;
  30. SHELLENV_DUMP_PROTOCOL_INFO DumpInfo;
  31. SHELLENV_DUMP_PROTOCOL_INFO DumpToken;
  32. EFI_GUID ProtocolId;
  33. } SEnvInternalProtocolInfo[] = {
  34. L"DevIo", NULL, NULL, DEVICE_IO_PROTOCOL,
  35. L"fs", NULL, NULL, SIMPLE_FILE_SYSTEM_PROTOCOL,
  36. L"diskio", NULL, NULL, DISK_IO_PROTOCOL,
  37. L"blkio", SEnvBlkIo, NULL, BLOCK_IO_PROTOCOL,
  38. L"txtin", NULL, NULL, SIMPLE_TEXT_INPUT_PROTOCOL,
  39. L"txtout", SEnvTextOut, NULL, SIMPLE_TEXT_OUTPUT_PROTOCOL,
  40. L"fs", NULL, NULL, SIMPLE_FILE_SYSTEM_PROTOCOL,
  41. L"load", NULL, NULL, LOAD_FILE_PROTOCOL,
  42. L"image", SEnvImage, SEnvImageTok, LOADED_IMAGE_PROTOCOL,
  43. L"varstore", NULL, NULL, VARIABLE_STORE_PROTOCOL,
  44. L"unicode", NULL, NULL, UNICODE_COLLATION_PROTOCOL,
  45. L"LegacyBoot", NULL, NULL, LEGACY_BOOT_PROTOCOL,
  46. L"serialio", NULL, NULL, SERIAL_IO_PROTOCOL,
  47. L"pxebc", NULL, NULL, EFI_PXE_BASE_CODE_PROTOCOL,
  48. L"net", NULL, NULL, EFI_SIMPLE_NETWORK_PROTOCOL,
  49. L"VgaClass", NULL, NULL, VGA_CLASS_DRIVER_PROTOCOL,
  50. L"TxtOutSplit", NULL, NULL, TEXT_OUT_SPLITER_PROTOCOL,
  51. L"ErrOutSplit", NULL, NULL, ERROR_OUT_SPLITER_PROTOCOL,
  52. L"TxtInSplit", NULL, NULL, TEXT_IN_SPLITER_PROTOCOL,
  53. L"dpath", SEnvDPath, SEnvDPathTok, DEVICE_PATH_PROTOCOL,
  54. /* just plain old protocol ids */
  55. L"ShellInt", NULL, NULL, SHELL_INTERFACE_PROTOCOL,
  56. L"SEnv", NULL, NULL, ENVIRONMENT_VARIABLE_ID,
  57. L"ShellProtId", NULL, NULL, PROTOCOL_ID_ID,
  58. L"ShellDevPathMap", NULL, NULL, DEVICE_PATH_MAPPING_ID,
  59. L"ShellAlias", NULL, NULL, ALIAS_ID,
  60. /* ID guids */
  61. L"G0", NULL, NULL, { 0,0,0,0,0,0,0,0,0,0,0 },
  62. L"Efi", NULL, NULL, EFI_GLOBAL_VARIABLE,
  63. L"GenFileInfo", NULL, NULL, EFI_FILE_INFO_ID,
  64. L"FileSysInfo", NULL, NULL, EFI_FILE_SYSTEM_INFO_ID,
  65. L"PcAnsi", NULL, NULL, DEVICE_PATH_MESSAGING_PC_ANSI,
  66. L"Vt100", NULL, NULL, DEVICE_PATH_MESSAGING_VT_100,
  67. L"InternalLoad", NULL, NULL, INTERNAL_LOAD_PROTOCOL,
  68. L"Unknown Device", NULL, NULL, UNKNOWN_DEVICE_GUID,
  69. NULL
  70. } ;
  71. /*
  72. * SEnvProtocolInfo - A list of all known protocol info structures
  73. */
  74. LIST_ENTRY SEnvProtocolInfo;
  75. /*
  76. *
  77. */
  78. VOID
  79. INTERNAL
  80. SEnvInitProtocolInfo (
  81. VOID
  82. )
  83. {
  84. InitializeListHead (&SEnvProtocolInfo);
  85. }
  86. VOID
  87. INTERNAL
  88. SEnvLoadInternalProtInfo (
  89. VOID
  90. )
  91. /* Initialize internal protocol handlers */
  92. {
  93. UINTN Index;
  94. for (Index=0; SEnvInternalProtocolInfo[Index].IdString; Index += 1) {
  95. SEnvAddProtocol (
  96. &SEnvInternalProtocolInfo[Index].ProtocolId,
  97. SEnvInternalProtocolInfo[Index].DumpToken,
  98. SEnvInternalProtocolInfo[Index].DumpInfo,
  99. SEnvInternalProtocolInfo[Index].IdString
  100. );
  101. }
  102. }
  103. PROTOCOL_INFO *
  104. SEnvGetProtById (
  105. IN EFI_GUID *Protocol,
  106. IN BOOLEAN GenId
  107. )
  108. /* Locate a protocol handle by guid */
  109. {
  110. PROTOCOL_INFO *Prot;
  111. LIST_ENTRY *Link;
  112. UINTN LastId, Id;
  113. CHAR16 s[40];
  114. ASSERT_LOCKED(&SEnvGuidLock);
  115. /*
  116. * Find the protocol entry for this id
  117. */
  118. LastId = 0;
  119. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  120. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  121. if (CompareGuid(&Prot->ProtocolId, Protocol) == 0) {
  122. return Prot;
  123. }
  124. if (Prot->IdString[0] == 'g') {
  125. Id = Atoi(Prot->IdString+1);
  126. LastId = Id > LastId ? Id : LastId;
  127. }
  128. }
  129. /*
  130. * If the protocol id is not found, gen a string for it if needed
  131. */
  132. Prot = NULL;
  133. if (GenId) {
  134. SPrint (s, sizeof(s), L"g%d", LastId+1);
  135. Prot = AllocateZeroPool (sizeof(PROTOCOL_INFO));
  136. if (Prot) {
  137. Prot->Signature = PROTOCOL_INFO_SIGNATURE;
  138. CopyMem (&Prot->ProtocolId, Protocol, sizeof(EFI_GUID));
  139. Prot->IdString = StrDuplicate(s);
  140. InsertTailList (&SEnvProtocolInfo, &Prot->Link);
  141. }
  142. }
  143. return Prot;
  144. }
  145. PROTOCOL_INFO *
  146. SEnvGetProtByStr (
  147. IN CHAR16 *Str
  148. )
  149. {
  150. PROTOCOL_INFO *Prot;
  151. LIST_ENTRY *Link;
  152. UINTN Index;
  153. EFI_GUID Guid;
  154. CHAR16 c;
  155. CHAR16 *p;
  156. ASSERT_LOCKED(&SEnvGuidLock);
  157. /* Search for short name match */
  158. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  159. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  160. if (StriCmp(Prot->IdString, Str) == 0) {
  161. return Prot;
  162. }
  163. }
  164. /* Convert Str to guid and then match */
  165. if (StrLen(Str) == 36 && Str[9] == '-' && Str[19] == '-' && Str[24] == '-') {
  166. Guid.Data1 = (UINT32) xtoi(Str+0);
  167. Guid.Data2 = (UINT16) xtoi(Str+10);
  168. Guid.Data3 = (UINT16) xtoi(Str+15);
  169. for (Index=0; Index < 8; Index++) {
  170. p = Str+25+Index*2;
  171. c = p[3];
  172. p[3] = 0;
  173. Guid.Data4[Index] = (UINT8) xtoi(p);
  174. p[3] = c;
  175. }
  176. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  177. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  178. if (CompareGuid(&Prot->ProtocolId, &Guid) == 0) {
  179. return Prot;
  180. }
  181. }
  182. }
  183. return NULL;
  184. }
  185. EFI_STATUS
  186. SEnvIGetProtID (
  187. IN CHAR16 *Str,
  188. OUT EFI_GUID *ProtId
  189. )
  190. {
  191. PROTOCOL_INFO *Prot;
  192. EFI_STATUS Status;
  193. AcquireLock (&SEnvGuidLock);
  194. Status = EFI_NOT_FOUND;
  195. CopyMem (ProtId, &NullGuid, sizeof(EFI_GUID));
  196. Prot = SEnvGetProtByStr (Str);
  197. if (Prot) {
  198. CopyMem (ProtId, &Prot->ProtocolId, sizeof(EFI_GUID));
  199. Status = EFI_SUCCESS;
  200. }
  201. ReleaseLock (&SEnvGuidLock);
  202. return Status;
  203. }
  204. VOID
  205. SEnvAddProtocol (
  206. IN EFI_GUID *Protocol,
  207. IN SHELLENV_DUMP_PROTOCOL_INFO DumpToken OPTIONAL,
  208. IN SHELLENV_DUMP_PROTOCOL_INFO DumpInfo OPTIONAL,
  209. IN CHAR16 *IdString
  210. )
  211. /* Published interface to add protocol handlers */
  212. {
  213. SEnvIAddProtocol (TRUE, Protocol, DumpToken, DumpInfo, IdString);
  214. }
  215. VOID
  216. INTERNAL
  217. SEnvIAddProtocol (
  218. IN BOOLEAN SaveId,
  219. IN EFI_GUID *Protocol,
  220. IN SHELLENV_DUMP_PROTOCOL_INFO DumpToken OPTIONAL,
  221. IN SHELLENV_DUMP_PROTOCOL_INFO DumpInfo OPTIONAL,
  222. IN CHAR16 *IdString
  223. )
  224. /* Internal interface to add protocol handlers */
  225. {
  226. PROTOCOL_INFO *Prot;
  227. BOOLEAN StoreInfo;
  228. CHAR16 *ObsoleteName;
  229. ObsoleteName = NULL;
  230. StoreInfo = FALSE;
  231. AcquireLock (&SEnvGuidLock);
  232. /*
  233. * Get the current protocol info
  234. */
  235. Prot = SEnvGetProtById (Protocol, FALSE);
  236. if (Prot) {
  237. /*
  238. * If the name has changed, delete the old var
  239. */
  240. if (StriCmp (Prot->IdString, IdString)) {
  241. ObsoleteName = Prot->IdString;
  242. StoreInfo = TRUE;
  243. } else {
  244. FreePool (Prot->IdString);
  245. }
  246. Prot->IdString = NULL;
  247. } else {
  248. /*
  249. * Allocate new protocol info
  250. */
  251. Prot = AllocateZeroPool (sizeof(PROTOCOL_INFO));
  252. Prot->Signature = PROTOCOL_INFO_SIGNATURE;
  253. StoreInfo = TRUE;
  254. }
  255. /*
  256. * Apply any updates to the protocol info
  257. */
  258. if (Prot) {
  259. CopyMem (&Prot->ProtocolId, Protocol, sizeof(EFI_GUID));
  260. Prot->IdString = StrDuplicate(IdString);
  261. Prot->DumpToken = DumpToken;
  262. Prot->DumpInfo = DumpInfo;
  263. if (Prot->Link.Flink) {
  264. RemoveEntryList (&Prot->Link);
  265. }
  266. InsertTailList (&SEnvProtocolInfo, &Prot->Link);
  267. }
  268. ReleaseLock (&SEnvGuidLock);
  269. /*
  270. * If the name changed, delete the old name
  271. */
  272. if (ObsoleteName) {
  273. RT->SetVariable (ObsoleteName, &SEnvProtId, 0, 0, NULL);
  274. FreePool (ObsoleteName);
  275. }
  276. /*
  277. * Store the protocol idstring to a variable
  278. */
  279. if (Prot && StoreInfo && SaveId) {
  280. RT->SetVariable (
  281. Prot->IdString,
  282. &SEnvProtId,
  283. EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
  284. sizeof(EFI_GUID),
  285. &Prot->ProtocolId
  286. );
  287. }
  288. }
  289. VOID
  290. INTERNAL
  291. SEnvLoadHandleProtocolInfo (
  292. IN EFI_GUID *SkipProtocol
  293. )
  294. /* Code to load the internal handle cross-reference info for each protocol */
  295. {
  296. PROTOCOL_INFO *Prot;
  297. LIST_ENTRY *Link;
  298. AcquireLock (&SEnvGuidLock);
  299. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  300. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  301. if (!SkipProtocol || CompareGuid(SkipProtocol, &Prot->ProtocolId) != 0) {
  302. LibLocateHandle (
  303. ByProtocol,
  304. &Prot->ProtocolId,
  305. NULL,
  306. &Prot->NoHandles,
  307. &Prot->Handles
  308. );
  309. }
  310. }
  311. ReleaseLock (&SEnvGuidLock);
  312. }
  313. VOID
  314. INTERNAL
  315. SEnvFreeHandleProtocolInfo (
  316. VOID
  317. )
  318. /* Free the internal handle cross-reference protocol info */
  319. {
  320. PROTOCOL_INFO *Prot;
  321. LIST_ENTRY *Link;
  322. AcquireLock (&SEnvGuidLock);
  323. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  324. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  325. if (Prot->NoHandles) {
  326. FreePool (Prot->Handles);
  327. Prot->Handles = NULL;
  328. Prot->NoHandles = 0;
  329. }
  330. }
  331. ReleaseLock (&SEnvGuidLock);
  332. }
  333. CHAR16 *
  334. INTERNAL
  335. SEnvIGetProtocol (
  336. IN EFI_GUID *ProtocolId,
  337. IN BOOLEAN GenId
  338. )
  339. /* Published interface to lookup a protocol id string */
  340. {
  341. PROTOCOL_INFO *Prot;
  342. CHAR16 *Id;
  343. ASSERT_LOCKED (&SEnvGuidLock);
  344. Prot = SEnvGetProtById(ProtocolId, GenId);
  345. Id = Prot ? Prot->IdString : NULL;
  346. return Id;
  347. }
  348. CHAR16 *
  349. SEnvGetProtocol (
  350. IN EFI_GUID *ProtocolId,
  351. IN BOOLEAN GenId
  352. )
  353. /* Published interface to lookup a protocol id string */
  354. {
  355. CHAR16 *Id;
  356. AcquireLock (&SEnvGuidLock);
  357. Id = SEnvIGetProtocol(ProtocolId, GenId);
  358. ReleaseLock (&SEnvGuidLock);
  359. return Id;
  360. }
  361. EFI_STATUS
  362. INTERNAL
  363. SEnvCmdProt (
  364. IN EFI_HANDLE ImageHandle,
  365. IN EFI_SYSTEM_TABLE *SystemTable
  366. )
  367. /* Code for internal "prot" command */
  368. {
  369. PROTOCOL_INFO *Prot;
  370. LIST_ENTRY *Link;
  371. UINTN Len, SLen;
  372. CHAR16 *p;
  373. UINTN Index;
  374. BOOLEAN PageBreaks;
  375. UINTN TempColumn;
  376. UINTN ScreenCount;
  377. UINTN ScreenSize;
  378. CHAR16 ReturnStr[1];
  379. InitializeShellApplication (ImageHandle, SystemTable);
  380. PageBreaks = FALSE;
  381. for (Index = 1;Index < SI->Argc; Index++) {
  382. p = SI->Argv[Index];
  383. if (*p == '-') {
  384. switch (p[1]) {
  385. case 'b' :
  386. case 'B' :
  387. PageBreaks = TRUE;
  388. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  389. ScreenCount = 0;
  390. break;
  391. default :
  392. Print(L"guid : Unknown flag %s\n",p);
  393. return EFI_INVALID_PARAMETER;
  394. }
  395. }
  396. }
  397. AcquireLock (&SEnvGuidLock);
  398. /*
  399. * Find the protocol entry for this id
  400. */
  401. SLen = 0;
  402. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  403. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  404. Len = StrLen(Prot->IdString);
  405. if (StrLen(Prot->IdString) > SLen) {
  406. SLen = Len;
  407. }
  408. }
  409. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  410. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  411. /* Can't use Lib function to dump the guid as it may lookup the "short name" for it */
  412. /*
  413. * BUGBUG : Have to release and reacquire the lock for output redirection of this command
  414. * to work properly. Otherwise, we get an ASSERT from RaiseTPL().
  415. */
  416. ReleaseLock (&SEnvGuidLock);
  417. Print(L" %h-.*s : %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x %c\n",
  418. SLen,
  419. Prot->IdString,
  420. Prot->ProtocolId.Data1,
  421. Prot->ProtocolId.Data2,
  422. Prot->ProtocolId.Data3,
  423. Prot->ProtocolId.Data4[0],
  424. Prot->ProtocolId.Data4[1],
  425. Prot->ProtocolId.Data4[2],
  426. Prot->ProtocolId.Data4[3],
  427. Prot->ProtocolId.Data4[4],
  428. Prot->ProtocolId.Data4[5],
  429. Prot->ProtocolId.Data4[6],
  430. Prot->ProtocolId.Data4[7],
  431. (Prot->DumpToken || Prot->DumpInfo) ? L'*' : L' '
  432. );
  433. if (PageBreaks) {
  434. ScreenCount++;
  435. if (ScreenCount > ScreenSize - 4) {
  436. ScreenCount = 0;
  437. Print (L"\nPress Return to contiue :");
  438. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  439. Print (L"\n\n");
  440. }
  441. }
  442. AcquireLock (&SEnvGuidLock);
  443. }
  444. ReleaseLock (&SEnvGuidLock);
  445. return EFI_SUCCESS;
  446. }
  447. VOID
  448. SEnvDHProt (
  449. IN BOOLEAN Verbose,
  450. IN UINTN HandleNo,
  451. IN EFI_HANDLE Handle
  452. )
  453. {
  454. PROTOCOL_INFO *Prot;
  455. LIST_ENTRY *Link;
  456. VOID *Interface;
  457. UINTN Index;
  458. EFI_STATUS Status;
  459. SHELLENV_DUMP_PROTOCOL_INFO Dump;
  460. if (!HandleNo) {
  461. for (HandleNo=0; HandleNo < SEnvNoHandles; HandleNo++) {
  462. if (SEnvHandles[HandleNo] == Handle) {
  463. break;
  464. }
  465. }
  466. HandleNo += 1;
  467. }
  468. Print (Verbose ? L"%NHandle %h02x (%hX)\n" : L"%N %h2x: ", HandleNo, Handle);
  469. for (Link=SEnvProtocolInfo.Flink; Link != &SEnvProtocolInfo; Link=Link->Flink) {
  470. Prot = CR(Link, PROTOCOL_INFO, Link, PROTOCOL_INFO_SIGNATURE);
  471. for (Index=0; Index < Prot->NoHandles; Index++) {
  472. /*
  473. * If this handle supports this protocol, dump it
  474. */
  475. if (Prot->Handles[Index] == Handle) {
  476. Dump = Verbose ? Prot->DumpInfo : Prot->DumpToken;
  477. Status = BS->HandleProtocol (Handle, &Prot->ProtocolId, &Interface);
  478. if (Verbose) {
  479. Print (L" %hs ", Prot->IdString);
  480. if (Dump && !EFI_ERROR(Status)) {
  481. Dump (Handle, Interface);
  482. }
  483. Print (L"\n");
  484. } else {
  485. if (Dump && !EFI_ERROR(Status)) {
  486. Dump (Handle, Interface);
  487. } else {
  488. Print (L"%hs ", Prot->IdString);
  489. }
  490. }
  491. }
  492. }
  493. }
  494. Print (Verbose ? L"%N" : L"%N\n");
  495. }
  496. EFI_STATUS
  497. INTERNAL
  498. SEnvCmdDH (
  499. IN EFI_HANDLE ImageHandle,
  500. IN EFI_SYSTEM_TABLE *SystemTable
  501. )
  502. /* Code for internal "DH" command */
  503. {
  504. BOOLEAN ByProtocol;
  505. CHAR16 *Arg, *p;
  506. EFI_STATUS Status;
  507. UINTN Index;
  508. PROTOCOL_INFO *Prot;
  509. BOOLEAN PageBreaks;
  510. UINTN TempColumn;
  511. UINTN ScreenCount;
  512. UINTN ScreenSize;
  513. CHAR16 ReturnStr[1];
  514. /*
  515. * Initialize
  516. */
  517. InitializeShellApplication (ImageHandle, SystemTable);
  518. Arg = NULL;
  519. ByProtocol = FALSE;
  520. /*
  521. * Crack args
  522. */
  523. PageBreaks = FALSE;
  524. for (Index = 1; Index < SI->Argc; Index += 1) {
  525. p = SI->Argv[Index];
  526. if (*p == '-') {
  527. switch (p[1]) {
  528. case 'p':
  529. case 'P':
  530. ByProtocol = TRUE;
  531. break;
  532. case 'b' :
  533. case 'B' :
  534. PageBreaks = TRUE;
  535. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  536. ScreenCount = 0;
  537. break;
  538. default:
  539. Print (L"%EDH: Unkown flag %s\n", p);
  540. Status = EFI_INVALID_PARAMETER;
  541. goto Done;
  542. }
  543. continue;
  544. }
  545. if (!Arg) {
  546. Arg = p;
  547. continue;
  548. }
  549. Print (L"%EDH: too many arguments\n");
  550. Status = EFI_INVALID_PARAMETER;
  551. goto Done;
  552. }
  553. /*
  554. *
  555. * Load handle & protocol info tables
  556. */
  557. SEnvLoadHandleTable ();
  558. SEnvLoadHandleProtocolInfo (NULL);
  559. if (Arg) {
  560. if (ByProtocol) {
  561. AcquireLock (&SEnvGuidLock);
  562. Prot = SEnvGetProtByStr (Arg);
  563. ReleaseLock (&SEnvGuidLock);
  564. if (Prot) {
  565. /* Dump the handles on this protocol */
  566. Print(L"%NHandle dump by protocol '%s'\n", Prot->IdString);
  567. for (Index=0; Index < Prot->NoHandles; Index++) {
  568. SEnvDHProt (FALSE, 0, Prot->Handles[Index]);
  569. if (PageBreaks) {
  570. ScreenCount++;
  571. if (ScreenCount > ScreenSize - 4) {
  572. ScreenCount = 0;
  573. Print (L"\nPress Return to contiue :");
  574. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  575. Print (L"\n\n");
  576. }
  577. }
  578. }
  579. } else {
  580. Print(L"%EDH: Protocol '%s' not found\n", Arg);
  581. }
  582. } else {
  583. /* Dump 1 handle */
  584. Index = SEnvHandleNoFromStr(Arg) - 1;
  585. if (Index > SEnvNoHandles) {
  586. Print(L"%EDH: Invalid handle #\n");
  587. } else {
  588. SEnvDHProt (TRUE, Index+1, SEnvHandles[Index]);
  589. }
  590. }
  591. } else {
  592. /* Dump all handles */
  593. Print(L"%NHandle dump\n");
  594. for (Index=0; Index < SEnvNoHandles; Index++) {
  595. SEnvDHProt (FALSE, Index+1, SEnvHandles[Index]);
  596. if (PageBreaks) {
  597. ScreenCount++;
  598. if (ScreenCount > ScreenSize - 4) {
  599. ScreenCount = 0;
  600. Print (L"\nPress Return to contiue :");
  601. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  602. Print (L"\n\n");
  603. }
  604. }
  605. }
  606. }
  607. Status = EFI_SUCCESS;
  608. Done:
  609. SEnvFreeHandleTable ();
  610. return Status;
  611. }
  612. extern LIST_ENTRY SEnvMap;
  613. extern LIST_ENTRY SEnvEnv;
  614. extern LIST_ENTRY SEnvAlias;
  615. EFI_STATUS
  616. SEnvLoadDefaults (
  617. IN EFI_HANDLE Image,
  618. IN EFI_SYSTEM_TABLE *SystemTable
  619. )
  620. {
  621. LIST_ENTRY DefCmds;
  622. POOL_PRINT Path;
  623. DEFAULT_CMD *Cmd;
  624. PROTOCOL_INFO *ProtFs, *ProtBlkIo;
  625. UINTN Index, HandleNo;
  626. CHAR16 *DefaultMapping;
  627. InitializeShellApplication (Image, SystemTable);
  628. /*
  629. * If we have some settings, use those
  630. */
  631. if (!IsListEmpty(&SEnvMap) || !IsListEmpty(&SEnvEnv) || !IsListEmpty(&SEnvAlias)) {
  632. return EFI_SUCCESS;
  633. }
  634. /*
  635. * There are no settings, build some defaults
  636. */
  637. InitializeListHead (&DefCmds);
  638. ZeroMem (&Path, sizeof(Path));
  639. AcquireLock (&SEnvLock);
  640. SEnvLoadHandleTable();
  641. SEnvLoadHandleProtocolInfo (NULL);
  642. AcquireLock (&SEnvGuidLock);
  643. ProtFs = SEnvGetProtByStr(L"fs");
  644. ProtBlkIo = SEnvGetProtByStr(L"blkio");
  645. ReleaseLock (&SEnvGuidLock);
  646. /*
  647. * Run all the devices that support a File System and add a default
  648. * mapping and path setting for each device
  649. */
  650. CatPrint (&Path, L"set path ");
  651. for (Index=0; Index < ProtFs->NoHandles; Index++) {
  652. for (HandleNo=0; HandleNo < SEnvNoHandles; HandleNo++) {
  653. if (SEnvHandles[HandleNo] == ProtFs->Handles[Index]) {
  654. break;
  655. }
  656. }
  657. HandleNo += 1;
  658. Cmd = AllocateZeroPool(sizeof(DEFAULT_CMD));
  659. Cmd->Line = Cmd->Buffer;
  660. SPrint(Cmd->Line, sizeof(Cmd->Buffer), L"map fs%x %x", Index, HandleNo);
  661. InsertTailList(&DefCmds, &Cmd->Link);
  662. /* append this device to the path */
  663. CatPrint (&Path, L"fs%x:\\efi\\tools;fs%x:\\;", Index, Index);
  664. }
  665. CatPrint (&Path, L".");
  666. /*
  667. * Run all the devices that support a BlockIo and add a default
  668. * mapping for the device
  669. */
  670. for (Index=0; Index < ProtBlkIo->NoHandles; Index++) {
  671. for (HandleNo=0; HandleNo < SEnvNoHandles; HandleNo++) {
  672. if (SEnvHandles[HandleNo] == ProtBlkIo->Handles[Index]) {
  673. break;
  674. }
  675. }
  676. HandleNo += 1;
  677. Cmd = AllocateZeroPool(sizeof(DEFAULT_CMD));
  678. Cmd->Line = Cmd->Buffer;
  679. SPrint(Cmd->Line, sizeof(Cmd->Buffer), L"map blk%x %x", Index, HandleNo);
  680. InsertTailList(&DefCmds, &Cmd->Link);
  681. }
  682. /* release handle table resources & lock */
  683. SEnvFreeHandleTable();
  684. ReleaseLock (&SEnvLock);
  685. /*
  686. * execute all the queue commands
  687. */
  688. while (!IsListEmpty(&DefCmds)) {
  689. Cmd = CR(DefCmds.Flink, DEFAULT_CMD, Link, 0);
  690. SEnvExecute (Image, Cmd->Line, TRUE);
  691. RemoveEntryList (&Cmd->Link);
  692. FreePool (Cmd);
  693. }
  694. SEnvExecute (Image, Path.str, TRUE);
  695. SEnvExecute (Image, L"alias dir ls", TRUE);
  696. SEnvExecute (Image, L"alias md mkdir", TRUE);
  697. SEnvExecute (Image, L"alias rd rm", TRUE);
  698. SEnvExecute (Image, L"alias del rm", TRUE);
  699. SEnvExecute (Image, L"alias copy cp", TRUE);
  700. DefaultMapping = SEnvGetDefaultMapping(Image);
  701. if (DefaultMapping!=NULL) {
  702. ZeroMem (&Path, sizeof(Path));
  703. CatPrint(&Path,L"%s:",DefaultMapping);
  704. SEnvExecute (Image, Path.str, TRUE);
  705. }
  706. FreePool (Path.str);
  707. return EFI_SUCCESS;
  708. }
  709. EFI_STATUS
  710. SEnvReloadDefaults (
  711. IN EFI_HANDLE Image,
  712. IN EFI_SYSTEM_TABLE *SystemTable
  713. )
  714. {
  715. LIST_ENTRY DefCmds;
  716. POOL_PRINT Path;
  717. DEFAULT_CMD *Cmd;
  718. PROTOCOL_INFO *ProtFs, *ProtBlkIo;
  719. UINTN Index, HandleNo;
  720. InitializeShellApplication (Image, SystemTable);
  721. /*
  722. * There are no settings, build some defaults
  723. */
  724. InitializeListHead (&DefCmds);
  725. ZeroMem (&Path, sizeof(Path));
  726. AcquireLock (&SEnvLock);
  727. SEnvLoadHandleTable();
  728. SEnvLoadHandleProtocolInfo (NULL);
  729. AcquireLock (&SEnvGuidLock);
  730. ProtFs = SEnvGetProtByStr(L"fs");
  731. ProtBlkIo = SEnvGetProtByStr(L"blkio");
  732. ReleaseLock (&SEnvGuidLock);
  733. /*
  734. * Run all the devices that support a File System and add a default
  735. * mapping and path setting for each device
  736. */
  737. CatPrint (&Path, L"set path ");
  738. for (Index=0; Index < ProtFs->NoHandles; Index++) {
  739. for (HandleNo=0; HandleNo < SEnvNoHandles; HandleNo++) {
  740. if (SEnvHandles[HandleNo] == ProtFs->Handles[Index]) {
  741. break;
  742. }
  743. }
  744. HandleNo += 1;
  745. Cmd = AllocateZeroPool(sizeof(DEFAULT_CMD));
  746. Cmd->Line = Cmd->Buffer;
  747. SPrint(Cmd->Line, sizeof(Cmd->Buffer), L"map fs%x %x", Index, HandleNo);
  748. InsertTailList(&DefCmds, &Cmd->Link);
  749. /* append this device to the path */
  750. CatPrint (&Path, L"fs%x:\\efi\\tools;fs%x:\\;", Index, Index);
  751. }
  752. CatPrint (&Path, L".");
  753. /*
  754. * Run all the devices that support a BlockIo and add a default
  755. * mapping for the device
  756. */
  757. for (Index=0; Index < ProtBlkIo->NoHandles; Index++) {
  758. for (HandleNo=0; HandleNo < SEnvNoHandles; HandleNo++) {
  759. if (SEnvHandles[HandleNo] == ProtBlkIo->Handles[Index]) {
  760. break;
  761. }
  762. }
  763. HandleNo += 1;
  764. Cmd = AllocateZeroPool(sizeof(DEFAULT_CMD));
  765. Cmd->Line = Cmd->Buffer;
  766. SPrint(Cmd->Line, sizeof(Cmd->Buffer), L"map blk%x %x", Index, HandleNo);
  767. InsertTailList(&DefCmds, &Cmd->Link);
  768. }
  769. /* release handle table resources & lock */
  770. SEnvFreeHandleTable();
  771. ReleaseLock (&SEnvLock);
  772. /*
  773. * execute all the queue commands
  774. */
  775. while (!IsListEmpty(&DefCmds)) {
  776. Cmd = CR(DefCmds.Flink, DEFAULT_CMD, Link, 0);
  777. SEnvExecute (Image, Cmd->Line, TRUE);
  778. RemoveEntryList (&Cmd->Link);
  779. FreePool (Cmd);
  780. }
  781. SEnvExecute (Image, Path.str, TRUE);
  782. FreePool (Path.str);
  783. return EFI_SUCCESS;
  784. }