You've already forked slimbootloader
mirror of
https://github.com/Dasharo/slimbootloader.git
synced 2026-03-06 15:26:20 -08:00
990e3e81e6
Convert the line endings stored for all text files in the repository to LF. The majority previously used DOS-style CRLF line endings. Add a .gitattributes file to enforce this and treat certain extensions as never being text files. Update PatchCheck.py to insist on LF line endings rather than CRLF. However, its other checks fail on this commit due to lots of pre-existing complaints that it only notices because the line endings have changed. Silicon/QemuSocPkg/FspBin/Patches/0001-Build-QEMU-FSP-2.0-binaries.patch needs to be treated as binary since it contains a mixture of line endings. This change has implications depending on the client platform you are using the repository from: * Windows The usual configuration for Git on Windows means that text files will be checked out to the work tree with DOS-style CRLF line endings. If that's not the case then you can configure Git to do so for the entire machine with: git config --global core.autocrlf true or for just the repository with: git config core.autocrlf true Line endings will be normalised to LF when they are committed to the repository. If you commit a text file with only LF line endings then it will be converted to CRLF line endings in your work tree. * Linux, MacOS and other Unices The usual configuration for Git on such platforms is to check files out of the repository with LF line endings. This is probably the right thing for you. In the unlikely even that you are using Git on Unix but editing or compiling on Windows for some reason then you may need to tweak your configuration to force the use of CRLF line endings as described above. * General For more information see https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings . Fixes: https://github.com/slimbootloader/slimbootloader/issues/1400 Signed-off-by: Mike Crowe <mac@mcrowe.com>
366 lines
9.0 KiB
C
366 lines
9.0 KiB
C
/** @file
|
|
Shell command `fs` to view partition information
|
|
|
|
Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#include <Library/BootloaderCommonLib.h>
|
|
#include <Library/ShellLib.h>
|
|
#include <Library/PartitionLib.h>
|
|
#include <Library/FileSystemLib.h>
|
|
#include <Library/MediaAccessLib.h>
|
|
#include <Library/ConsoleInLib.h>
|
|
#include <Guid/OsBootOptionGuid.h>
|
|
#include <Library/BootOptionLib.h>
|
|
#include <Guid/DeviceTableHobGuid.h>
|
|
|
|
STATIC OS_BOOT_MEDIUM_TYPE mDeviceType = OsBootDeviceMax;
|
|
STATIC UINT8 mDeviceInstance = 0;
|
|
STATIC EFI_HANDLE mHwPartHandle = NULL;
|
|
STATIC EFI_HANDLE mFsHandle = NULL;
|
|
|
|
/**
|
|
Show media information
|
|
|
|
@param[in] Shell shell instance
|
|
@param[in] Argc number of command line arguments
|
|
@param[in] Argv command line arguments
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
EFI_STATUS
|
|
EFIAPI
|
|
ShellCommandFsFunc (
|
|
IN SHELL *Shell,
|
|
IN UINTN Argc,
|
|
IN CHAR16 *Argv[]
|
|
);
|
|
|
|
CONST SHELL_COMMAND ShellCommandFs = {
|
|
L"fs",
|
|
L"filesystem access command",
|
|
&ShellCommandFsFunc
|
|
};
|
|
|
|
/**
|
|
Print available platform devices
|
|
|
|
@retval none
|
|
|
|
**/
|
|
STATIC
|
|
VOID
|
|
PrintPlatformDevices (
|
|
IN VOID
|
|
)
|
|
{
|
|
PLT_DEVICE_TABLE *DeviceTable;
|
|
UINT16 Count;
|
|
UINT16 Index;
|
|
OS_BOOT_MEDIUM_TYPE DeviceType;
|
|
UINT8 DeviceInstance;
|
|
|
|
Count = 0;
|
|
DeviceTable = (PLT_DEVICE_TABLE *)GetDeviceTable ();
|
|
if (DeviceTable != NULL) {
|
|
Count = DeviceTable->DeviceNumber;
|
|
for (Index = 0; Index < Count; Index++) {
|
|
DeviceType = (OS_BOOT_MEDIUM_TYPE)DeviceTable->Device[Index].Type;
|
|
if (DeviceType >= OsBootDeviceMax)
|
|
continue;
|
|
|
|
DeviceInstance = DeviceTable->Device[Index].Instance;
|
|
ShellPrint (L" %d:%d %a", DeviceType, DeviceInstance, GetBootDeviceNameString (DeviceType));
|
|
if (DeviceTable->Device[Index].Dev.PciDev.IsMmioDevice != 0) {
|
|
ShellPrint (L"(MEM 0x%x)\n", DeviceTable->Device[Index].Dev.DevAddr);
|
|
} else {
|
|
ShellPrint (L"(PCI 0x%x:0x%x:0x%x)\n",
|
|
DeviceTable->Device[Index].Dev.PciDev.PciBusNumber,
|
|
DeviceTable->Device[Index].Dev.PciDev.PciDeviceNumber,
|
|
DeviceTable->Device[Index].Dev.PciDev.PciFunctionNumber);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
Close file system
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
CmdFsClose (
|
|
IN VOID
|
|
)
|
|
{
|
|
if (mFsHandle != NULL) {
|
|
CloseFileSystem (mFsHandle);
|
|
mFsHandle = NULL;
|
|
}
|
|
if (mHwPartHandle != NULL) {
|
|
ClosePartitions (mHwPartHandle);
|
|
mHwPartHandle = NULL;
|
|
}
|
|
|
|
if (mDeviceType != OsBootDeviceMax) {
|
|
// De-init the current media device
|
|
// If USB keyboard console is used, don't DeInit USB yet.
|
|
if (!((mDeviceType == OsBootDeviceUsb) &&
|
|
((PcdGet32 (PcdConsoleInDeviceMask) & ConsoleInUsbKeyboard) != 0))) {
|
|
MediaInitialize (0, DevDeinit);
|
|
}
|
|
mDeviceType = OsBootDeviceMax;
|
|
mDeviceInstance = 0;
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
Initialize file system
|
|
|
|
@param[in] DeviceType Platform Device Index
|
|
@param[in] DeviceInstance The device instance number starting from 0.
|
|
@param[in] HwPartNo HW Partition Number
|
|
@param[in] SwPartNo SW Partition Number
|
|
|
|
@retval EFI_SUCCESS FS init success
|
|
@retval Others Error
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
CmdFsInit (
|
|
IN OS_BOOT_MEDIUM_TYPE DeviceType,
|
|
IN UINT8 DeviceInstance,
|
|
IN UINT32 HwPartNo,
|
|
IN UINT32 SwPartNo
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
OS_FILE_SYSTEM_TYPE FsType;
|
|
UINTN BaseAddress;
|
|
|
|
// Get device bar
|
|
BaseAddress = GetDeviceAddr (DeviceType, DeviceInstance);
|
|
if (BaseAddress == 0) {
|
|
ShellPrint (L"Device no. %d (%a) is not in platform devices. <device no.> - ",
|
|
DeviceType, GetBootDeviceNameString (DeviceType));
|
|
PrintPlatformDevices ();
|
|
return EFI_ABORTED;
|
|
} else if (!(BaseAddress & 0xFF000000)) {
|
|
BaseAddress = TO_MM_PCI_ADDRESS (BaseAddress);
|
|
}
|
|
|
|
if (mDeviceType != OsBootDeviceMax) {
|
|
CmdFsClose ();
|
|
}
|
|
|
|
// Set media interface
|
|
Status = MediaSetInterfaceType (DeviceType);
|
|
if (EFI_ERROR (Status)) {
|
|
return Status;
|
|
}
|
|
|
|
Status = MediaInitialize (BaseAddress, DevInitAll);
|
|
ShellPrint (L"Media(%a) Init ", GetBootDeviceNameString (DeviceType));
|
|
mDeviceType = DeviceType;
|
|
mDeviceInstance = DeviceInstance;
|
|
if (!EFI_ERROR (Status)) {
|
|
ShellPrint (L"Success!\n");
|
|
} else {
|
|
ShellPrint (L"Fail!\n");
|
|
goto Error;
|
|
}
|
|
|
|
// Find a partition
|
|
ShellPrint (L"Find a Partition\n");
|
|
Status = FindPartitions (HwPartNo, &mHwPartHandle);
|
|
ShellPrint (L"Partition Detect (device:%d, hwpart:%d) ", mDeviceType, HwPartNo);
|
|
if (!EFI_ERROR (Status)) {
|
|
ShellPrint (L"Success!\n");
|
|
} else {
|
|
ShellPrint (L"Fail!\n");
|
|
goto Error;
|
|
}
|
|
|
|
ShellPrint (L"Init FileSystem\n");
|
|
Status = InitFileSystem (SwPartNo, EnumFileSystemTypeAuto, mHwPartHandle, &mFsHandle);
|
|
ShellPrint (L"FileSystem Detect (device:%d, hwpart:%d, swpart:%d) ",
|
|
mDeviceType, HwPartNo, SwPartNo);
|
|
if (!EFI_ERROR (Status)) {
|
|
FsType = GetFileSystemType (mFsHandle);
|
|
ShellPrint (L"Success! (%a)\n", GetFsTypeString (FsType));
|
|
} else {
|
|
ShellPrint (L"Fail!\n");
|
|
goto Error;
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
Error:
|
|
CmdFsClose ();
|
|
return Status;
|
|
}
|
|
|
|
/**
|
|
Print directory or file list
|
|
|
|
@retval EFI_SUCCESS
|
|
@retval EFI_ABORTED
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
CmdFsFsListDir (
|
|
IN CHAR16 *DirFilePath
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
|
|
if (mFsHandle == NULL) {
|
|
ShellPrint (L"FileSystem is not initialized!\n");
|
|
return EFI_ABORTED;
|
|
}
|
|
|
|
Status = ListDir (mFsHandle, DirFilePath);
|
|
if (Status == EFI_NOT_FOUND) {
|
|
ShellPrint (L"Not found!\n");
|
|
} else if (Status == EFI_UNSUPPORTED) {
|
|
ShellPrint (L"This command has been disabled.\n");
|
|
}
|
|
return EFI_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
Display current filesystem info
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
STATIC
|
|
EFI_STATUS
|
|
CmdFsInfo (
|
|
IN VOID
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
UINT32 HwPartNo;
|
|
UINT32 SwPartNo;
|
|
OS_FILE_SYSTEM_TYPE FsType;
|
|
|
|
ShellPrint (L"Current DeviceType: %a\n", (mDeviceType != OsBootDeviceMax) ?
|
|
GetBootDeviceNameString (mDeviceType) : "Not Initialized");
|
|
|
|
ShellPrint (L"Current DeviceInstance: %d\n", mDeviceInstance);
|
|
|
|
ShellPrint (L"Current HwPart: ");
|
|
Status = GetPartitionCurrentPartNo (mHwPartHandle, &HwPartNo);
|
|
if (!EFI_ERROR (Status)) {
|
|
ShellPrint (L"%d\n", HwPartNo);
|
|
} else {
|
|
ShellPrint (L"Not Initialized\n");
|
|
}
|
|
|
|
ShellPrint (L"Current SwPart: ");
|
|
Status = GetFileSystemCurrentPartNo (mFsHandle, &SwPartNo);
|
|
if (!EFI_ERROR (Status)) {
|
|
ShellPrint (L"%d\n", SwPartNo);
|
|
} else {
|
|
ShellPrint (L"Not Initialized\n");
|
|
}
|
|
|
|
FsType = GetFileSystemType (mFsHandle);
|
|
ShellPrint (L"Current FileSystem: %a\n", (FsType != EnumFileSystemMax) ?
|
|
GetFsTypeString (FsType) : "Not Detected");
|
|
|
|
return EFI_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
Basic file system test commands
|
|
|
|
@param[in] Shell shell instance
|
|
@param[in] Argc number of command line arguments
|
|
@param[in] Argv command line arguments
|
|
|
|
@retval EFI_SUCCESS
|
|
|
|
**/
|
|
EFI_STATUS
|
|
EFIAPI
|
|
ShellCommandFsFunc (
|
|
IN SHELL *Shell,
|
|
IN UINTN Argc,
|
|
IN CHAR16 *Argv[]
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
OS_BOOT_MEDIUM_TYPE DeviceType;
|
|
UINT8 DeviceInstance;
|
|
UINT32 HwPartNo;
|
|
UINT32 SwPartNo;
|
|
CHAR16 *SubCmd;
|
|
CHAR16 *String;
|
|
UINTN Result;
|
|
|
|
if (Argc < 2) {
|
|
goto Usage;
|
|
}
|
|
|
|
SubCmd = Argv[1];
|
|
if (StrCmp (SubCmd, L"init") == 0) {
|
|
if (Argc < 3) {
|
|
DeviceType = 0;
|
|
DeviceInstance = 0;
|
|
} else {
|
|
Status = StrHexToUintnS (Argv[2], &String, &Result);
|
|
if (EFI_ERROR (Status)) {
|
|
goto Usage;
|
|
}
|
|
DeviceType = (OS_BOOT_MEDIUM_TYPE)Result;
|
|
|
|
Result = 0;
|
|
if (String[0] == L':') {
|
|
String++;
|
|
Status = StrHexToUintnS (String, NULL, &Result);
|
|
if (EFI_ERROR (Status)) {
|
|
goto Usage;
|
|
}
|
|
}
|
|
DeviceInstance = (UINT8)Result;
|
|
}
|
|
|
|
HwPartNo = (Argc < 4) ? 0 : (UINT32)StrHexToUintn (Argv[3]);
|
|
SwPartNo = (Argc < 5) ? 0 : (UINT32)StrHexToUintn (Argv[4]);
|
|
Status = CmdFsInit (DeviceType, DeviceInstance, HwPartNo, SwPartNo);
|
|
} else if (StrCmp (SubCmd, L"close") == 0) {
|
|
Status = CmdFsClose ();
|
|
} else if (StrCmp (SubCmd, L"ls") == 0) {
|
|
Status = CmdFsFsListDir ((Argc < 3) ? L"/" : Argv[2]);
|
|
} else if (StrCmp (SubCmd, L"info") == 0) {
|
|
Status = CmdFsInfo ();
|
|
} else {
|
|
goto Usage;
|
|
}
|
|
return Status;
|
|
|
|
Usage:
|
|
ShellPrint (L"Usage: %s init [DevType[:DevInstance]] [HwPart] [SwPart]\n", Argv[0]);
|
|
ShellPrint (L" %s close\n", Argv[0]);
|
|
ShellPrint (L" %s info\n", Argv[0]);
|
|
ShellPrint (L" %s ls [dir or file path]\n", Argv[0]);
|
|
|
|
ShellPrint (L"\nDevType:DevInstance - Media type and instance number in the same media type\n");
|
|
PrintPlatformDevices ();
|
|
ShellPrint (L"HwPart - HW partition or port number\n");
|
|
ShellPrint (L"SwPart - Logical partition number from MBR or GPT\n");
|
|
|
|
return EFI_ABORTED;
|
|
}
|