Browse Source

The bootloaderhost utility is now working under Linux.

Michael McMaster 12 năm trước cách đây
mục cha
commit
42c6fd6e74

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 68
lib/SCSI2SD/software/SCSI2SD/USB_Bootloader.cydsn/CortexM3/ARM_GCC_473/Release/.deps/ARM_C_FILE.P


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 112 - 112
lib/SCSI2SD/software/SCSI2SD/USB_Bootloader.cydsn/CortexM3/ARM_GCC_473/Release/BL.lst


+ 7 - 4
lib/SCSI2SD/software/SCSI2SD/USB_Bootloader.cydsn/CortexM3/ARM_GCC_473/Release/USB_Bootloader-ARM_GCC_473-Release-BUILD.log

@@ -1,8 +1,11 @@
---------------- Build Started: 10/26/2013 23:47:14 Project: USB_Bootloader, Configuration: ARM GCC 4.7.3 Release ---------------
+--------------- Build Started: 10/27/2013 11:12:40 Project: USB_Bootloader, Configuration: ARM GCC 4.7.3 Release ---------------
 The code generation step is up to date.
-The compile step is up to date, no work needs to be done.
-The link step is up to date, no work needs to be done.
+arm-none-eabi-gcc.exe -I. -I./Generated_Source/PSoC5 -Wno-main -mcpu=cortex-m3 -mthumb -Wall -g -D NDEBUG -Wa,-alh=.\CortexM3\ARM_GCC_473\Release\BL.lst -Os -ffunction-sections -c .\Generated_Source\PSoC5\BL.c -o .\CortexM3\ARM_GCC_473\Release\BL.o
+arm-none-eabi-ar.exe -rs .\CortexM3\ARM_GCC_473\Release\USB_Bootloader.a .\CortexM3\ARM_GCC_473\Release\cyfitter_cfg.o .\CortexM3\ARM_GCC_473\Release\USBFS.o .\CortexM3\ARM_GCC_473\Release\USBFS_audio.o .\CortexM3\ARM_GCC_473\Release\USBFS_boot.o .\CortexM3\ARM_GCC_473\Release\USBFS_cdc.o .\CortexM3\ARM_GCC_473\Release\USBFS_cls.o .\CortexM3\ARM_GCC_473\Release\USBFS_descr.o .\CortexM3\ARM_GCC_473\Release\USBFS_drv.o .\CortexM3\ARM_GCC_473\Release\USBFS_episr.o .\CortexM3\ARM_GCC_473\Release\USBFS_hid.o .\CortexM3\ARM_GCC_473\Release\USBFS_pm.o .\CortexM3\ARM_GCC_473\Release\USBFS_std.o .\CortexM3\ARM_GCC_473\Release\USBFS_vnd.o .\CortexM3\ARM_GCC_473\Release\USBFS_midi.o .\CortexM3\ARM_GCC_473\Release\BL.o .\CortexM3\ARM_GCC_473\Release\USBFS_Dm.o .\CortexM3\ARM_GCC_473\Release\USBFS_Dp.o .\CortexM3\ARM_GCC_473\Release\CyBootAsmGnu.o .\CortexM3\ARM_GCC_473\Release\CyDmac.o .\CortexM3\ARM_GCC_473\Release\CyFlash.o .\CortexM3\ARM_GCC_473\Release\CyLib.o .\CortexM3\ARM_GCC_473\Release\cyPm.o .\CortexM3\ARM_GCC_473\Release\CySpc.o .\CortexM3\ARM_GCC_473\Release\cyutils.o
+arm-none-eabi-ar.exe: creating .\CortexM3\ARM_GCC_473\Release\USB_Bootloader.a
+arm-none-eabi-gcc.exe -mthumb -march=armv7-m -mfix-cortex-m3-ldrd -T .\Generated_Source\PSoC5\cm3gcc.ld -g -Wl,-Map,.\CortexM3\ARM_GCC_473\Release\USB_Bootloader.map -specs=nano.specs -Wl,--gc-sections -Wl,--start-group -o .\CortexM3\ARM_GCC_473\Release\USB_Bootloader.elf .\CortexM3\ARM_GCC_473\Release\main.o .\CortexM3\ARM_GCC_473\Release\cymetadata.o .\CortexM3\ARM_GCC_473\Release\Cm3Start.o .\CortexM3\ARM_GCC_473\Release\USB_Bootloader.a "C:\Program Files (x86)\Cypress\PSoC Creator\3.0\PSoC Creator\psoc\content\cycomponentlibrary\CyComponentLibrary.cylib\CortexM3\ARM_GCC_473\Release\CyComponentLibrary.a" -Wl,--end-group
+cyelftool.exe -P W:\SCSI2SD\USB_Bootloader.cydsn\CortexM3\ARM_GCC_473\Release\USB_Bootloader.elf --flash_row_size 256 --flash_size 131072 --size_var_name BL_SizeBytes --checksum_var_name BL_Checksum
 cyelftool.exe -S W:\SCSI2SD\USB_Bootloader.cydsn\CortexM3\ARM_GCC_473\Release\USB_Bootloader.elf
 Flash used: 8856 of 131072 bytes (6.8 %).
 SRAM used: 10869 of 32768 bytes (33.2 %).
