Skip to content

Commit

Permalink
Release 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jun 5, 2024
1 parent e86ebb7 commit 304511d
Show file tree
Hide file tree
Showing 49 changed files with 371 additions and 389 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
SCAN_HOST: ${{ secrets.SCAN_HOST }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_SCANNER_VERSION: 5.0.1.3006
SONAR_SCANNER_VERSION: 6.0.0.4432
BUILD_WRAPPER_OUT_DIR: "$HOME/.build_wrapper_out"
APT_PACKAGES: protobuf-compiler libspdlog-dev libpcap-dev libgmock-dev

Expand Down
116 changes: 76 additions & 40 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CXXFLAGS += $(EXTRA_FLAGS)

## Installation path
## The path to install binaries and manpages in, default is /opt/scsi2pi
TARGET=/opt/scsi2pi
TARGET := /opt/scsi2pi

## BOARD=FULLSPEC
## Specifies the board type that you are using. Typically this is
Expand All @@ -52,55 +52,91 @@ BOARD ?= FULLSPEC

CXXFLAGS += -DBOARD_$(BOARD)

## BUILD_*=1
## Specifies the device types to build, default is all. Supported types:
## SCHD SCSI Removable and non-removable Hard Drive
## ENABLE_*=1
## DISABLE_*=1
## Specifies the device types to build or not to build, default is to build all. Supported types:
## SCHD SCSI Removable and Non-removable Hard Drive
## SCCD SCSI CD-Rom Drive
## SCMO SCSI Optical Memory
## SCDP DaynaPort Network Adapter
## SCLP SCSI Printer
## SCHS Host Services
## SAHD SASI Hard Drive
ifeq ($(or $(BUILD_SCHD),$(BUILD_SCMO),$(BUILD_SCCD),$(BUILD_SCDP),$(BUILD_SCLP),$(BUILD_SCHS),$(BUILD_SAHD)),)
BUILD_SCHD = 1
BUILD_SCMO = 1
BUILD_SCCD = 1
BUILD_SCDP = 1
BUILD_SCLP = 1
BUILD_SCHS = 1
BUILD_SAHD = 1
ifeq ($(or $(ENABLE_SCHD),$(ENABLE_SCMO),$(ENABLE_SCCD),$(ENABLE_SCDP),$(ENABLE_SCLP),$(ENABLE_SCHS),$(ENABLE_SAHD)),)
ENABLE_SCHD = 1
ENABLE_SCMO = 1
ENABLE_SCCD = 1
ENABLE_SCDP = 1
ENABLE_SCLP = 1
ENABLE_SCHS = 1
ENABLE_SAHD = 1
endif
ifdef BUILD_SCHD
CXXFLAGS += -DBUILD_MODE_PAGE_DEVICE -DBUILD_DISK -DBUILD_SCHD

ifdef ENABLE_SCRM
ENABLE_SCHD = 1
endif

ifdef DISABLE_SCHD
ENABLE_SCHD =
endif
ifdef DISABLE_SCMO
ENABLE_SCMO =
endif
ifdef BUILD_SCMO
CXXFLAGS += -DBUILD_MODE_PAGE_DEVICE -DBUILD_DISK -DBUILD_SCMO
ifdef DISABLE_SCCD
ENABLE_SCCD =
endif
ifdef BUILD_SCCD
CXXFLAGS += -DBUILD_MODE_PAGE_DEVICE -DBUILD_DISK -DBUILD_SCCD
ifdef DISABLE_SCDP
ENABLE_SCDP =
endif
ifdef BUILD_SCDP
ifdef DISABLE_SCLP
ENABLE_SCLP =
endif
ifdef DISABLE_SCHS
ENABLE_SCHS =
endif
ifdef DISABLE_SAHD
ENABLE_SAHD =
endif

ifdef ENABLE_SCHD
CXXFLAGS += -DBUILD_SCHD
endif
ifdef ENABLE_SCMO
CXXFLAGS += -DBUILD_SCMO
endif
ifdef ENABLE_SCCD
CXXFLAGS += -DBUILD_SCCD
endif
ifdef ENABLE_SCDP
CXXFLAGS += -DBUILD_SCDP
endif
ifdef BUILD_SCLP
ifdef ENABLE_SCLP
CXXFLAGS += -DBUILD_SCLP
endif
ifdef BUILD_SCHS
CXXFLAGS += -DBUILD_MODE_PAGE_DEVICE -DBUILD_SCHS
ifdef ENABLE_SCHS
CXXFLAGS += -DBUILD_SCHS
endif
ifdef ENABLE_SAHD
CXXFLAGS += -DBUILD_SAHD
endif
ifdef BUILD_SAHD
CXXFLAGS += -DBUILD_DISK -DBUILD_SAHD

ifeq ($(or $(ENABLE_SCHD),$(ENABLE_SCMO),$(ENABLE_SCCD),$(ENABLE_SAHD),$(ENABLE_SCHS)),1)
CXXFLAGS += -DBUILD_MODE_PAGE_DEVICE
endif

ifeq ($(or $(ENABLE_SCHD),$(ENABLE_SCMO),$(ENABLE_SCCD),$(ENABLE_SAHD)),1)
CXXFLAGS += -DBUILD_DISK
endif

S2P = s2p
S2PCTL = s2pctl
S2PDUMP = s2pdump
S2PEXEC = s2pexec
S2PPROTO = s2pproto
S2P_TEST = s2p_test
IN_PROCESS_TEST = in_process_test
S2P := s2p
S2PCTL := s2pctl
S2PDUMP := s2pdump
S2PEXEC := s2pexec
S2PPROTO := s2pproto
S2P_TEST := s2p_test
IN_PROCESS_TEST := in_process_test

INSTALL_BIN = $(TARGET)/bin
INSTALL_BIN := $(TARGET)/bin

OBJDIR := obj
LIBDIR := lib
Expand All @@ -126,7 +162,7 @@ DIR_BUSES := buses
DIR_CONTROLLERS := controllers
DIR_DEVICES := devices

SRC_PROTOC = ../proto/s2p_interface.proto
SRC_PROTOC := ../proto/s2p_interface.proto

SRC_GENERATED = $(GENERATED_DIR)/s2p_interface.pb.cpp

Expand All @@ -146,42 +182,42 @@ SRC_DISK = \
$(DIR_DEVICES)/storage_device.cpp \
$(DIR_DEVICES)/mode_page_device.cpp

ifdef BUILD_SCHD
ifeq ($(ENABLE_SCHD),1)
SRC_SCHD = \
$(DIR_DEVICES)/scsi_hd.cpp
SRC_SCHD += $(SRC_DISK)
endif

ifdef BUILD_SCMO
ifeq ($(ENABLE_SCMO),1)
SRC_SCMO = \
$(DIR_DEVICES)/optical_memory.cpp
SRC_SCMO += $(SRC_DISK)
endif

ifdef BUILD_SCCD
ifeq ($(ENABLE_SCCD),1)
SRC_SCCD = \
$(DIR_DEVICES)/scsi_cd.cpp
SRC_SCCD += $(SRC_DISK)
endif

ifdef BUILD_SCDP
ifeq ($(ENABLE_SCDP),1)
SRC_SCDP = \
$(DIR_DEVICES)/daynaport.cpp \
$(DIR_DEVICES)/tap_driver.cpp
endif

ifdef BUILD_SCLP
ifeq ($(ENABLE_SCLP),1)
SRC_SCLP = \
$(DIR_DEVICES)/printer.cpp
endif

ifdef BUILD_SCHS
ifeq ($(ENABLE_SCHS),1)
SRC_SCHS = \
$(DIR_DEVICES)/host_services.cpp \
$(DIR_DEVICES)/mode_page_device.cpp
endif

ifdef BUILD_SAHD
ifeq ($(ENABLE_SAHD),1)
SRC_SAHD = \
$(DIR_DEVICES)/sasi_hd.cpp
SRC_SAHD += $(SRC_DISK)
Expand Down
10 changes: 3 additions & 7 deletions cpp/base/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class Device // NOSONAR The number of fields and methods is justified, the compl
{
return type;
}
string GetTypeString() const
{
return PbDeviceType_Name(type);
}

bool IsReady() const
{
Expand Down Expand Up @@ -99,17 +95,17 @@ class Device // NOSONAR The number of fields and methods is justified, the compl
return lun;
}

string GetVendor() const
const string& GetVendor() const
{
return vendor;
}
void SetVendor(const string&);
string GetProduct() const
const string& GetProduct() const
{
return product;
}
void SetProduct(const string&, bool = true);
string GetRevision() const
const string& GetRevision() const
{
return revision;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/device_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DeviceFactory

static string GetExtensionLowerCase(string_view);

inline static const unordered_map<string, PbDeviceType, s2p_util::StringHash, equal_to<>> DEVICE_MAPPING = {
inline static const unordered_map<string_view, PbDeviceType> DEVICE_MAPPING = {
{ "daynaport", SCDP },
{ "printer", SCLP },
{ "services", SCHS }
Expand Down
26 changes: 25 additions & 1 deletion cpp/base/memory_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@
//
// SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2022-2023 Uwe Seimet
// Copyright (C) 2022-2024 Uwe Seimet
//
//---------------------------------------------------------------------------

#include "memory_util.h"

template<typename T>
void memory_util::SetInt16(vector<T> &buf, int offset, int value)
{
assert(buf.size() > static_cast<size_t>(offset) + 1);

buf[offset] = static_cast<T>(value >> 8);
buf[offset + 1] = static_cast<T>(value);
}
template void memory_util::SetInt16(vector<byte>&, int, int);
template void memory_util::SetInt16(vector<uint8_t>&, int, int);

template<typename T>
void memory_util::SetInt32(vector<T> &buf, int offset, uint32_t value)
{
assert(buf.size() > static_cast<size_t>(offset) + 3);

buf[offset] = static_cast<T>(value >> 24);
buf[offset + 1] = static_cast<T>(value >> 16);
buf[offset + 2] = static_cast<T>(value >> 8);
buf[offset + 3] = static_cast<T>(value);
}
template void memory_util::SetInt32(vector<byte>&, int, uint32_t);
template void memory_util::SetInt32(vector<uint8_t>&, int, uint32_t);

int memory_util::GetInt24(span<const int> buf, int offset)
{
assert(buf.size() > static_cast<size_t>(offset) + 2);
Expand Down
21 changes: 2 additions & 19 deletions cpp/base/memory_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,8 @@ int GetInt16(const auto &buf, int offset)
return (static_cast<int>(buf[offset]) << 8) | buf[offset + 1];
}

template<typename T>
void SetInt16(vector<T> &buf, int offset, int value)
{
assert(buf.size() > static_cast<size_t>(offset) + 1);

buf[offset] = static_cast<T>(value >> 8);
buf[offset + 1] = static_cast<T>(value);
}

template<typename T>
void SetInt32(vector<T> &buf, int offset, uint32_t value)
{
assert(buf.size() > static_cast<size_t>(offset) + 3);

buf[offset] = static_cast<T>(value >> 24);
buf[offset + 1] = static_cast<T>(value >> 16);
buf[offset + 2] = static_cast<T>(value >> 8);
buf[offset + 3] = static_cast<T>(value);
}
template<typename T> void SetInt16(vector<T>&, int, int);
template<typename T> void SetInt32(vector<T>&, int, uint32_t);

int GetInt24(span<const int>, int);
uint32_t GetInt32(span<const int>, int);
Expand Down
22 changes: 22 additions & 0 deletions cpp/base/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool PrimaryDevice::Init(const param_map &params)
return true;
}

void PrimaryDevice::AddCommand(scsi_command cmd, const command &c)
{
commands[static_cast<int>(cmd)] = c;
}

void PrimaryDevice::Dispatch(scsi_command cmd)
{
if (const auto &command = commands[static_cast<int>(cmd)]; command) {
Expand Down Expand Up @@ -96,6 +101,23 @@ void PrimaryDevice::SetController(AbstractController *c)
device_logger.SetIdAndLun(GetId(), GetLun());
}

void PrimaryDevice::StatusPhase() const
{
controller->Status();
}

void PrimaryDevice::DataInPhase(int length) const
{
controller->SetCurrentLength(length);
controller->DataIn();
}

void PrimaryDevice::DataOutPhase(int length) const
{
controller->SetCurrentLength(length);
controller->DataOut();
}

void PrimaryDevice::TestUnitReady()
{
CheckReady();
Expand Down
22 changes: 4 additions & 18 deletions cpp/base/primary_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ class PrimaryDevice : public ScsiPrimaryCommands, public Device
{
}

void AddCommand(scsi_command cmd, const command &c)
{
commands[static_cast<int>(cmd)] = c;
}
void AddCommand(scsi_command, const command&);

vector<uint8_t> HandleInquiry(device_type, bool) const;
virtual vector<uint8_t> InquiryInternal() const = 0;
Expand All @@ -121,20 +118,9 @@ class PrimaryDevice : public ScsiPrimaryCommands, public Device
void ReserveUnit() override;
void ReleaseUnit() override;

void StatusPhase() const
{
controller->Status();
}
void DataInPhase(int length) const
{
controller->SetCurrentLength(length);
controller->DataIn();
}
void DataOutPhase(int length) const
{
controller->SetCurrentLength(length);
controller->DataOut();
}
void StatusPhase() const;
void DataInPhase(int) const;
void DataOutPhase(int) const;

void LogTrace(const string &s) const
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/property_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ property_map PropertyHandler::GetProperties(const string &filter) const
return filtered_properties;
}

string PropertyHandler::GetProperty(string_view key, const string &def) const
const string& PropertyHandler::GetProperty(string_view key, const string &def) const
{
for (const auto& [k, v] : property_cache) {
if (k == key) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/base/property_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PropertyHandler
void Init(const string&, const property_map&, bool);

property_map GetProperties(const string& = "") const;
string GetProperty(string_view, const string& = "") const;
const string& GetProperty(string_view, const string& = "") const;
void AddProperty(const string &key, string_view value)
{
property_cache[key] = value;
Expand Down
Loading

0 comments on commit 304511d

Please sign in to comment.