Skip to content

Commit

Permalink
XiangshanSeriesPkg:Add BOSC NanhuDev platform
Browse files Browse the repository at this point in the history
This commit adds the initial support for BOSC's
nanhu platform which provides up to 2 RISC-V RV64
processor cores.

Signed-off-by: Yang Wang <[email protected]>
Signed-off-by: Ran Wang <[email protected]>
Signed-off-by: YunFeng Yang <[email protected]>
Signed-off-by: YaXing Guo <[email protected]>
Cc: Leif Lindholm <[email protected]>
Cc: Michael D Kinney <[email protected]>
Cc: Sunil V L <[email protected]>
Cc: Daniel Schaefer <[email protected]>
  • Loading branch information
Yang Wang authored and vlsunil committed Sep 2, 2024
1 parent 2acddc9 commit 4f49a84
Show file tree
Hide file tree
Showing 17 changed files with 1,865 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Maintainers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,10 @@ R: dahogn <[email protected]>
R: meng-cz <[email protected]>
R: caiyuqing379 <[email protected]>
R: USER0FISH <[email protected]>

Bosc platforms and silicon
F: Platform/Bosc/
F: Silicon/Bosc/NanHuPkg/
M: Sunil V L <[email protected]>
R: Yang Wang<[email protected]>
R: Ran Wang<[email protected]>
61 changes: 61 additions & 0 deletions Platform/Bosc/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Introduction to BOSC Xiangshan Series Platform #

This document provides guidelines for building UEFI firmware for BOSC NanhuDev.
BOSC NanhuDev is a 64 and processor of RISC-V architecture.
BOSC NanhuDev UEFI can currently use Opensbi+UEFI firmware+GRUB to successfully enter the Linux.

## How to build (X86 Linux Environment)

### NanhuDev EDK2 Initial Environment ###

**statement**:The operating environment of this project is deployed on the BOSC original environment.

1. Install package on ubuntu

```
sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build uuide-dev
```
2. Follow edk2-platforms/Readme.md to obtaining source code, and config build env. For Example:
```
export WORKSPACE=/work/git/tianocore
mkdir -p $WORKSPACE
cd $WORKSPACE
git clone https://github.com/tianocore/edk2.git
cd edk2
git submodule update --init
cd ..
git clone https://github.com/tianocore/edk2-platforms.git
cd edk2-platforms
git submodule update --init
cd ..
git clone https://github.com/tianocore/edk2-non-osi.git
export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms:$PWD/edk2-non-osi
```
3. Build
3.1 Using GCC toolchain
```
export GCC5_RISCV64_PREFIX=riscv64-linux-gnu-
export PYTHON_COMMAND=python3
export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
source edk2/edksetup.sh --reconfig
make -C edk2/BaseTools
source edk2/edksetup.sh BaseTools
build --buildtarget=DEBUG -a RISCV64 -t GCC5 -p Platform/Bosc/XiangshanSeriesPkg/NanhuDev/NanhuDev.dsc
```
After a successful build, the resulting images can be found in Build/{Platform Name}/{TARGET}_{TOOL_CHAIN_TAG}/FV/NANHUDEV.fd
4. When compiling Opensbi, specify that payload is NANHUDEV.fd and specify dtb path.
make -C ~/opensbi PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- -j FW_PAYLOAD_PATH=$(PAYLOAD) FW_FDT_PATH=$(DTB_PATH)
5. Use GRUB2 to boot linux OS
Reference: https://fedoraproject.org/wiki/Architectures/RISC-V/GRUB2
Copy grubriscv64.efi and Image(linux) to the root directory of the NVME partition.
## Known Issues and Limitations
This test only runs on BOSC NanhuDev with RISC-V RV64 architecture
552 changes: 552 additions & 0 deletions Platform/Bosc/XiangshanSeriesPkg/NanhuDev/NanhuDev.dsc

Large diffs are not rendered by default.

241 changes: 241 additions & 0 deletions Platform/Bosc/XiangshanSeriesPkg/NanhuDev/NanhuDev.fdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# @file
# Flash definition file on Bosc NanHuDev RISC-V platform
#
# Copyright (c) 2023, Academy of Intelligent Innovation, Shandong Universiy, China.P.R. All rights reserved.<BR>
# Copyright (c) 2024, Bosc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
# Platform definitions
#
!include NanhuDev.fdf.inc

#
# Build the variable store and the firmware code as one unified flash device
# image.
#
[FD.NANHUDEV]
BaseAddress = $(FW_BASE_ADDRESS)
Size = $(FW_SIZE)
ErasePolarity = 1
BlockSize = $(BLOCK_SIZE)
NumBlocks = $(FW_BLOCKS)


$(FVMAIN_OFFSET)|$(FVMAIN_SIZE)
gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRiscVDxeFvBase|gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRiscVDxeFvSize
FV = FVMAIN_COMPACT

!include VarStore.fdf.inc
################################################################################

[FV.DXEFV]
BlockSize = 0x10000
FvAlignment = 16
ERASE_POLARITY = 1
MEMORY_MAPPED = TRUE
STICKY_WRITE = TRUE
LOCK_CAP = TRUE
LOCK_STATUS = TRUE
WRITE_DISABLED_CAP = TRUE
WRITE_ENABLED_CAP = TRUE
WRITE_STATUS = TRUE
WRITE_LOCK_CAP = TRUE
WRITE_LOCK_STATUS = TRUE
READ_DISABLED_CAP = TRUE
READ_ENABLED_CAP = TRUE
READ_STATUS = TRUE
READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE

APRIORI DXE {
INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF Platform/SiFive/U5SeriesPkg/Universal/Dxe/RamFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
INF UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf
}

#
# DXE Phase modules
#
INF MdeModulePkg/Core/Dxe/DxeMain.inf

INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF ArmVirtPkg/CloudHvPlatformHasAcpiDtDxe/CloudHvHasAcpiDtDxe.inf
INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf
INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf

INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

# RISC-V Platform Drivers
INF Platform/SiFive/U5SeriesPkg/Universal/Dxe/RamFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf

# RISC-V Core Drivers
INF UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
INF UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf

INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
!endif

INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf
INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
INF FatPkg/EnhancedFatDxe/Fat.inf
INF MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf

!ifndef $(SOURCE_DEBUG_ENABLE)
INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
!endif

INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
INF ShellPkg/Application/Shell/Shell.inf

#
# Network modules
#
!if $(E1000_ENABLE)
FILE DRIVER = 5D695E11-9B3F-4b83-B25F-4A8D5D69BE07 {
SECTION PE32 = Intel3.5/EFIX64/E3507X2.EFI
}
!endif

!include NetworkPkg/Network.fdf.inc

#
# Usb Support
#
INF MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
INF MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
INF MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf
INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf

INF MdeModulePkg/Application/UiApp/UiApp.inf

################################################################################

[FV.FVMAIN_COMPACT]
FvAlignment = 16
ERASE_POLARITY = 1
MEMORY_MAPPED = TRUE
STICKY_WRITE = TRUE
LOCK_CAP = TRUE
LOCK_STATUS = TRUE
WRITE_DISABLED_CAP = TRUE
WRITE_ENABLED_CAP = TRUE
WRITE_STATUS = TRUE
WRITE_LOCK_CAP = TRUE
WRITE_LOCK_STATUS = TRUE
READ_DISABLED_CAP = TRUE
READ_ENABLED_CAP = TRUE
READ_STATUS = TRUE
READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE
FvNameGuid = 27A72E80-3118-4c0c-8673-AA5B4EFA9613

INF Silicon/Bosc/NanHuPkg/Sec/SecMain.inf

FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
#
# These firmware volumes will have files placed in them uncompressed,
# and then both firmware volumes will be compressed in a single
# compression operation in order to achieve better overall compression.
#
SECTION FV_IMAGE = DXEFV
}
}