---------------- Build Succeeded: 10/26/2013 23:47:16 ---------------
+--------------- Build Succeeded: 10/27/2013 11:12:50 ---------------

BIN
lib/SCSI2SD/software/SCSI2SD/USB_Bootloader.cydsn/CortexM3/ARM_GCC_473/Release/USB_Bootloader.a


+ 9 - 9
lib/SCSI2SD/software/SCSI2SD/USB_Bootloader.cydsn/USB_Bootloader.cyprj.Micha_000

@@ -12,7 +12,7 @@
 <CyGuid_f44455c5-3770-4452-b988-0a7a7ff46256 type_name="CyDesigner.Common.ProjMgmt.Model.CyConfigDependencies" version="1">
 <dependency_info name="c9323d49-d323-40b8-9b59-cc008d68a989@Release@CortexM3" xml_contents_version="2">
 <CyGuid_1173175f-1b9b-4ad4-a065-754a48a27021 type_name="CyDesigner.Common.Base.CyFileDeps" version="1">
-<file name=".\CortexM3\ARM_GCC_473\Release\main.o">
+<file name=".\CortexM3\ARM_GCC_473\Release\BL.o">
 <dep name=".\Generated_Source\PSoC5\BL.h" />
 <dep name=".\Generated_Source\PSoC5\BL_PVT.h" />
 <dep name=".\Generated_Source\PSoC5\CyDmac.h" />
@@ -44,7 +44,7 @@
 <dep name=".\Generated_Source\PSoC5\cypins.h" />
 <dep name=".\Generated_Source\PSoC5\cytypes.h" />
 <dep name=".\Generated_Source\PSoC5\project.h" />
-<dep name=".\main.c" />
+<dep name=".\Generated_Source\PSoC5\BL.c" />
 </file>
 <file name=".\Generated_Source\PSoC5\BL.h" />
 <file name=".\Generated_Source\PSoC5\BL_PVT.h" />
@@ -77,8 +77,8 @@
 <file name=".\Generated_Source\PSoC5\cypins.h" />
 <file name=".\Generated_Source\PSoC5\cytypes.h" />
 <file name=".\Generated_Source\PSoC5\project.h" />
-<file name=".\main.c" />
-<file name=".\CortexM3\ARM_GCC_473\Release\BL.o">
+<file name=".\Generated_Source\PSoC5\BL.c" />
+<file name=".\CortexM3\ARM_GCC_473\Release\main.o">
 <dep name=".\Generated_Source\PSoC5\BL.h" />
 <dep name=".\Generated_Source\PSoC5\BL_PVT.h" />
 <dep name=".\Generated_Source\PSoC5\CyDmac.h" />
@@ -110,9 +110,9 @@
 <dep name=".\Generated_Source\PSoC5\cypins.h" />
 <dep name=".\Generated_Source\PSoC5\cytypes.h" />
 <dep name=".\Generated_Source\PSoC5\project.h" />
-<dep name=".\Generated_Source\PSoC5\BL.c" />
+<dep name=".\main.c" />
 </file>
-<file name=".\Generated_Source\PSoC5\BL.c" />
+<file name=".\main.c" />
 <file name=".\CortexM3\ARM_GCC_473\Release\Cm3Start.o">
 <dep name=".\Generated_Source\PSoC5\CyDmac.h" />
 <dep name=".\Generated_Source\PSoC5\CyFlash.h" />
@@ -1060,7 +1060,7 @@
 </dataGuid>
 <dataGuid v="769d31ea-68b1-4f0c-b90a-7c10a43ee563">
 <CyGuid_769d31ea-68b1-4f0c-b90a-7c10a43ee563 type_name="CyDesigner.Common.ProjMgmt.Model.CyLinkCustomData" version="1">
-<deps_time v="130272513693327039" />
+<deps_time v="130273099690675686" />
 </CyGuid_769d31ea-68b1-4f0c-b90a-7c10a43ee563>
 </dataGuid>
 <dataGuid v="bf610382-39c6-441f-80b8-b04622ea7845">
