Exemples de scripts de shell, Exemple de code exemples de scripts de shell, Exemples – HP Interface micrologicielle extensible HP Unified Manuel d'utilisation

Page 71

Advertising
background image

Exemple de code

Exemples de scripts de shell

Exemples

L'exemple suivant montre comment capturer une configuration (exportation) et la copier (importation)
à partir du fichier startup.nsh monté sur un support virtuel iLO.

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);

Exemples de scripts de shell

71

Advertising
Ce manuel est liée aux produits suivants: