Shell-beispielskripts, Beispielcode shell-beispielskripts, Beispiele – HP Unified Extensible Firmware Interface Benutzerhandbuch

Seite 71

Advertising
background image

Beispielcode

Shell-Beispielskripts

Beispiele

Die folgenden Beispielskripts illustrieren das Erfassen einer Konfiguration (Export) und deren
Replikation (Import) mit der auf einem virtuellen iLO Medium bereitgestellten Datei startup.nsh.

fs0:\>

/** @file
This is an example Shell Application. Note that there are
other ways to add a command to the shell. This example
demonstrates just one.

Copyright (c) 2013 Hewlett-Packard Development Company, L.P.

This software contains information confidential and proprietary to
Hewlett-Packard Company. It shall not be reproduced in whole or in part,
or transferred to other documents, or disclosed to third parties, or used
for any purpose other than that for which it was obtained without the prior
written consent of Hewlett-Packard Company.

**/

#include <Protocol/EfiShell.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>

/**
Implements simple shell HelloWorld Application that prints out
the string "Hello World" to the screen and then display UEFI
Shell revision and registered environment variables in system.
This example demonstrates how a new UEFI Shell Application can
be created to run at UEFI Shell Prompt.

@param ImageHandle Handle to the Image
@param SystemTable Pointer to the System Table

@retval EFI_SUCCESS In all cases
**/
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SHELL_PROTOCOL *UefiShellProtocol;
CONST CHAR16 *ConstEnvNameList;
CONST CHAR16 *Value;
EFI_STATUS Status;

Print (L"Hello World!\n");

//
// Locate UEFI Shell Protocol
//
Status = gBS->OpenProtocol (
ImageHandle,
&gEfiShellProtocolGuid,
(VOID **)&UefiShellProtocol,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);

if (EFI_ERROR(Status)) {
//
// Search for the shell protocol
//
Status = gBS->LocateProtocol (
&gEfiShellProtocolGuid,
NULL,
(VOID **)&UefiShellProtocol
);
if (EFI_ERROR(Status)) {
UefiShellProtocol = NULL;
return EFI_SUCCESS;
}
}

if (UefiShellProtocol != NULL) {
//
// Sample to read UEFI Shell Major and Minor Version Variables
//
Print (L"UEFI Shell Revision: %d.%d\n", UefiShellProtocol->MajorVersion, UefiShellProtocol->MinorVersion);

Shell-Beispielskripts

71

Advertising
Dieses Handbuch ist für die folgenden Produkte bezogen werden: