mirror of
https://github.com/edk2-porting/edk2-rk3588.git
synced 2026-01-13 07:50:43 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbf783223f | ||
|
|
eff37d1c6a | ||
|
|
3e4234ac61 | ||
|
|
8d3257255d | ||
|
|
06408b6bf6 | ||
|
|
c52b05713a | ||
|
|
b7898949e7 | ||
|
|
76d4032bb0 | ||
|
|
a80e23a23e | ||
|
|
c9563d7748 |
14
README.md
14
README.md
@@ -317,6 +317,20 @@ This has been observed in cases where firmware was present on more than one devi
|
||||
|
||||
**Note:** the number of eFuses is limited, thus MAC addresses can only be changed a few times.
|
||||
|
||||
### Wi-Fi / Bluetooth not working on mainline Linux
|
||||
The most likely cause is missing upstream firmware support. Check `dmesg` for messages that indicate firmware load errors.
|
||||
|
||||
This can usually be fixed by manually copying the necessary blobs to `/usr/lib/firmware`.
|
||||
|
||||
For instance, on Khadas Edge2 with an onboard AP6275P module (BCM/SYN43752):
|
||||
```bash
|
||||
sudo wget https://github.com/armbian/firmware/raw/refs/heads/master/brcm/brcmfmac43752-pcie.bin -P /usr/lib/firmware/brcm/
|
||||
sudo wget https://github.com/armbian/firmware/raw/refs/heads/master/brcm/brcmfmac43752-pcie.clm_blob -P /usr/lib/firmware/brcm/
|
||||
sudo wget https://github.com/armbian/firmware/raw/refs/heads/master/brcm/brcmfmac43752-pcie.txt -P /usr/lib/firmware/brcm/
|
||||
sudo wget https://github.com/armbian/firmware/raw/refs/heads/master/brcm/BCM4362A2.hcd -P /usr/lib/firmware/brcm/
|
||||
```
|
||||
then reboot.
|
||||
|
||||
## Advanced troubleshooting
|
||||
The firmware will log detailed information to the serial console when using a debug version. See the [release notes](https://github.com/edk2-porting/edk2-rk3588/releases) for details on how to obtain this version.
|
||||
|
||||
|
||||
140
devicetree/mainline/rk3588-orangepi-5-plus-fixup.dts
Normal file
140
devicetree/mainline/rk3588-orangepi-5-plus-fixup.dts
Normal file
@@ -0,0 +1,140 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
#include "rk3588-orangepi-5-plus.dts"
|
||||
|
||||
/ {
|
||||
vbus5v0_typec: regulator-vbus5v0-typec {
|
||||
compatible = "regulator-fixed";
|
||||
regulator-name = "vbus5v0_typec";
|
||||
regulator-boot-on;
|
||||
regulator-min-microvolt = <5000000>;
|
||||
regulator-max-microvolt = <5000000>;
|
||||
enable-active-high;
|
||||
gpio = <&gpio4 RK_PB0 GPIO_ACTIVE_HIGH>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&typec5v_pwren>;
|
||||
vin-supply = <&vcc5v0_sys>;
|
||||
};
|
||||
};
|
||||
|
||||
&i2c6 {
|
||||
fusb302: typec-portc@22 {
|
||||
compatible = "fcs,fusb302";
|
||||
reg = <0x22>;
|
||||
interrupt-parent = <&gpio0>;
|
||||
interrupts = <RK_PD3 IRQ_TYPE_LEVEL_LOW>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&usbc0_int>;
|
||||
vbus-supply = <&vbus5v0_typec>;
|
||||
|
||||
usb_con: connector {
|
||||
compatible = "usb-c-connector";
|
||||
data-role = "dual";
|
||||
label = "USB-C";
|
||||
power-role = "source";
|
||||
source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)>;
|
||||
|
||||
ports {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
port@0 {
|
||||
reg = <0>;
|
||||
|
||||
usbc0_orien_sw: endpoint {
|
||||
remote-endpoint = <&usbdp_phy0_orientation_switch>;
|
||||
};
|
||||
};
|
||||
|
||||
port@1 {
|
||||
reg = <1>;
|
||||
|
||||
usbc0_role_sw: endpoint {
|
||||
remote-endpoint = <&dwc3_0_role_switch>;
|
||||
};
|
||||
};
|
||||
|
||||
port@2 {
|
||||
reg = <2>;
|
||||
|
||||
dp_altmode_mux: endpoint {
|
||||
remote-endpoint = <&usbdp_phy0_dp_altmode_mux>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&pinctrl {
|
||||
usb-typec {
|
||||
usbc0_int: usbc0-int {
|
||||
rockchip,pins = <0 RK_PD3 RK_FUNC_GPIO &pcfg_pull_up>;
|
||||
};
|
||||
|
||||
typec5v_pwren: typec5v-pwren {
|
||||
rockchip,pins = <4 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&u2phy0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&u2phy0_otg {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&u2phy1 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&u2phy1_otg {
|
||||
phy-supply = <&vcc5v0_usb20>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&usbdp_phy0 {
|
||||
mode-switch;
|
||||
orientation-switch;
|
||||
sbu1-dc-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>;
|
||||
sbu2-dc-gpios = <&gpio4 RK_PA7 GPIO_ACTIVE_HIGH>;
|
||||
status = "okay";
|
||||
|
||||
port {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
usbdp_phy0_orientation_switch: endpoint@0 {
|
||||
reg = <0>;
|
||||
remote-endpoint = <&usbc0_orien_sw>;
|
||||
};
|
||||
|
||||
usbdp_phy0_dp_altmode_mux: endpoint@1 {
|
||||
reg = <1>;
|
||||
remote-endpoint = <&dp_altmode_mux>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&usbdp_phy1 {
|
||||
phy-supply = <&vcc5v0_usb20>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&usb_host0_xhci {
|
||||
usb-role-switch;
|
||||
status = "okay";
|
||||
|
||||
port {
|
||||
dwc3_0_role_switch: endpoint {
|
||||
remote-endpoint = <&usbc0_role_sw>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&usb_host1_xhci {
|
||||
dr_mode = "host";
|
||||
status = "okay";
|
||||
};
|
||||
80
devicetree/mainline/rk3588-rock-5-itx-fixup.dts
Normal file
80
devicetree/mainline/rk3588-rock-5-itx-fixup.dts
Normal file
@@ -0,0 +1,80 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
#include <dt-bindings/soc/rockchip,vop2.h>
|
||||
#include "rk3588-rock-5-itx.dts"
|
||||
|
||||
/ {
|
||||
/delete-node/ pcie-oscillator;
|
||||
|
||||
hdmi0-con {
|
||||
compatible = "hdmi-connector";
|
||||
type = "a";
|
||||
|
||||
port {
|
||||
hdmi0_con_in: endpoint {
|
||||
remote-endpoint = <&hdmi0_out_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Remove the "pcie30_refclk" gated-fixed-clock to maintain compatibility
|
||||
* with kernels older than v6.13-rc1. It is backed by a GPIO regulator
|
||||
* anyway, so simply referencing it in vpcie3v3-supply also addresses
|
||||
* the potential issue where pcie3x2 might probe earlier than pcie3x4 and
|
||||
* hang on DBI access because the clock didn't have a chance to be enabled.
|
||||
*/
|
||||
&pcie3x2 {
|
||||
clocks = <&cru ACLK_PCIE_2L_MSTR>, <&cru ACLK_PCIE_2L_SLV>,
|
||||
<&cru ACLK_PCIE_2L_DBI>, <&cru PCLK_PCIE_2L>,
|
||||
<&cru CLK_PCIE_AUX1>, <&cru CLK_PCIE2L_PIPE>;
|
||||
clock-names = "aclk_mst", "aclk_slv",
|
||||
"aclk_dbi", "pclk",
|
||||
"aux", "pipe";
|
||||
vpcie3v3-supply = <&vcc3v3_pi6c_05>;
|
||||
};
|
||||
|
||||
&pcie3x4 {
|
||||
clocks = <&cru ACLK_PCIE_4L_MSTR>, <&cru ACLK_PCIE_4L_SLV>,
|
||||
<&cru ACLK_PCIE_4L_DBI>, <&cru PCLK_PCIE_4L>,
|
||||
<&cru CLK_PCIE_AUX0>, <&cru CLK_PCIE4L_PIPE>;
|
||||
clock-names = "aclk_mst", "aclk_slv",
|
||||
"aclk_dbi", "pclk",
|
||||
"aux", "pipe";
|
||||
};
|
||||
|
||||
&hdmi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&hdmi0_in {
|
||||
hdmi0_in_vp0: endpoint {
|
||||
remote-endpoint = <&vp0_out_hdmi0>;
|
||||
};
|
||||
};
|
||||
|
||||
&hdmi0_out {
|
||||
hdmi0_out_con: endpoint {
|
||||
remote-endpoint = <&hdmi0_con_in>;
|
||||
};
|
||||
};
|
||||
|
||||
&hdptxphy_hdmi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vop_mmu {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vop {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vp0 {
|
||||
vp0_out_hdmi0: endpoint@ROCKCHIP_VOP2_EP_HDMI0 {
|
||||
reg = <ROCKCHIP_VOP2_EP_HDMI0>;
|
||||
remote-endpoint = <&hdmi0_in_vp0>;
|
||||
};
|
||||
};
|
||||
271
devicetree/mainline/rk3588s-khadas-edge2-fixup.dts
Normal file
271
devicetree/mainline/rk3588s-khadas-edge2-fixup.dts
Normal file
@@ -0,0 +1,271 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
#include <dt-bindings/soc/rockchip,vop2.h>
|
||||
#include <dt-bindings/usb/pd.h>
|
||||
#include "rk3588s-khadas-edge2.dts"
|
||||
|
||||
/ {
|
||||
analog-sound {
|
||||
compatible = "audio-graph-card";
|
||||
label = "rk3588-es8316";
|
||||
|
||||
widgets = "Microphone", "Mic Jack",
|
||||
"Headphone", "Headphones";
|
||||
|
||||
routing = "MIC2", "Mic Jack",
|
||||
"Headphones", "HPOL",
|
||||
"Headphones", "HPOR";
|
||||
|
||||
dais = <&i2s0_8ch_p0>;
|
||||
hp-det-gpios = <&gpio1 RK_PD3 GPIO_ACTIVE_LOW>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&hp_detect>;
|
||||
};
|
||||
|
||||
hdmi0-con {
|
||||
compatible = "hdmi-connector";
|
||||
type = "a";
|
||||
|
||||
port {
|
||||
hdmi0_con_in: endpoint {
|
||||
remote-endpoint = <&hdmi0_out_con>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vbus5v0_typec: regulator-vbus5v0-typec {
|
||||
compatible = "regulator-fixed";
|
||||
regulator-name = "vbus5v0_typec";
|
||||
regulator-boot-on;
|
||||
regulator-min-microvolt = <5000000>;
|
||||
regulator-max-microvolt = <5000000>;
|
||||
enable-active-high;
|
||||
gpio = <&gpio3 RK_PA4 GPIO_ACTIVE_HIGH>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&typec5v_pwren>;
|
||||
vin-supply = <&vcc5v0_sys>;
|
||||
};
|
||||
};
|
||||
|
||||
&i2c2 {
|
||||
fusb302: typec-portc@22 {
|
||||
compatible = "fcs,fusb302";
|
||||
reg = <0x22>;
|
||||
interrupt-parent = <&gpio1>;
|
||||
interrupts = <RK_PB5 IRQ_TYPE_LEVEL_LOW>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&usbc0_int>;
|
||||
vbus-supply = <&vbus5v0_typec>;
|
||||
|
||||
usb_con: connector {
|
||||
compatible = "usb-c-connector";
|
||||
data-role = "dual";
|
||||
label = "USB-C";
|
||||
power-role = "dual";
|
||||
try-power-role = "source";
|
||||
op-sink-microwatt = <1000000>;
|
||||
sink-pdos =
|
||||
<PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)
|
||||
PDO_FIXED(9000, 3000, PDO_FIXED_USB_COMM)
|
||||
PDO_FIXED(12000, 3000, PDO_FIXED_USB_COMM)>;
|
||||
source-pdos =
|
||||
<PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)>;
|
||||
|
||||
ports {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
port@0 {
|
||||
reg = <0>;
|
||||
|
||||
usbc0_orien_sw: endpoint {
|
||||
remote-endpoint = <&usbdp_phy0_orientation_switch>;
|
||||
};
|
||||
};
|
||||
|
||||
port@1 {
|
||||
reg = <1>;
|
||||
|
||||
usbc0_role_sw: endpoint {
|
||||
remote-endpoint = <&dwc3_0_role_switch>;
|
||||
};
|
||||
};
|
||||
|
||||
port@2 {
|
||||
reg = <2>;
|
||||
|
||||
dp_altmode_mux: endpoint {
|
||||
remote-endpoint = <&usbdp_phy0_dp_altmode_mux>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&i2c3 {
|
||||
status = "okay";
|
||||
|
||||
es8316: audio-codec@10 {
|
||||
compatible = "everest,es8316";
|
||||
reg = <0x10>;
|
||||
clocks = <&cru I2S0_8CH_MCLKOUT>;
|
||||
clock-names = "mclk";
|
||||
assigned-clocks = <&cru I2S0_8CH_MCLKOUT>;
|
||||
assigned-clock-rates = <12288000>;
|
||||
#sound-dai-cells = <0>;
|
||||
|
||||
port {
|
||||
es8316_p0_0: endpoint {
|
||||
remote-endpoint = <&i2s0_8ch_p0_0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&i2s0_8ch {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&i2s0_lrck
|
||||
&i2s0_mclk
|
||||
&i2s0_sclk
|
||||
&i2s0_sdi0
|
||||
&i2s0_sdo0>;
|
||||
status = "okay";
|
||||
|
||||
i2s0_8ch_p0: port {
|
||||
i2s0_8ch_p0_0: endpoint {
|
||||
dai-format = "i2s";
|
||||
mclk-fs = <256>;
|
||||
remote-endpoint = <&es8316_p0_0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&pinctrl {
|
||||
usb-typec {
|
||||
usbc0_int: usbc0-int {
|
||||
rockchip,pins = <1 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>;
|
||||
};
|
||||
|
||||
typec5v_pwren: typec5v-pwren {
|
||||
rockchip,pins = <3 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
};
|
||||
|
||||
sound {
|
||||
hp_detect: hp-detect {
|
||||
rockchip,pins = <1 RK_PD3 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
};
|
||||
|
||||
bluetooth {
|
||||
bt_reset: bt-reset {
|
||||
rockchip,pins = <0 RK_PD4 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
|
||||
bt_dev_wake: bt-dev-wake {
|
||||
rockchip,pins = <0 RK_PD3 RK_FUNC_GPIO &pcfg_pull_none>;
|
||||
};
|
||||
|
||||
bt_host_wake: bt-host-wake {
|
||||
rockchip,pins = <0 RK_PD5 RK_FUNC_GPIO &pcfg_pull_down>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&uart9 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&uart9m2_xfer>, <&uart9m2_rtsn>, <&uart9m2_ctsn>;
|
||||
uart-has-rtscts;
|
||||
|
||||
bluetooth {
|
||||
compatible = "brcm,bcm43752-bt", "cypress,cyw4373a0-bt";
|
||||
max-speed = <4000000>;
|
||||
clocks = <&hym8563>;
|
||||
clock-names = "lpo";
|
||||
shutdown-gpios = <&gpio0 RK_PD4 GPIO_ACTIVE_HIGH>;
|
||||
device-wakeup-gpios = <&gpio0 RK_PD3 GPIO_ACTIVE_HIGH>;
|
||||
interrupt-parent = <&gpio0>;
|
||||
interrupts = <RK_PD5 IRQ_TYPE_LEVEL_HIGH>;
|
||||
interrupt-names = "host-wakeup";
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&bt_reset>, <&bt_dev_wake>, <&bt_host_wake>;
|
||||
};
|
||||
};
|
||||
|
||||
&u2phy0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&u2phy0_otg {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&usbdp_phy0 {
|
||||
mode-switch;
|
||||
orientation-switch;
|
||||
sbu1-dc-gpios = <&gpio4 RK_PA0 GPIO_ACTIVE_HIGH>;
|
||||
sbu2-dc-gpios = <&gpio4 RK_PA1 GPIO_ACTIVE_HIGH>;
|
||||
status = "okay";
|
||||
|
||||
port {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
usbdp_phy0_orientation_switch: endpoint@0 {
|
||||
reg = <0>;
|
||||
remote-endpoint = <&usbc0_orien_sw>;
|
||||
};
|
||||
|
||||
usbdp_phy0_dp_altmode_mux: endpoint@1 {
|
||||
reg = <1>;
|
||||
remote-endpoint = <&dp_altmode_mux>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&usb_host0_xhci {
|
||||
usb-role-switch;
|
||||
status = "okay";
|
||||
|
||||
port {
|
||||
dwc3_0_role_switch: endpoint {
|
||||
remote-endpoint = <&usbc0_role_sw>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&hdmi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&hdmi0_in {
|
||||
hdmi0_in_vp0: endpoint {
|
||||
remote-endpoint = <&vp0_out_hdmi0>;
|
||||
};
|
||||
};
|
||||
|
||||
&hdmi0_out {
|
||||
hdmi0_out_con: endpoint {
|
||||
remote-endpoint = <&hdmi0_con_in>;
|
||||
};
|
||||
};
|
||||
|
||||
&hdptxphy_hdmi0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vop_mmu {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vop {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&vp0 {
|
||||
vp0_out_hdmi0: endpoint@ROCKCHIP_VOP2_EP_HDMI0 {
|
||||
reg = <ROCKCHIP_VOP2_EP_HDMI0>;
|
||||
remote-endpoint = <&hdmi0_in_vp0>;
|
||||
};
|
||||
};
|
||||
@@ -83,8 +83,11 @@
|
||||
# PCIe/SATA/USB Combo PIPE PHY support flags and default values
|
||||
# NanoPC CM3588 has one 2.5 GBE wired to the first PCIE2 port
|
||||
#
|
||||
gRK3588TokenSpaceGuid.PcdPcie30PhyModeDefault|$(PCIE30_PHY_MODE_NABIBI)
|
||||
gRK3588TokenSpaceGuid.PcdPcie30x2Supported|TRUE
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy0Switchable|FALSE
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy0ModeDefault|$(COMBO_PHY_MODE_PCIE)
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy2ModeDefault|$(COMBO_PHY_MODE_USB3)
|
||||
|
||||
#
|
||||
# USB/DP Combo PHY support flags and default values
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
[Sources]
|
||||
devicetree/mainline/upstream/src/arm64/rockchip/rk3588s-khadas-edge2.dts
|
||||
devicetree/mainline/rk3588s-khadas-edge2-fixup.dts
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
[Sources]
|
||||
devicetree/mainline/upstream/src/arm64/rockchip/rk3588-orangepi-5-plus.dts
|
||||
devicetree/mainline/rk3588-orangepi-5-plus-fixup.dts
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
[Sources]
|
||||
devicetree/mainline/upstream/src/arm64/rockchip/rk3588-rock-5-itx.dts
|
||||
devicetree/mainline/rk3588-rock-5-itx-fixup.dts
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
@@ -241,6 +241,9 @@ PcieIoInit (
|
||||
GpioPinSetDirection (1, GPIO_PIN_PA4, GPIO_PIN_OUTPUT);
|
||||
// PciePinmuxInit(Segment, 1);
|
||||
break;
|
||||
case PCIE_SEGMENT_PCIE30X2:
|
||||
GpioPinSetDirection (4, GPIO_PIN_PB0, GPIO_PIN_OUTPUT);
|
||||
break;
|
||||
case PCIE_SEGMENT_PCIE20L0:
|
||||
GpioPinSetDirection (4, GPIO_PIN_PA5, GPIO_PIN_OUTPUT);
|
||||
GpioPinSetDirection (1, GPIO_PIN_PD2, GPIO_PIN_OUTPUT);
|
||||
@@ -296,6 +299,9 @@ PciePeReset (
|
||||
case PCIE_SEGMENT_PCIE30X4:
|
||||
GpioPinWrite (4, GPIO_PIN_PB6, !Enable);
|
||||
break;
|
||||
case PCIE_SEGMENT_PCIE30X2:
|
||||
GpioPinWrite (4, GPIO_PIN_PB0, !Enable);
|
||||
break;
|
||||
case PCIE_SEGMENT_PCIE20L0: // m.2 a+e key
|
||||
GpioPinWrite (4, GPIO_PIN_PA5, !Enable);
|
||||
break;
|
||||
|
||||
@@ -87,6 +87,8 @@
|
||||
#
|
||||
# PCIe/SATA/USB Combo PIPE PHY support flags and default values
|
||||
#
|
||||
gRK3588TokenSpaceGuid.PcdPcie30PhyModeDefault|$(PCIE30_PHY_MODE_NANBNB)
|
||||
gRK3588TokenSpaceGuid.PcdPcie30x2Supported|TRUE
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy0Switchable|FALSE
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy1Switchable|FALSE
|
||||
gRK3588TokenSpaceGuid.PcdComboPhy2Switchable|FALSE
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2024-2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
**/
|
||||
|
||||
#ifndef __EXIT_BOOT_SERVICES_HOOK_H__
|
||||
#define __EXIT_BOOT_SERVICES_HOOK_H__
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/ExitBootServicesOsNotify.h>
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
LIST_ENTRY Link;
|
||||
EXIT_BOOT_SERVICES_OS_HANDLER Handler;
|
||||
} EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY;
|
||||
#define EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_SIGNATURE SIGNATURE_32('E', 'b', 'S', 'h')
|
||||
#define EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_FROM_LINK(a) \
|
||||
CR (a, EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY, Link, EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_SIGNATURE)
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL Notify;
|
||||
LIST_ENTRY Handlers;
|
||||
} EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE;
|
||||
#define EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_SIGNATURE SIGNATURE_32('E', 'b', 'S', 'n')
|
||||
#define EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_FROM_THIS(a) \
|
||||
CR (a, EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE, Notify, EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_SIGNATURE)
|
||||
|
||||
EFI_PHYSICAL_ADDRESS
|
||||
FindPeImageBase (
|
||||
IN EFI_PHYSICAL_ADDRESS Base
|
||||
);
|
||||
|
||||
EXIT_BOOT_SERVICES_OS_TYPE
|
||||
IdentifyOsType (
|
||||
IN EFI_PHYSICAL_ADDRESS OsLoaderAddress
|
||||
);
|
||||
|
||||
CHAR8 *
|
||||
OsTypeToString (
|
||||
IN EXIT_BOOT_SERVICES_OS_TYPE OsType
|
||||
);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,165 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2024-2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
**/
|
||||
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
#include "ExitBootServicesHook.h"
|
||||
|
||||
STATIC EFI_EXIT_BOOT_SERVICES mOriginalExitBootServices;
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RegisterHandler (
|
||||
IN EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *This,
|
||||
IN EXIT_BOOT_SERVICES_OS_HANDLER Handler
|
||||
)
|
||||
{
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE *Instance;
|
||||
LIST_ENTRY *Link;
|
||||
EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY *Entry;
|
||||
|
||||
if (Handler == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_FROM_THIS (This);
|
||||
|
||||
for ( Link = GetFirstNode (&Instance->Handlers)
|
||||
; !IsNull (&Instance->Handlers, Link)
|
||||
; Link = GetNextNode (&Instance->Handlers, Link)
|
||||
)
|
||||
{
|
||||
Entry = EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_FROM_LINK (Link);
|
||||
if (Entry->Handler == Handler) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT (IsNull (&Instance->Handlers, Link));
|
||||
Entry = AllocatePool (sizeof (*Entry));
|
||||
if (Entry == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Entry->Signature = EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_SIGNATURE;
|
||||
Entry->Handler = Handler;
|
||||
InsertTailList (&Instance->Handlers, &Entry->Link);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UnregisterHandler (
|
||||
IN EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *This,
|
||||
IN EXIT_BOOT_SERVICES_OS_HANDLER Handler
|
||||
)
|
||||
{
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE *Instance;
|
||||
LIST_ENTRY *Link;
|
||||
EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY *Entry;
|
||||
|
||||
if (Handler == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_FROM_THIS (This);
|
||||
|
||||
for ( Link = GetFirstNode (&Instance->Handlers)
|
||||
; !IsNull (&Instance->Handlers, Link)
|
||||
; Link = GetNextNode (&Instance->Handlers, Link)
|
||||
)
|
||||
{
|
||||
Entry = EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_FROM_LINK (Link);
|
||||
if (Entry->Handler == Handler) {
|
||||
RemoveEntryList (&Entry->Link);
|
||||
FreePool (Entry);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
STATIC EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE mNotifyInstance = {
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_INSTANCE_SIGNATURE,
|
||||
{
|
||||
RegisterHandler,
|
||||
UnregisterHandler
|
||||
},
|
||||
INITIALIZE_LIST_HEAD_VARIABLE (mNotifyInstance.Handlers)
|
||||
};
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ExitBootServicesHook (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN UINTN MapKey
|
||||
)
|
||||
{
|
||||
EXIT_BOOT_SERVICES_OS_CONTEXT Context;
|
||||
LIST_ENTRY *Link;
|
||||
EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY *Entry;
|
||||
|
||||
Context.ReturnAddress = (EFI_PHYSICAL_ADDRESS)RETURN_ADDRESS (0);
|
||||
ASSERT (Context.ReturnAddress != 0);
|
||||
|
||||
Context.OsLoaderAddress = FindPeImageBase (Context.ReturnAddress);
|
||||
Context.OsType = IdentifyOsType (Context.OsLoaderAddress);
|
||||
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"ExitBootServices: Booting %a OS at 0x%lx\n",
|
||||
OsTypeToString (Context.OsType),
|
||||
Context.OsLoaderAddress
|
||||
));
|
||||
|
||||
for ( Link = GetFirstNode (&mNotifyInstance.Handlers)
|
||||
; !IsNull (&mNotifyInstance.Handlers, Link)
|
||||
; Link = GetNextNode (&mNotifyInstance.Handlers, Link)
|
||||
)
|
||||
{
|
||||
Entry = EXIT_BOOT_SERVICES_OS_HANDLER_ENTRY_FROM_LINK (Link);
|
||||
Entry->Handler (&Context);
|
||||
}
|
||||
|
||||
gBS->ExitBootServices = mOriginalExitBootServices;
|
||||
|
||||
return gBS->ExitBootServices (ImageHandle, MapKey);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ExitBootServicesHookDxeInitialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gExitBootServicesOsNotifyProtocolGuid,
|
||||
&mNotifyInstance.Notify,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
mOriginalExitBootServices = gBS->ExitBootServices;
|
||||
gBS->ExitBootServices = ExitBootServicesHook;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#/** @file
|
||||
#
|
||||
# Copyright (c) 2024-2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = ExitBootServicesHookDxe
|
||||
FILE_GUID = 6fd64e41-870c-44cd-b8b1-6752255fb399
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = ExitBootServicesHookDxeInitialize
|
||||
|
||||
[Sources]
|
||||
ExitBootServicesHookDxe.c
|
||||
OsIdentification.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
Silicon/Rockchip/RockchipPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
MemoryAllocationLib
|
||||
PeCoffGetEntryPointLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
UefiLib
|
||||
|
||||
[Protocols]
|
||||
gExitBootServicesOsNotifyProtocolGuid ## PRODUCES
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
@@ -0,0 +1,130 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2024-2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
**/
|
||||
|
||||
#include <IndustryStandard/PeImage.h>
|
||||
#include <Library/PeCoffGetEntryPointLib.h>
|
||||
|
||||
#include "ExitBootServicesHook.h"
|
||||
|
||||
STATIC CHAR8 *mOsTypeStrings[] = {
|
||||
[ExitBootServicesOsUnknown] = "Unknown",
|
||||
[ExitBootServicesOsWindows] = "Windows",
|
||||
[ExitBootServicesOsLinux] = "Linux",
|
||||
};
|
||||
STATIC_ASSERT (ARRAY_SIZE (mOsTypeStrings) == ExitBootServicesOsMax);
|
||||
|
||||
#define LINUX_ARM64_MAGIC 0x644d5241
|
||||
#define LINUX_PE_MAGIC 0x818223cd
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsPeImageVmlinuz (
|
||||
IN VOID *PeImage
|
||||
)
|
||||
{
|
||||
UINT8 *Buf = PeImage;
|
||||
|
||||
switch (*(UINT32 *)(Buf + 0x38)) {
|
||||
case LINUX_ARM64_MAGIC:
|
||||
case LINUX_PE_MAGIC:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC CHAR8 mWinLoadNameStr[] = "winload";
|
||||
#define PDB_NAME_MAX_LENGTH 256
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsPeImageWinLoader (
|
||||
IN VOID *PeImage
|
||||
)
|
||||
{
|
||||
CHAR8 *PdbStr;
|
||||
UINTN WinLoadNameStrLen;
|
||||
UINTN Index;
|
||||
|
||||
PdbStr = (CHAR8 *)PeCoffLoaderGetPdbPointer (PeImage);
|
||||
if (PdbStr == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WinLoadNameStrLen = sizeof (mWinLoadNameStr) - sizeof (CHAR8);
|
||||
|
||||
for (Index = 0; Index < PDB_NAME_MAX_LENGTH && PdbStr[Index] != '\0'; Index++) {
|
||||
if (AsciiStrnCmp (PdbStr + Index, mWinLoadNameStr, WinLoadNameStrLen) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EFI_PHYSICAL_ADDRESS
|
||||
FindPeImageBase (
|
||||
IN EFI_PHYSICAL_ADDRESS Base
|
||||
)
|
||||
{
|
||||
EFI_IMAGE_DOS_HEADER *DosHdr;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
|
||||
|
||||
Base &= ~(EFI_PAGE_SIZE - 1);
|
||||
|
||||
while (Base != 0) {
|
||||
DosHdr = (EFI_IMAGE_DOS_HEADER *)Base;
|
||||
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Base + DosHdr->e_lfanew);
|
||||
if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Base -= EFI_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return Base;
|
||||
}
|
||||
|
||||
EXIT_BOOT_SERVICES_OS_TYPE
|
||||
IdentifyOsType (
|
||||
IN EFI_PHYSICAL_ADDRESS OsLoaderAddress
|
||||
)
|
||||
{
|
||||
VOID *OsLoaderImage;
|
||||
|
||||
if (OsLoaderAddress == 0) {
|
||||
return ExitBootServicesOsUnknown;
|
||||
}
|
||||
|
||||
OsLoaderImage = (VOID *)OsLoaderAddress;
|
||||
|
||||
if (IsPeImageVmlinuz (OsLoaderImage)) {
|
||||
return ExitBootServicesOsLinux;
|
||||
}
|
||||
|
||||
if (IsPeImageWinLoader (OsLoaderImage)) {
|
||||
return ExitBootServicesOsWindows;
|
||||
}
|
||||
|
||||
return ExitBootServicesOsUnknown;
|
||||
}
|
||||
|
||||
CHAR8 *
|
||||
OsTypeToString (
|
||||
IN EXIT_BOOT_SERVICES_OS_TYPE OsType
|
||||
)
|
||||
{
|
||||
if ((OsType < ExitBootServicesOsUnknown) || (OsType >= ExitBootServicesOsMax)) {
|
||||
ASSERT (FALSE);
|
||||
return mOsTypeStrings[ExitBootServicesOsUnknown];
|
||||
}
|
||||
|
||||
return mOsTypeStrings[OsType];
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
**/
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Protocol/ExitBootServicesOsNotify.h>
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GetTime (
|
||||
OUT EFI_TIME *Time,
|
||||
OUT EFI_TIME_CAPABILITIES *Capabilities
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SetTime (
|
||||
IN EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GetWakeupTime (
|
||||
OUT BOOLEAN *Enabled,
|
||||
OUT BOOLEAN *Pending,
|
||||
OUT EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SetWakeupTime (
|
||||
IN BOOLEAN Enabled,
|
||||
OUT EFI_TIME *Time
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
ExitBootServicesOsHandler (
|
||||
IN EXIT_BOOT_SERVICES_OS_CONTEXT *Context
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VOID *Dtb;
|
||||
|
||||
Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, &Dtb);
|
||||
if (EFI_ERROR (Status) || (Dtb == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Context->OsType != ExitBootServicesOsLinux) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// The OS (i.e. Linux with FDT) most likely has a native driver
|
||||
// for the RTC peripheral. In this case, we must prevent UEFI
|
||||
// from accessing the hardware at runtime by disabling RTC services.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "RuntimeServicesManager: Disabling EFI RTC services\n"));
|
||||
gRT->GetTime = GetTime;
|
||||
gRT->SetTime = SetTime;
|
||||
gRT->GetWakeupTime = GetWakeupTime;
|
||||
gRT->SetWakeupTime = SetWakeupTime;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RuntimeServicesManagerDxeInitialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *ExitBootServicesOsNotify;
|
||||
|
||||
Status = gBS->LocateProtocol (
|
||||
&gExitBootServicesOsNotifyProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&ExitBootServicesOsNotify
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = ExitBootServicesOsNotify->RegisterHandler (
|
||||
ExitBootServicesOsNotify,
|
||||
ExitBootServicesOsHandler
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#/** @file
|
||||
#
|
||||
# Copyright (c) 2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001A
|
||||
BASE_NAME = RuntimeServicesManagerDxe
|
||||
FILE_GUID = e83cd2ea-e435-48fd-94a8-97005d6296ec
|
||||
MODULE_TYPE = DXE_RUNTIME_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = RuntimeServicesManagerDxeInitialize
|
||||
|
||||
[Sources]
|
||||
RuntimeServicesManagerDxe.c
|
||||
|
||||
[Packages]
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
Silicon/Rockchip/RockchipPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
UefiRuntimeServicesTableLib
|
||||
UefiLib
|
||||
UefiDriverEntryPoint
|
||||
|
||||
[Guids]
|
||||
gFdtTableGuid
|
||||
|
||||
[Protocols]
|
||||
gExitBootServicesOsNotifyProtocolGuid
|
||||
|
||||
[Depex]
|
||||
gExitBootServicesOsNotifyProtocolGuid
|
||||
@@ -30,6 +30,16 @@
|
||||
INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
|
||||
INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
|
||||
|
||||
#
|
||||
# ExitBootServices hook manager
|
||||
#
|
||||
INF Silicon/Rockchip/Drivers/ExitBootServicesHookDxe/ExitBootServicesHookDxe.inf
|
||||
|
||||
#
|
||||
# Runtime Services state manager
|
||||
#
|
||||
INF Silicon/Rockchip/Drivers/RuntimeServicesManagerDxe/RuntimeServicesManagerDxe.inf
|
||||
|
||||
#
|
||||
# Status LED support
|
||||
#
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2024-2025, Mario Bălănică <mariobalanica02@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
*
|
||||
**/
|
||||
|
||||
#ifndef __EXIT_BOOT_SERVICES_OS_NOTIFY_H__
|
||||
#define __EXIT_BOOT_SERVICES_OS_NOTIFY_H__
|
||||
|
||||
#define EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL_GUID \
|
||||
{ 0x8c254127, 0x3fd5, 0x4b75, { 0xbb, 0x13, 0x22, 0xe8, 0xb5, 0x3e, 0x64, 0x03 } }
|
||||
|
||||
typedef struct _EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL;
|
||||
|
||||
typedef enum {
|
||||
ExitBootServicesOsUnknown = 0,
|
||||
ExitBootServicesOsWindows,
|
||||
ExitBootServicesOsLinux,
|
||||
ExitBootServicesOsMax
|
||||
} EXIT_BOOT_SERVICES_OS_TYPE;
|
||||
|
||||
typedef struct {
|
||||
EXIT_BOOT_SERVICES_OS_TYPE OsType;
|
||||
EFI_PHYSICAL_ADDRESS OsLoaderAddress;
|
||||
EFI_PHYSICAL_ADDRESS ReturnAddress;
|
||||
} EXIT_BOOT_SERVICES_OS_CONTEXT;
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(EFIAPI *EXIT_BOOT_SERVICES_OS_HANDLER)(
|
||||
IN EXIT_BOOT_SERVICES_OS_CONTEXT *Context
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EXIT_BOOT_SERVICES_OS_NOTIFY_REGISTER)(
|
||||
IN EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *This,
|
||||
IN EXIT_BOOT_SERVICES_OS_HANDLER Handler
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EXIT_BOOT_SERVICES_OS_NOTIFY_UNREGISTER)(
|
||||
IN EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *This,
|
||||
IN EXIT_BOOT_SERVICES_OS_HANDLER Handler
|
||||
);
|
||||
|
||||
struct _EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL {
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_REGISTER RegisterHandler;
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_UNREGISTER UnregisterHandler;
|
||||
};
|
||||
|
||||
extern EFI_GUID gExitBootServicesOsNotifyProtocolGuid;
|
||||
|
||||
#endif
|
||||
@@ -10,7 +10,7 @@
|
||||
**/
|
||||
|
||||
#include <IndustryStandard/AcpiAml.h>
|
||||
#include <IndustryStandard/PeImage.h>
|
||||
#include <Protocol/ExitBootServicesOsNotify.h>
|
||||
#include <Protocol/LoadedImage.h>
|
||||
#include <Protocol/NonDiscoverableDevice.h>
|
||||
#include <Library/AcpiLib.h>
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PeCoffGetEntryPointLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <AcpiTables.h>
|
||||
@@ -29,18 +28,11 @@ STATIC CONST EFI_GUID mAcpiTableFile = {
|
||||
0x7E374E25, 0x8E01, 0x4FEE, { 0x87, 0xf2, 0x39, 0x0C, 0x23, 0xC6, 0x06, 0xCD }
|
||||
};
|
||||
|
||||
STATIC EFI_EXIT_BOOT_SERVICES mOriginalExitBootServices;
|
||||
|
||||
STATIC EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol;
|
||||
STATIC EFI_ACPI_DESCRIPTION_HEADER *mDsdtTable;
|
||||
|
||||
STATIC BOOLEAN mIsSdmmcBoot = FALSE;
|
||||
|
||||
typedef enum {
|
||||
AcpiOsUnknown = 0,
|
||||
AcpiOsWindows,
|
||||
} ACPI_OS_BOOT_TYPE;
|
||||
|
||||
#define SDT_PATTERN_LEN (AML_NAME_SEG_SIZE + 1)
|
||||
|
||||
//
|
||||
@@ -200,7 +192,7 @@ STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AcpiFixupPcieEcam (
|
||||
IN ACPI_OS_BOOT_TYPE OsType
|
||||
IN EXIT_BOOT_SERVICES_OS_TYPE OsType
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
@@ -232,7 +224,7 @@ AcpiFixupPcieEcam (
|
||||
|
||||
if (PcieEcamMode == ACPI_PCIE_ECAM_COMPAT_MODE_NXPMX6_SINGLE_DEV ||
|
||||
PcieEcamMode == ACPI_PCIE_ECAM_COMPAT_MODE_NXPMX6_GRAVITON) {
|
||||
if (OsType == AcpiOsWindows) {
|
||||
if (OsType == ExitBootServicesOsWindows) {
|
||||
PcieEcamMode = ACPI_PCIE_ECAM_COMPAT_MODE_NXPMX6;
|
||||
} else {
|
||||
PcieEcamMode &= ~ACPI_PCIE_ECAM_COMPAT_MODE_NXPMX6;
|
||||
@@ -309,10 +301,12 @@ AcpiFixupPcieEcam (
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
AcpiPlatformOsBootHandler (
|
||||
IN ACPI_OS_BOOT_TYPE OsType
|
||||
AcpiPlatformExitBootServicesOsHandler (
|
||||
IN EXIT_BOOT_SERVICES_OS_CONTEXT *Context
|
||||
)
|
||||
{
|
||||
EXIT_BOOT_SERVICES_OS_TYPE OsType = Context->OsType;
|
||||
|
||||
if (mAcpiSdtProtocol == NULL || mDsdtTable == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -322,7 +316,7 @@ AcpiPlatformOsBootHandler (
|
||||
// which by default uses atomics on uncached memory and would crash
|
||||
// the system.
|
||||
//
|
||||
if (OsType == AcpiOsWindows) {
|
||||
if (OsType == ExitBootServicesOsWindows) {
|
||||
AcpiUpdateSdtNameInteger (mDsdtTable, "EHID", 0);
|
||||
}
|
||||
|
||||
@@ -339,89 +333,6 @@ AcpiPlatformOsBootHandler (
|
||||
AcpiUpdateChecksum ((UINT8 *)mDsdtTable, mDsdtTable->Length);
|
||||
}
|
||||
|
||||
STATIC
|
||||
UINTN
|
||||
EFIAPI
|
||||
FindPeImageBase (
|
||||
EFI_PHYSICAL_ADDRESS Base
|
||||
)
|
||||
{
|
||||
EFI_IMAGE_DOS_HEADER *DosHdr;
|
||||
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
|
||||
|
||||
Base &= ~(EFI_PAGE_SIZE - 1);
|
||||
|
||||
while (Base != 0) {
|
||||
DosHdr = (EFI_IMAGE_DOS_HEADER *)Base;
|
||||
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Base + DosHdr->e_lfanew);
|
||||
if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Base -= EFI_PAGE_SIZE;
|
||||
}
|
||||
|
||||
return Base;
|
||||
}
|
||||
|
||||
STATIC CHAR8 mWinLoadNameStr[] = "winload";
|
||||
#define PDB_NAME_MAX_LENGTH 256
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsPeImageWinLoader (
|
||||
IN VOID *PeImage
|
||||
)
|
||||
{
|
||||
CHAR8 *PdbStr;
|
||||
UINTN Index;
|
||||
|
||||
PdbStr = (CHAR8 *)PeCoffLoaderGetPdbPointer (PeImage);
|
||||
if (PdbStr == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < PDB_NAME_MAX_LENGTH && PdbStr[Index] != '\0'; Index++) {
|
||||
if (AsciiStrnCmp (PdbStr + Index, mWinLoadNameStr, sizeof (mWinLoadNameStr) - sizeof (CHAR8)) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AcpiPlatformExitBootServicesHook (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN UINTN MapKey
|
||||
)
|
||||
{
|
||||
UINTN ReturnAddress;
|
||||
UINTN OsLoaderAddress;
|
||||
ACPI_OS_BOOT_TYPE OsType;
|
||||
|
||||
ReturnAddress = (UINTN)RETURN_ADDRESS (0);
|
||||
|
||||
gBS->ExitBootServices = mOriginalExitBootServices;
|
||||
|
||||
OsType = AcpiOsUnknown;
|
||||
|
||||
OsLoaderAddress = FindPeImageBase (ReturnAddress);
|
||||
if (OsLoaderAddress > 0) {
|
||||
if (IsPeImageWinLoader ((VOID *)OsLoaderAddress)) {
|
||||
OsType = AcpiOsWindows;
|
||||
}
|
||||
}
|
||||
|
||||
AcpiPlatformOsBootHandler (OsType);
|
||||
|
||||
return gBS->ExitBootServices (ImageHandle, MapKey);
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsDeviceSdmmc (
|
||||
@@ -547,8 +458,9 @@ AcpiPlatformDxeInitialize (
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
EFI_STATUS Status;
|
||||
EFI_EVENT Event;
|
||||
EXIT_BOOT_SERVICES_OS_NOTIFY_PROTOCOL *ExitBootServicesOsNotify;
|
||||
|
||||
if ((PcdGet32 (PcdConfigTableMode) & CONFIG_TABLE_MODE_ACPI) == 0) {
|
||||
DEBUG ((DEBUG_WARN, "AcpiPlatform: ACPI support is disabled by the settings.\n"));
|
||||
@@ -575,8 +487,19 @@ AcpiPlatformDxeInitialize (
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
mOriginalExitBootServices = gBS->ExitBootServices;
|
||||
gBS->ExitBootServices = AcpiPlatformExitBootServicesHook;
|
||||
Status = gBS->LocateProtocol (
|
||||
&gExitBootServicesOsNotifyProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&ExitBootServicesOsNotify
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = ExitBootServicesOsNotify->RegisterHandler (
|
||||
ExitBootServicesOsNotify,
|
||||
AcpiPlatformExitBootServicesOsHandler
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
DebugLib
|
||||
DevicePathLib
|
||||
MemoryAllocationLib
|
||||
PeCoffGetEntryPointLib
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
UefiDriverEntryPoint
|
||||
@@ -46,6 +45,7 @@
|
||||
gEdkiiNonDiscoverableDeviceProtocolGuid
|
||||
gEfiAcpiSdtProtocolGuid
|
||||
gEfiLoadedImageProtocolGuid
|
||||
gExitBootServicesOsNotifyProtocolGuid
|
||||
|
||||
[Pcd]
|
||||
gRK3588TokenSpaceGuid.PcdConfigTableMode
|
||||
@@ -60,4 +60,5 @@
|
||||
gRockchipTokenSpaceGuid.PcdRkSdmmcBaseAddress
|
||||
|
||||
[Depex]
|
||||
gRockchipPlatformConfigAppliedProtocolGuid
|
||||
gRockchipPlatformConfigAppliedProtocolGuid AND
|
||||
gExitBootServicesOsNotifyProtocolGuid
|
||||
|
||||
@@ -538,6 +538,16 @@ FspiLib|Silicon/Rockchip/Library/FspiLib/FspiLib.inf
|
||||
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
|
||||
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
|
||||
|
||||
#
|
||||
# ExitBootServices hook manager
|
||||
#
|
||||
Silicon/Rockchip/Drivers/ExitBootServicesHookDxe/ExitBootServicesHookDxe.inf
|
||||
|
||||
#
|
||||
# Runtime Services state manager
|
||||
#
|
||||
Silicon/Rockchip/Drivers/RuntimeServicesManagerDxe/RuntimeServicesManagerDxe.inf
|
||||
|
||||
#
|
||||
# Status LED support
|
||||
#
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
gPca95xxProtocolGuid = { 0x7e91391b, 0xa23c, 0x4a51, { 0x9d, 0xf7, 0xf6, 0x74, 0xef, 0x1d, 0x51, 0x1b } }
|
||||
gRockchipDsiPanelProtocolGuid = { 0x07a5d05c, 0x3216, 0x49fc, { 0xb4, 0x22, 0x28, 0x9d, 0x38, 0xd5, 0xdf, 0x7e } }
|
||||
gRockchipFirmwareBootDeviceProtocolGuid = { 0x8733765a, 0x3ce7, 0x47b5, { 0xb2, 0xc0, 0x39, 0x80, 0x68, 0xd5, 0x86, 0xb3 } }
|
||||
gExitBootServicesOsNotifyProtocolGuid = { 0x8c254127, 0x3fd5, 0x4b75, { 0xbb, 0x13, 0x22, 0xe8, 0xb5, 0x3e, 0x64, 0x03 } }
|
||||
|
||||
[Guids]
|
||||
gRockchipTokenSpaceGuid = { 0xc620b83a, 0x3175, 0x11ec, { 0x95, 0xb4, 0xf4, 0x2a, 0x7d, 0xcb, 0x92, 0x5d } }
|
||||
|
||||
Reference in New Issue
Block a user