35 Commits

Author SHA1 Message Date
Randy
240ff8df7c fix: osloader can't boot on new yocto build
Ext2Fs->Ext2FsFeaturesIncompat report EXT2F_INCOMPAT_CSUM_SEED
so that fail into not support.

boot tested with old/new yocto image, ubuntu.

Signed-off-by: Randy <randy.lin@intel.com>
2024-10-16 14:03:13 -07:00
tsaikevin
d952b1487c fix: [Common] Fix Coverity issues (#1978)
Fixed Untrusted loop bound (CWE 606)

Signed-off-by: Kevin Tsai <kevin.tsai@intel.com>
2023-07-31 16:06:00 -07:00
Stanley Chang
a6264ae2c4 [ExtLib] fix the list of symbolic links
This patch fixes 2 issues related to symbolic links:

1. when "fs ls" a directory, symbolic links are not shown.

  It is because Ext2fsLs() only shows regular files and directories.

2. when "fs ls <symbolic_link>" the output is incorrect.

  It is because File->FileNamePtr points to a local variable,
  "NameBuf" in Ext2fsOpen(), if the file is a symbolic link

This patch replaces File->FileNamePtr with FileNameBuf.
It slightly increases Ext2fsLs/Ext2fsOpen/SearchDirectory time,
because of the use of strcpy and strcat.

Test method:

1. create a regular file, "a", in directory "x"
2. create a symbolic link file, "b", pointing to "a".
3. under the shell of OSLoader,
   "fs ls x"
     - expected result: a, b (symbolic link)
   "fs ls x/a"
     - expected result: a and its file size is shown
   "fs ls x/b"
     - expected result: b -> a, and the file size of a is shown

Verify: TGL-UP3 RVP

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
2022-12-05 11:35:37 -07:00
Stanley Chang
aca5762eec [ExtLib] fix the failure of loading files in Ext4 partition
This patch fixes an issue that SBL fails to load a file in Ext4 partition,
when
  1. the ext4 partition uses Extent
  2. the inode's first extent block is an internal node
  3. the node has only one entry (i.e., eh_entries = 1)
Under the above conditions, the data block may point to the child of
first ei_block when accessing the data within the range of child node.

Test method:
  1. Install Ubuntu 20.04.5 LTS/(min install) in an eMMC disk

     Note: this issue is only reproducible when loading a file
     satisfying all conditions mentioned above (i.e., eh_entries = 1).

     So far, the /boot/initrd.img after installing Ubuntu in an eMMC
     (where part table: 500MB(FAT), 20GB (EXT4), 4GB (Swap)) satisfies
     the conditions. However, for some reasons, when using USB SATA disk,
     it will not generate a /boot/initr.rd meeting the conditions.

  2. Boot to OSLoader
  3. "fs init 2:0 0 1" the eMMC disk (assume the HW:SW-part is 0 1)
  4. "fs load boot/initrd.img"

Expected result:
  1. With this patch: successfully load the file.
  2. Without this patch: ASSERT [OsLoader] ..

Verified: EHL CRB

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
2022-11-29 14:55:30 -07:00
Stanley Chang
b6f150c0ea [ExtLib] fix invalid memory access to support large EXT fs (#1739)
This patch fixes an invalid memory access issue caused by
the fs->Ext2FsGDSize is smaller than the size of EXT2GD.

The EXT2GD is a 64-byte structure, but fs->Ext2FsGDSize is not always 32.

Before this patch, Ext2fsOpen() allocates a smaller memory than expected:
  i.e., Ext2FsGrpDes = AllocatePool (Ext2FsGDSize * Ext2FsNumCylinder);
When ReadGDBlock() loads data (E2FS_CGLOAD) into fs->Ext2FsGrpDes,
it possibly accesses mem out of the allocated Ext2FsGrpDes space.

This patch loads each element into fs->Ext2FsGrpDes.

This patch also
1. prints informative messages when OS Loader fails to load Linux files.
2. increase EHL's PLD_HEAP_SIZE (since the size of initrd in Ubuntu LiveCD
   is over 130MB)

Test method:
1. create a huge EXT FS (says, at least 36GB)
2. In the fs, place the following file/dir:
    a: non-empty file
    b: dir
    b/c: non-empty file
3. boot with SBL OS Loader and enter Shell.
4. execute "fs init <...skip...>" to init the fs
5. execute "fs ls"
6. execute "fs ls b/c"
7. execute "fs load a"
8. execute "fs load b/c"

Verify:
1. 10MB/10GB/100GB/200GB EXT2/EXT3/EXT4 FS
2. EHL CRB

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
2022-11-14 08:33:16 -07:00
Mike Crowe
990e3e81e6 Use LF line endings in the repository
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>
2021-11-10 12:46:42 -08:00
Maurice Ma
f4a184ef35 Enhance Ext2 filesystem library
For EXT2 filesystem revision 0, there are some fixed fields in the
super block structure according to the documentation. The code should
always use those fixed values for safe regardless of the value inside
the image.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2021-11-05 07:27:13 -07:00
Stanley Chang
3a02cd0f45 Add EXT FS check in initialization
This patch runs basic check during EXT FS initialization
by opening root directory to ensure superblock been
validated.

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
2021-05-21 20:11:53 -07:00
Stanley Chang
19123314d5 Fix return code of SearchDirectory
This patch changes the return code of SearchDirectory
to EFI_NOT_FOUND when a file to search cannot be found

Signed-off-by: Stanley Chang <stanley.chang@intel.com>
2021-05-19 07:12:16 -07:00
James Gutbub
738f946aac Allow Ext23Lib symbolic links to have longer paths
In the Ext23Lib support for symbolic links was recently enabled
but there was a limitation imposed to use the CFG data boot
option filepath limit of 16 bytes which does not need to be also
be imposed on symbolic link paths. This will allow symbolic link
paths to be up to 260 characters long.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2021-04-29 19:33:09 -07:00
James Gutbub
10b1685dc5 Add support for symbolic links to Ext23Lib
Some of the boot option file paths used when
booting with OS Loader payload are failing
because the Ext23Lib does not support symbolic
soft links (e.g. ln -s <file> <link>). This
patch adds support for loading the soft link
succesfully.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2021-04-15 08:32:34 -07:00
Maurice Ma
99332b68dc Fix new Klocwork scanning issues
This patch fixed some new reported klocwork scanning issues.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2020-08-25 09:57:23 -07:00
Aiden Park
f1d04b0dcd Print file size in unsigned format in 'fs ls'
File size shows negative number, so unsigned print format is used.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-06-17 15:13:18 -07:00
Aiden Park
e99762353a Introduce CONSOLE_PRINT macro (#701)
This will allow necessary messages to be printed to consoles.

These macros will redirect debug message to consoles.
  CONSOLE_PRINT
  CONSOLE_PRINT_UNICODE

These conditional macros will redirect debug message to consoles or
DEBUG(). The PrintLevel is valid only when redirected to DEBUG().
  CONSOLE_PRINT_CONDITION
  CONSOLE_PRINT_UNICODE_CONDITION

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-05-04 14:53:08 -07:00
Aiden Park
3ec0361920 Fix pointer type cast errors from Visual Studio (#617)
Visual Studio reports more pointer type cast errors with 64-bit build.
This will cover the issue on the existing targets.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-03-27 11:03:28 -07:00
Aiden Park
29446a1c2a Pointer type cast for both 32/64-bit operation (#615)
This patch allows both 32/64-bit addressing properly.
- Pointer type cast with UINTN
- Add missing EFIAPI for APIs

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-03-26 17:30:55 -07:00
Maurice Ma
faa172e67e Add missing header files in INF
In order to sync up with EDK201911 stable release, it is required
to add missing header files in the INF file. Otherwise, the build
will throw warnings. This patch added the missing headers in INF
files.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2020-02-03 15:49:48 -08:00
Aiden Park
b24fd2759c Cosmetic: Convert LF to CRLF
This will fully support PatchCheck.py.
- Remove all trailing whitespace
- Convert LF to CRLF by default
- Update EFI_D_* to DEBUG_*
- Re-enable CRLF check in PatchCheck.py

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-12-02 16:21:19 -08:00
Aiden Park
40754d582e CmdFs: Support display console print in 'fs ls' (#428)
This allows 'fs ls' command to print directory or file lists to both serial
and display console according to CONSOLE_OUT_DEVICE_MASK.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-03 21:44:58 -08:00
Aiden Park
f6a5597397 'fs ls' aligns a filename with 16 chars fixed size
This patch will print a filename with 16 chars aligned size.
- left justified filename with padding up to 16 chars
- length of filename > 16 chars, full filename is printed as it is

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-10-30 17:13:08 -07:00
Aiden Park
4bc6dd2f02 [ExtLib] Update coding convention in function definition
This patch updates function/APIs definition and comment syntax
with EDK coding convention.
- No functional changes
- Remove unused funtions

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-10-30 17:13:08 -07:00
Aiden Park
9c3b81a64d Add FS (File System) shell command
This 'fs' shell command can be used for basic file system check.

Usage: fs init [device no.] [hwpart no.] [swpart no.]
       fs close
       fs info
       fs ls [dir or file path]

- 'device no.' is from Platform Device Table.
- all 0s by default if 'fs init' has no parameters
- root dir by default if 'fs ls' has no dir or file path

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-10-30 17:13:08 -07:00
James Gutbub
2a28a0d3df Clean up EXT library
The EXT library has some unused code that
we can remove to help reduce the size and
to clean things up some more. Also add a
routine for dumping the group descriptor
table which can be helpful for debugging
issues.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-10-09 11:56:09 -07:00
James Gutbub
5ca06f0d92 Support 64bit EXT FS & non-512 block sizes
EXT2/3 library has some limiatation to support
hardware block sizes larger than 512 (e.g. 4KB)
and also does not currently support the flag
INCOMPAT_64BIT which indicates larger group
descriptor sizes. This patch adds flexibility
to support 512 and 4KB block sizes as well as
64bit EXT file systems.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-10-08 17:23:59 -07:00
Aiden Park
b17c6c29b1 Fix compile errors when disabling compile optimization
- 'OpenFile may be used uninitialized' in ExtLib
- 'undefined reference to memcpy' in FatLib
- 'Lasa/Laml may be used uninitialized' in TpmLib
- 'Adjust may be used uninitialized' in Stage2Support

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-09-29 22:26:22 -07:00