diff --git a/.gitignore b/.gitignore index 5ceb3864..995e1e8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ venv +*.pyc +core diff --git a/src/raspberrypi/.vscode/launch.json b/src/raspberrypi/.vscode/launch.json index 4ac5ab4b..b58c19b7 100644 --- a/src/raspberrypi/.vscode/launch.json +++ b/src/raspberrypi/.vscode/launch.json @@ -8,13 +8,15 @@ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/rascsi", + "program": "${workspaceFolder}/bin/fullspec/rascsi", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", + "targetArchitecture": "arm", + "miDebuggerPath": "${workspaceFolder}/launch_sudo.sh", "setupCommands": [ { "description": "Enable pretty-printing for gdb", diff --git a/src/raspberrypi/.vscode/tasks.json b/src/raspberrypi/.vscode/tasks.json index eeedfe8a..850ac6dd 100644 --- a/src/raspberrypi/.vscode/tasks.json +++ b/src/raspberrypi/.vscode/tasks.json @@ -5,7 +5,7 @@ "type": "shell", "label": "g++ build active file", "command": "make", - "args": ["all", "DEBUG=1"], + "args": ["all", "DEBUG=1", "-j4"], "options": { "cwd": "${workspaceFolder}/" }, diff --git a/src/raspberrypi/Makefile b/src/raspberrypi/Makefile index c2424c65..9a9984be 100644 --- a/src/raspberrypi/Makefile +++ b/src/raspberrypi/Makefile @@ -75,6 +75,7 @@ SRC_RASCSI = \ gpiobus.cpp \ filepath.cpp \ fileio.cpp\ + os.cpp\ rascsi_version.cpp # os.cpp # rasctl_command.cpp diff --git a/src/raspberrypi/controllers/scsidev_ctrl.cpp b/src/raspberrypi/controllers/scsidev_ctrl.cpp index ce5417a2..da9b6b79 100644 --- a/src/raspberrypi/controllers/scsidev_ctrl.cpp +++ b/src/raspberrypi/controllers/scsidev_ctrl.cpp @@ -559,7 +559,7 @@ void FASTCALL SCSIDEV::CmdInquiry() if (disk) { major = (DWORD)(RASCSI >> 8); minor = (DWORD)(RASCSI & 0xff); - LOGINFO("%s Buffer size is %d",__PRETTY_FUNCTION__, ctrl.bufsize); + LOGTRACE("%s Buffer size is %d",__PRETTY_FUNCTION__, ctrl.bufsize); ctrl.length = ctrl.unit[lun]->Inquiry(ctrl.cmd, ctrl.buffer, major, minor); } else { diff --git a/src/raspberrypi/devices/ctapdriver.cpp b/src/raspberrypi/devices/ctapdriver.cpp index fd5c941c..188fda41 100644 --- a/src/raspberrypi/devices/ctapdriver.cpp +++ b/src/raspberrypi/devices/ctapdriver.cpp @@ -48,35 +48,44 @@ BOOL FASTCALL CTapDriver::Init() ASSERT(this); + LOGTRACE("Opening Tap device"); // TAP device initilization if ((m_hTAP = open("/dev/net/tun", O_RDWR)) < 0) { LOGERROR("Error: can't open tun. Errno: %d %s", errno, strerror(errno)); return FALSE; } + LOGTRACE("Opened tap device %d",m_hTAP); + // IFF_NO_PI for no extra packet information memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, dev, IFNAMSIZ); + LOGTRACE("Going to open %s", ifr.ifr_name); if ((ret = ioctl(m_hTAP, TUNSETIFF, (void *)&ifr)) < 0) { LOGERROR("Error: can't ioctl TUNSETIFF. Errno: %d %s", errno, strerror(errno)); close(m_hTAP); return FALSE; } + LOGTRACE("return code from ioctl was %d", ret); - // Force the tap interface up LOGDEBUG("ip link set ras0 up"); - system("ip link set ras0 up"); + ret = run_system_cmd("ip link set ras0 up"); + LOGTRACE("return code from ip link set ras0 up was %d", ret); + LOGDEBUG("brctl addif rascsi_bridge ras0"); - system("brctl addif rascsi_bridge ras0"); - + ret = run_system_cmd("brctl addif rascsi_bridge ras0"); + LOGTRACE("return code from brctl addif rascsi_bridge ras0 was %d", ret); + // Get MAC address + LOGTRACE("Getting the MAC address"); ifr.ifr_addr.sa_family = AF_INET; if ((ret = ioctl(m_hTAP, SIOCGIFHWADDR, &ifr)) < 0) { LOGERROR("Error: can't ioctl SIOCGIFHWADDR. Errno: %d %s", errno, strerror(errno)); close(m_hTAP); return FALSE; } + LOGTRACE("got the mac"); // Save MAC address memcpy(m_MacAddr, ifr.ifr_hwaddr.sa_data, sizeof(m_MacAddr)); @@ -141,20 +150,20 @@ BOOL FASTCALL CTapDriver::Init() void FASTCALL CTapDriver::Cleanup() { ASSERT(this); - + int result; LOGDEBUG("brctl delif rascsi_bridge ras0"); - system("brctl delif rascsi_bridge ras0"); + result = run_system_cmd("brctl delif rascsi_bridge ras0"); + if(result != EXIT_SUCCESS){ + LOGWARN("Warning: The brctl delif command failed."); + LOGWARN("You may need to manually remove the ras0 tap device from the bridge"); + } - - // Release TAP device + // Release TAP defice if (m_hTAP != -1) { close(m_hTAP); m_hTAP = -1; } - - - } //--------------------------------------------------------------------------- diff --git a/src/raspberrypi/devices/disk.cpp b/src/raspberrypi/devices/disk.cpp index e97142ed..4701b2ff 100644 --- a/src/raspberrypi/devices/disk.cpp +++ b/src/raspberrypi/devices/disk.cpp @@ -974,6 +974,7 @@ BOOL FASTCALL Disk::IsNULL() const } return FALSE; } + //--------------------------------------------------------------------------- // // Retrieve the disk's ID @@ -984,6 +985,37 @@ DWORD FASTCALL Disk::GetID() const return disk.id; } + +//--------------------------------------------------------------------------- +// +// Get cache writeback mode +// +//--------------------------------------------------------------------------- +BOOL FASTCALL Disk::IsCacheWB() +{ + return cache_wb; +} + +//--------------------------------------------------------------------------- +// +// Set cache writeback mode +// +//--------------------------------------------------------------------------- +void FASTCALL Disk::SetCacheWB(BOOL enable) +{ + cache_wb = enable; +} + +//--------------------------------------------------------------------------- +// +// Set unsupported command +// +//--------------------------------------------------------------------------- +void FASTCALL Disk::InvalidCmd() +{ + disk.code = DISK_INVALIDCMD; +} + //--------------------------------------------------------------------------- // // SASI Check diff --git a/src/raspberrypi/devices/disk.h b/src/raspberrypi/devices/disk.h index ae9e5de9..5f8e9da3 100644 --- a/src/raspberrypi/devices/disk.h +++ b/src/raspberrypi/devices/disk.h @@ -328,13 +328,13 @@ public: // PLAY AUDIO MSF command virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb); // PLAY AUDIO TRACK command - void FASTCALL InvalidCmd() { disk.code = DISK_INVALIDCMD; } + void FASTCALL InvalidCmd(); // Unsupported command // Other - BOOL IsCacheWB() { return cache_wb; } + BOOL FASTCALL IsCacheWB(); // Get cache writeback mode - void SetCacheWB(BOOL enable) { cache_wb = enable; } + void FASTCALL SetCacheWB(BOOL enable); // Set cache writeback mode protected: diff --git a/src/raspberrypi/devices/scsi_daynaport.cpp b/src/raspberrypi/devices/scsi_daynaport.cpp index ff8ec5f6..6eebad4c 100644 --- a/src/raspberrypi/devices/scsi_daynaport.cpp +++ b/src/raspberrypi/devices/scsi_daynaport.cpp @@ -38,10 +38,6 @@ const char* SCSIDaynaPort::m_firmware_version = "01.00.00"; const BYTE SCSIDaynaPort::m_bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; const BYTE SCSIDaynaPort::m_apple_talk_addr[6] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff }; -#ifndef NDEBUG -static DWORD file_counter = 0; -#endif - //--------------------------------------------------------------------------- // // Constructor @@ -63,11 +59,13 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk() LOGINFO("Tap interface created") } + LOGTRACE("%s this->reset()", __PRETTY_FUNCTION__); this->Reset(); disk.ready = true; disk.reset = false; // Generate MAC Address + LOGTRACE("%s memset(m_mac_addr, 0x00, 6);", __PRETTY_FUNCTION__); memset(m_mac_addr, 0x00, 6); // if (m_bTapEnable) { @@ -76,6 +74,7 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk() // } // !!!!!!!!!!!!!!!!! For now, hard code the MAC address. Its annoying when it keeps changing during development! // TODO: Remove this hard-coded address + LOGTRACE("%s m_mac_addr[0]=0x00;", __PRETTY_FUNCTION__); m_mac_addr[0]=0x00; m_mac_addr[1]=0x80; m_mac_addr[2]=0x19; @@ -299,8 +298,6 @@ int FASTCALL SCSIDaynaPort::Read(const DWORD *cdb, BYTE *buf, DWORD block) buf[5] = 0; } - LOGTRACE("%s Packet of size %d received [Counter: %d]", __PRETTY_FUNCTION__, (int)rx_packet_size, (int)file_counter); - // Return the packet size + 2 for the length + 4 for the flag field // The CRC was already appended by the ctapdriver return rx_packet_size + m_read_header_size; diff --git a/src/raspberrypi/os.cpp b/src/raspberrypi/os.cpp new file mode 100644 index 00000000..50711802 --- /dev/null +++ b/src/raspberrypi/os.cpp @@ -0,0 +1,35 @@ +//--------------------------------------------------------------------------- +// +// SCSI Target Emulator RaSCSI (*^..^*) +// for Raspberry Pi +// +// Powered by XM6 TypeG Technology. +// Copyright (C) 2016-2020 GIMONS +// Copyright (C) 2020-2021 akuker +// +// [ OS related definitions ] +// +//--------------------------------------------------------------------------- + +#include "os.h" +#include + + +//--------------------------------------------------------------------------- +// +// Run system command and wait for it to finish +// +//--------------------------------------------------------------------------- +int run_system_cmd(const char* command) +{ + pid_t pid; + int result; + int status = 0; + pid=fork(); + if(pid == 0){ + result = system(command); + exit(result); + } + waitpid(pid, &status, 0); + return status; +} \ No newline at end of file diff --git a/src/raspberrypi/os.h b/src/raspberrypi/os.h index cb145f7e..9cb9f31e 100644 --- a/src/raspberrypi/os.h +++ b/src/raspberrypi/os.h @@ -155,4 +155,7 @@ typedef const char *LPCSTR; #define xstrcasecmp strcasecmp #define xstrncasecmp strncasecmp +// Run system command and wait for it to finish +extern int run_system_cmd(const char* command); + #endif // os_h diff --git a/src/raspberrypi/os_integration/rascsi.service b/src/raspberrypi/os_integration/rascsi.service index d5072387..62fe6528 100644 --- a/src/raspberrypi/os_integration/rascsi.service +++ b/src/raspberrypi/os_integration/rascsi.service @@ -9,7 +9,7 @@ ExecStart=/usr/local/bin/rascsi # Example: If you want to automatically attach a hard disk at startup, change # the ExecStart line to: # ExecStart=/usr/local/bin/rascsi -ID1 /home/pi/images/harddisk.hda -ExecStop=/usr/local/bin/rasctl -stop +# This functionality isn't implmented yet: ExecStop=/usr/local/bin/rasctl -stop StandardOutput=syslog StandardError=syslog SyslogIdentifier=RASCSI diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 331359a3..b08924a6 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -297,6 +297,8 @@ void ListDevice(FILE *fp) // mount status output if (pUnit->GetID() == MAKEID('S', 'C', 'B', 'R')) { FPRT(fp, "%s", "HOST BRIDGE"); + } else if (pUnit->GetID() == MAKEID('S', 'C', 'D', 'P')) { + FPRT(fp, "%s", "DaynaPort SCSI/Link"); } else { pUnit->GetPath(filepath); FPRT(fp, "%s", @@ -526,6 +528,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file) // break; case rasctl_dev_daynaport: // DaynaPort SCSI Link pUnit = new SCSIDaynaPort(); + LOGTRACE("Done creating SCSIDayanPort"); break; default: FPRT(fp, "Error : Invalid device type\n"); @@ -533,7 +536,7 @@ BOOL ProcessCmd(FILE *fp, int id, int un, int cmd, int type, char *file) } // drive checks files - if (type <= 1 || (type <= 3 && xstrcasecmp(file, "-") != 0)) { + if (type <= rasctl_dev_scsi_hd || (type <= rasctl_dev_cd && xstrcasecmp(file, "-") != 0)) { // Set the Path filepath.SetPath(file);