Overview
This is a mruby porting on EFI Shell.
- You can call UEFI functions via wrapper functions of BootService and RuntimeService.
- You can define any native C structure and you can access to the members via the structure.
Notice
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. It may break the system or make your PC unbootable. Please use this software carefully.
How to use
- Download UEFI Shell from Tiano page.
- Put UEFI Shell binary in your USB memory as
EFI\BOOT\BOOTX64.efi
. - Download mruby on EFI Shell from download page.
- Extract it and put it in your USB memory.
- You can run mruby script as follows:
> mruby.efi script.rb
Samples
Calling ResetSystem
of Runtime Service
# Shutdown
# Currently, the name of constants are too long...
UEFI::RuntimeService.reset_system(UEFI::RuntimeService::ResetShutdown, UEFI::Status::SUCCESS)
Defining and calling UEFI native protocols
This is an example of reading disk via EFI_DISK_IO_PROTOCOL
.
You can download entire source code from example/read_disk.rb
.
# This is a part of the source code.
# Any native C structure can be defined.
class DiskIoProtocol < UEFI::Protocol
# DiskIoProtocol: http://wiki.phoenix.com/wiki/index.php/EFI_DISK_IO_PROTOCOL
GUID = UEFI::Guid.new("CE345171-BA0B-11d2-8e4F-00a0c969723b")
define_variable(:revision, :u64)
define_function(:read_disk, :efi_status, [:p, :u32, :u64, :u64, :p])
#...
end
# (snip)
# Now, `handle` contains the Handle of DiskIoProtocol,
# `media_id` contains ID of the disk.
puts "handle: #{handle}"
puts "media_id: #{media_id}"
# Find DiskIoProtocol via HandleProtocol.
ptr = UEFI::BootService.handle_protocol(handle, DiskIoProtocol::GUID)
dp = DiskIoProtocol.new(ptr)
buf = " " * 512 # Buffer to be filled with returned data.
st = dp.read_disk(ptr, media_id, 0, buf.size, buf)
if (st.success?)
print_binary_data(buf)
else
puts "ERROR: #{st}"
end
The result is as follows:
Reference
[T.B.D.]
License
Same as mruby, MIT License.
Copyright (c) 2013 Masamitsu MURASE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.