@@ -1071,8 +1071,8 @@
 <dataGuid v="504337dd-7d07-4bc7-9057-90e60cf6c469">
 <CyGuid_504337dd-7d07-4bc7-9057-90e60cf6c469 type_name="CyDesigner.Common.Debugger.CyBreakpointList" version="1">
 <debugger_breakpoint_list>
-<CyGuid_76464711-0ae1-4583-b869-f07a0403fc6e type_name="CyDesigner.Common.Debugger.CyFileLineBreakpoint" version="1" hitcount="0" condition="" enabled="True" hardware="True" temparary="False" filename=".\Generated_Source\PSoC5\BL.c" linenumber="354" />
-<CyGuid_76464711-0ae1-4583-b869-f07a0403fc6e type_name="CyDesigner.Common.Debugger.CyFileLineBreakpoint" version="1" hitcount="0" condition="" enabled="True" hardware="True" temparary="False" filename=".\Generated_Source\PSoC5\BL.c" linenumber="575" />
+<CyGuid_76464711-0ae1-4583-b869-f07a0403fc6e type_name="CyDesigner.Common.Debugger.CyFileLineBreakpoint" version="1" hitcount="0" condition="" enabled="False" hardware="True" temparary="False" filename=".\Generated_Source\PSoC5\BL.c" linenumber="354" />
+<CyGuid_76464711-0ae1-4583-b869-f07a0403fc6e type_name="CyDesigner.Common.Debugger.CyFileLineBreakpoint" version="1" hitcount="0" condition="" enabled="False" hardware="True" temparary="False" filename=".\Generated_Source\PSoC5\BL.c" linenumber="575" />
 </debugger_breakpoint_list>
 </CyGuid_504337dd-7d07-4bc7-9057-90e60cf6c469>
 </dataGuid>

+ 23 - 2
lib/SCSI2SD/software/bootloaderhost/Makefile

@@ -1,4 +1,25 @@
 all:  bootloaderhost
 
-bootloaderhost: main.c
-	gcc -g -I cybootloaderutils -I hidapi/hidapi main.c hidapi/linux/hid.c cybootloaderutils/cybtldr_api2.c cybootloaderutils/cybtldr_api.c cybootloaderutils/cybtldr_command.c cybootloaderutils/cybtldr_parse.c -ludev -o $@
+CYAPI = \
+	cybootloaderutils/cybtldr_api2.c \
+	cybootloaderutils/cybtldr_api.c \
+	cybootloaderutils/cybtldr_command.c \
+	cybootloaderutils/cybtldr_parse.c \
+
+
+UNAME_S := $(shell uname -s)
+ifeq ($(UNAME_S),Linux)
+	HID_C = hidapi/linux/hid.c
+	LDFLAGS += -ludev
+endif
+ifeq ($(UNAME_S),Darwin)
+	# Should match OSX
+	HID_C = hidapi/mac/hid.c
+endif
+
+
+bootloaderhost: main.c $(HID_C) $(CYAPI)
+	$(CC) $(CFLAGS) -g -I cybootloaderutils -I hidapi/hidapi $^ $(LDFLAGS) -o $@
+
+clean:
+	rm bootloaderhost

+ 118 - 20
lib/SCSI2SD/software/bootloaderhost/main.c

@@ -1,5 +1,26 @@
+//	Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
+//
+//	This file is part of SCSI2SD.
+//
+//	SCSI2SD is free software: you can redistribute it and/or modify
+//	it under the terms of the GNU General Public License as published by
+//	the Free Software Foundation, either version 3 of the License, or
+//	(at your option) any later version.
+//
+//	SCSI2SD is distributed in the hope that it will be useful,
+//	but WITHOUT ANY WARRANTY; without even the implied warranty of
+//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//	GNU General Public License for more details.
+//
+//	You should have received a copy of the GNU General Public License
+//	along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
+
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 
 #include "hidapi.h"
 #include "cybtldr_api.h"
@@ -19,8 +40,19 @@ static int CloseConnection(void)
 
 static int ReadData(unsigned char* data, int count)
 {
-printf("read");
-	return (hid_read(handle, data, count) >= 0 ? 0 : -1);
+	unsigned char buf[65];
+	buf[0] = 0; // Report ID
+
+	int result = hid_read(handle, buf, count);
+
+	if (result < 0)
+	{
+		fprintf(stderr, "USB HID Read Failure: %ls\n", hid_error(handle));
+	}
+
+	memcpy(data, buf, count);
+
+	return (result >= 0) ? 0 : -1;
 }
 
 static int WriteData(unsigned char* data, int count)