[Rule.Common.SEC]
FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED FIXED {
PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING ="$(MODULE_NAME)" Optional
VERSION STRING ="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.DXE_CORE]
FILE DXE_CORE = $(NAMED_GUID) {
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.DXE_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.DXE_RUNTIME_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.UEFI_DRIVER]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.UEFI_DRIVER.BINARY]
FILE DRIVER = $(NAMED_GUID) {
DXE_DEPEX DXE_DEPEX Optional |.depex
PE32 PE32 |.efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.UEFI_APPLICATION]
FILE APPLICATION = $(NAMED_GUID) {
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.UEFI_APPLICATION.BINARY]
FILE APPLICATION = $(NAMED_GUID) {
PE32 PE32 |.efi
UI STRING="$(MODULE_NAME)" Optional
VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
}

[Rule.Common.USER_DEFINED.ACPITABLE]
FILE FREEFORM = $(NAMED_GUID) {
RAW ACPI |.acpi
RAW ASL |.aml
UI STRING="$(MODULE_NAME)" Optional
}
62 changes: 62 additions & 0 deletions Platform/Bosc/XiangshanSeriesPkg/NanhuDev/NanhuDev.fdf.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## @file
# Definitions of Flash definition file on Bosc NanHuDev RISC-V platform
#
# Copyright (c) 2023, Academy of Intelligent Innovation, Shandong Universiy, China.P.R. All rights reserved.<BR>
# Copyright (c) 2024, Bosc. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
DEFINE BLOCK_SIZE = 0x1000

DEFINE FW_BASE_ADDRESS = 0x80200000
DEFINE FW_SIZE = 0x00800000
DEFINE FW_BLOCKS = 0x800

#
# 0x000000-0x7DFFFF code
# 0x7E0000-0x800000 variables
#
DEFINE CODE_BASE_ADDRESS = $(FW_BASE_ADDRESS)
DEFINE CODE_SIZE = 0x00780000
DEFINE CODE_BLOCKS = 0x780
DEFINE VARS_BLOCKS = 0x20

#
# Other FV regions are in the second FW domain.
# The size of memory region must be power of 2.
# The base address must be aligned with the size.
#
# FW memory region
#
DEFINE FVMAIN_OFFSET = 0x00000000
DEFINE FVMAIN_SIZE = 0x00780000

#
# EFI Variable memory region.
# The total size of EFI Variable FD must include
# all of sub regions of EFI Variable
#
DEFINE VARS_OFFSET = 0x00780000
DEFINE VARS_SIZE = 0x00007000
DEFINE VARS_FTW_WORKING_OFFSET = $(VARS_OFFSET) + $(VARS_SIZE)
DEFINE VARS_FTW_WORKING_SIZE = 0x00001000
DEFINE VARS_FTW_SPARE_OFFSET = $(VARS_FTW_WORKING_OFFSET) + $(VARS_FTW_WORKING_SIZE)
DEFINE VARS_FTW_SPARE_SIZE = 0x00018000

DEFINE VARIABLE_FW_SIZE = $(VARS_FTW_SPARE_OFFSET) + $(VARS_FTW_SPARE_SIZE) - $(VARS_OFFSET)

SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFdBaseAddress = $(FW_BASE_ADDRESS) + $(VARS_OFFSET)
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFdSize = $(VARS_SIZE) + $(VARS_FTW_WORKING_SIZE) + $(VARS_FTW_SPARE_SIZE)
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFdBlockSize = $(BLOCK_SIZE)
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFirmwareRegionBaseAddress = $(CODE_BASE_ADDRESS) + $(VARS_OFFSET)
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFirmwareRegionSize = $(VARIABLE_FW_SIZE)
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdTemporaryRamBase = $(CODE_BASE_ADDRESS) + $(FW_SIZE) + 0x1FF0000
SET gUefiRiscVPlatformPkgTokenSpaceGuid.PcdTemporaryRamSize = 0x10000

SET gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency = 500000 # Adapted CPU clock is 50MHz
SET gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase = 0x310B0000
SET gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate = 115200
SET gHisiTokenSpaceGuid.PcdSerialPortSendDelay = 50
SET gHisiTokenSpaceGuid.PcdUartClkInHz = 50000000
Loading

0 comments on commit 4f49a84

Please sign in to comment.