@@ -32,26 +64,30 @@ static int WriteData(unsigned char* data, int count)
 	{
 		buf[i+1] = data[i];
 	}
-	//int result = hid_write(handle, buf, 65);
-	int result = hid_send_feature_report(handle, buf, count + 1);
-printf("write %d, %d", count, result);
+	int result = hid_write(handle, buf, count + 1);
+
+	if (result < 0)
+	{
+		fprintf(stderr, "USB HID Write Failure: %ls\n", hid_error(handle));
+	}
+
 	return (result >= 0) ? 0 : -1;
 }
 
 
 static void ProgressUpdate(unsigned char arrayId, unsigned short rowNum)
 {
-	printf("Completed array %d, row %d\n", arrayId, rowNum);
+	printf("Programmed flash array %d, row %d\n", arrayId, rowNum);
 }
 
-int main(int argc, char* argv[])
+static void usage()
 {
-	int res;
-	unsigned char buf[65];
-	#define MAX_STR 255
-	wchar_t wstr[MAX_STR];
-	int i;
+	printf("Usage: bootloaderhost [-v UsbVendorId] [-p UsbProductId] /path/to/firmware.cyacd\n");
+	printf("\n\n");
+}
 
+int main(int argc, char* argv[])
+{
 	CyBtldr_CommunicationsData cyComms =
 	{
 		&OpenConnection,
@@ -61,15 +97,61 @@ int main(int argc, char* argv[])
 		64
 	};
 
+	printf("PSoC 3/5LP USB HID Bootloader Host\n");
+	printf("Copyright (C) 2013 Michael McMaster <michael@codesrc.com>\n\n");
+
+	uint16_t vendorId = 0x04B4; // Cypress
+	uint16_t productId = 0xB71D; // Default PSoC3/5LP Bootloader
+
+	opterr = 0;
+	int c;
+	while ((c = getopt(argc, argv, "v:p:")) != -1)
+	{
+		switch (c)
+		{
+		case 'v':
+			sscanf(optarg, "%x", &vendorId);
+			break;
+		case 'p':
+			sscanf(optarg, "%x", &productId);
+			break;
+		case '?':
+			usage();
+			exit(1);
+		}
+	}
+
+	const char* filename;
+	if (optind < argc)
+	{
+		filename = argv[optind];
+	}
+	else
+	{
+		usage();
+		exit(1);
+	}
+
+	printf(
+		"USB device parameters\n\tVendor ID:\t0x%04X\n\tProduct ID:\t0x%04X\n",
+		vendorId,
+		productId);
+
 	// Enumerate and print the HID devices on the system
-	struct hid_device_info *dev = NULL;
+	struct hid_device_info *dev = hid_enumerate(vendorId, productId);
 
-	printf("Waiting for a mate\n");
-	while (dev == NULL)
+	if (!dev)
 	{
-		dev = hid_enumerate(0x04B4, 0xB71D);
+		printf("Waiting for device connection\n");
+		printf("Connect USB cable to the bus-powered device now, or otherwise reset the device.\n");
+	}
+
+	while (!dev)
+	{
+		dev = hid_enumerate(vendorId, productId);
 		usleep(10000); // 10ms
 	}
+
 	printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls",
 		dev->vendor_id, dev->product_id, dev->path, dev->serial_number);
 	printf("\n");
@@ -80,14 +162,30 @@ int main(int argc, char* argv[])
 
 	// Open the device using the VID, PID,
 	// and optionally the Serial number.
-	handle = hid_open(0x04B4, 0xB71D, NULL);
+	handle = hid_open(vendorId, productId, NULL);
+	if (!handle)
+	{
+		fprintf(
+			stderr,
+			"Could not open device %s. Check permissions.\n", dev->path
+			);
+		exit(1);
+	}
 
 
-	printf("Tryng to program\n");
-	int result = CyBtldr_Program("/home/michael/projects/SCSI2SD/git/software/SCSI2SD/SCSI2SD.cydsn/CortexM3/ARM_GCC_473/Release/SCSI2SD.cyacd",
+	printf("Starting firmware upload: %s\n", filename);
+	int result = CyBtldr_Program(
+		filename,
 		&cyComms,
 		&ProgressUpdate);
-	printf("Possibly successful ? %d\n", result);
+	if (result == 0)
+	{
+		printf("Firmware update complete\n");
+	}
+	else
+	{
+		printf("Firmware update failed\n");
+	}
 
 	return 0;
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác