forked from len0rd/rockbox
Implement sendfirm functionality in beastpatcher. Set svn:eol-style properties.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21260 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1240216a75
commit
11fa12c366
10 changed files with 1242 additions and 1040 deletions
|
@ -30,22 +30,22 @@ CC = $(CROSS)gcc
|
||||||
|
|
||||||
all: $(OUTPUT)
|
all: $(OUTPUT)
|
||||||
|
|
||||||
beastpatcher: beastpatcher.c bootimg.c mtp_common.h mtp_libmtp.c
|
beastpatcher: beastpatcher.c bootimg.c mtp_common.h mtp_libmtp.c main.c
|
||||||
gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c $(LIBS)
|
gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c main.c $(LIBS)
|
||||||
strip beastpatcher
|
strip beastpatcher
|
||||||
|
|
||||||
beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c $(WINLIBS)
|
beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c main.c $(WINLIBS)
|
||||||
$(CC) $(CFLAGS) -o beastpatcher.exe beastpatcher.c bootimg.c mtp_win32.c $(WINLIBS)
|
$(CC) $(CFLAGS) -o beastpatcher.exe beastpatcher.c bootimg.c mtp_win32.c main.c $(WINLIBS)
|
||||||
$(CROSS)strip beastpatcher.exe
|
$(CROSS)strip beastpatcher.exe
|
||||||
|
|
||||||
beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc
|
beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc
|
||||||
lipo -create beastpatcher-ppc beastpatcher-i386 -output beastpatcher-mac
|
lipo -create beastpatcher-ppc beastpatcher-i386 -output beastpatcher-mac
|
||||||
|
|
||||||
beastpatcher-i386: beastpatcher.c bootimg.c usb.h libusb-i386.a
|
beastpatcher-i386: beastpatcher.c bootimg.c usb.h main.c libusb-i386.a
|
||||||
$(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch i386 $(CFLAGS) -o beastpatcher-i386 beastpatcher.c bootimg.c -I. libusb-i386.a
|
$(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch i386 $(CFLAGS) -o beastpatcher-i386 beastpatcher.c bootimg.c -I. libusb-i386.a
|
||||||
strip beastpatcher-i386
|
strip beastpatcher-i386
|
||||||
|
|
||||||
beastpatcher-ppc: beastpatcher.c bootimg.c usb.h libusb-ppc.a
|
beastpatcher-ppc: beastpatcher.c bootimg.c usb.h main.c libusb-ppc.a
|
||||||
$(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch ppc $(CFLAGS) -o beastpatcher-ppc beastpatcher.c bootimg.c -I. libusb-ppc.a
|
$(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch ppc $(CFLAGS) -o beastpatcher-ppc beastpatcher.c bootimg.c -I. libusb-ppc.a
|
||||||
strip beastpatcher-ppc
|
strip beastpatcher-ppc
|
||||||
|
|
||||||
|
|
|
@ -55,18 +55,6 @@
|
||||||
#include "mtp_common.h"
|
#include "mtp_common.h"
|
||||||
#include "bootimg.h"
|
#include "bootimg.h"
|
||||||
|
|
||||||
#define VERSION "1.0 with v1 bootloader"
|
|
||||||
|
|
||||||
void print_usage(void)
|
|
||||||
{
|
|
||||||
fprintf(stderr,"Usage: beastpatcher [action]\n");
|
|
||||||
fprintf(stderr,"\n");
|
|
||||||
fprintf(stderr,"Where [action] is one of the following options:\n");
|
|
||||||
fprintf(stderr," --install (default)\n");
|
|
||||||
fprintf(stderr," -?, --help\n");
|
|
||||||
fprintf(stderr,"\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Code to create a single-boot bootloader.
|
/* Code to create a single-boot bootloader.
|
||||||
Based on tools/gigabeats.c by Will Robertson.
|
Based on tools/gigabeats.c by Will Robertson.
|
||||||
*/
|
*/
|
||||||
|
@ -139,27 +127,13 @@ static void create_single_boot(unsigned char* boot, int bootlen,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int beastpatcher(int argc, char* argv[])
|
int beastpatcher(void)
|
||||||
{
|
{
|
||||||
char yesno[4];
|
char yesno[4];
|
||||||
unsigned char* fwbuf;
|
unsigned char* fwbuf;
|
||||||
int fwsize;
|
int fwsize;
|
||||||
struct mtp_info_t mtp_info;
|
struct mtp_info_t mtp_info;
|
||||||
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
|
|
||||||
fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
|
|
||||||
fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
|
|
||||||
|
|
||||||
/* No options are currently implemented, so just display help if any are
|
|
||||||
provided. */
|
|
||||||
|
|
||||||
if (argc > 1) {
|
|
||||||
print_usage();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mtp_init(&mtp_info) < 0) {
|
if (mtp_init(&mtp_info) < 0) {
|
||||||
fprintf(stderr,"[ERR] Can not init MTP\n");
|
fprintf(stderr,"[ERR] Can not init MTP\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -212,16 +186,3 @@ int beastpatcher(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
char yesno[4];
|
|
||||||
|
|
||||||
res = beastpatcher(argc, argv);
|
|
||||||
|
|
||||||
printf("\nPress ENTER to exit beastpatcher: ");
|
|
||||||
fgets(yesno,4,stdin);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
45
utils/MTP/beastpatcher/beastpatcher.h
Normal file
45
utils/MTP/beastpatcher/beastpatcher.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009, Dave Chapman
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer in the documentation and/or other materials provided
|
||||||
|
* with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef BEASTPATCHER_H
|
||||||
|
#define BEASTPATCHER_H
|
||||||
|
|
||||||
|
int beastpatcher(void);
|
||||||
|
|
||||||
|
#endif
|
93
utils/MTP/beastpatcher/main.c
Normal file
93
utils/MTP/beastpatcher/main.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009, Dave Chapman
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer in the documentation and/or other materials provided
|
||||||
|
* with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "beastpatcher.h"
|
||||||
|
#include "mtp_common.h"
|
||||||
|
|
||||||
|
#if defined(__WIN32__) || defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define VERSION "1.0 with v1 bootloader"
|
||||||
|
|
||||||
|
#include "../MTP_DLL/MTP_DLL.h"
|
||||||
|
|
||||||
|
static void print_usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Usage: beastpatcher [action]\n");
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
fprintf(stderr,"Where [action] is one of the following options:\n");
|
||||||
|
fprintf(stderr," -i, --install (default)\n");
|
||||||
|
fprintf(stderr," -h, --help\n");
|
||||||
|
fprintf(stderr," -s, --send nk.bin\n");
|
||||||
|
fprintf(stderr,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
char yesno[4];
|
||||||
|
struct mtp_info_t mtp_info;
|
||||||
|
|
||||||
|
fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
|
||||||
|
fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
|
||||||
|
fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
|
||||||
|
|
||||||
|
if(argc == 1 || strcmp(argv[1],"-i")==0 || strcmp(argv[1],"--install")==0) {
|
||||||
|
res = beastpatcher();
|
||||||
|
/* don't ask for enter if started with command line arguments */
|
||||||
|
if(argc == 1) {
|
||||||
|
printf("\nPress ENTER to exit beastpatcher: ");
|
||||||
|
fgets(yesno,4,stdin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if((argc > 2) && ((strcmp(argv[1],"-s")==0) || (strcmp(argv[1],"--send")==0))) {
|
||||||
|
res = mtp_send_file(&mtp_info, argv[2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print_usage();
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,5 +66,6 @@ int mtp_finished(struct mtp_info_t* mtp_info);
|
||||||
int mtp_scan(struct mtp_info_t* mtp_info);
|
int mtp_scan(struct mtp_info_t* mtp_info);
|
||||||
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
int fwsize);
|
int fwsize);
|
||||||
|
int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename);
|
||||||
|
|
||||||
#endif /* !_MTP_COMMON_H */
|
#endif /* !_MTP_COMMON_H */
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
#include "libmtp.h"
|
#include "libmtp.h"
|
||||||
#include "mtp_common.h"
|
#include "mtp_common.h"
|
||||||
|
|
||||||
|
static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize);
|
||||||
|
|
||||||
int mtp_init(struct mtp_info_t* mtp_info)
|
int mtp_init(struct mtp_info_t* mtp_info)
|
||||||
{
|
{
|
||||||
/* Fill the info struct with zeros - mainly for the strings */
|
/* Fill the info struct with zeros - mainly for the strings */
|
||||||
|
@ -117,7 +119,6 @@ static int progress(uint64_t const sent, uint64_t const total,
|
||||||
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
int fwsize)
|
int fwsize)
|
||||||
{
|
{
|
||||||
LIBMTP_file_t *genfile;
|
|
||||||
int ret;
|
int ret;
|
||||||
size_t n;
|
size_t n;
|
||||||
FILE* fwfile;
|
FILE* fwfile;
|
||||||
|
@ -142,6 +143,20 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
/* Reset file pointer */
|
/* Reset file pointer */
|
||||||
fseek(fwfile, SEEK_SET, 0);
|
fseek(fwfile, SEEK_SET, 0);
|
||||||
|
|
||||||
|
ret = mtp_send_fileptr(mtp_info, fwfile, fwsize);
|
||||||
|
|
||||||
|
/* Close the temporary file - this also deletes it. */
|
||||||
|
fclose(fwfile);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize)
|
||||||
|
{
|
||||||
|
LIBMTP_file_t* genfile;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Prepare for uploading firmware */
|
/* Prepare for uploading firmware */
|
||||||
genfile = LIBMTP_new_file_t();
|
genfile = LIBMTP_new_file_t();
|
||||||
genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
|
genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
|
||||||
|
@ -167,8 +182,35 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
LIBMTP_destroy_file_t(genfile);
|
LIBMTP_destroy_file_t(genfile);
|
||||||
|
|
||||||
/* Close the temporary file - this also deletes it. */
|
return ret;
|
||||||
fclose(fwfile);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename)
|
||||||
|
{
|
||||||
|
FILE* fwfile;
|
||||||
|
int ret;
|
||||||
|
#ifdef _LARGEFILE64_SOURCE
|
||||||
|
struct stat64 sb;
|
||||||
|
ret = stat64(filename, &sb);
|
||||||
|
#else
|
||||||
|
struct stat sb;
|
||||||
|
ret = stat(filename, &sb);
|
||||||
|
#endif
|
||||||
|
if (ret == -1)
|
||||||
|
{
|
||||||
|
perror("[ERR] ");
|
||||||
|
}
|
||||||
|
|
||||||
|
fwfile = fopen(filename, "r");
|
||||||
|
if (fwfile == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[ERR] Could not create temporary file.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ret = mtp_send_fileptr(mtp_info, fwfile, sb.st_size);
|
||||||
|
|
||||||
|
fclose(fwfile);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,18 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "mtp_common.h"
|
#include "mtp_common.h"
|
||||||
|
|
||||||
#include "../MTP_DLL/MTP_DLL.h"
|
#include "../MTP_DLL/MTP_DLL.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int filesize(const char* filename);
|
||||||
|
|
||||||
|
|
||||||
int mtp_init(struct mtp_info_t* mtp_info)
|
int mtp_init(struct mtp_info_t* mtp_info)
|
||||||
{
|
{
|
||||||
/* Fill the info struct with zeros - mainly for the strings */
|
/* Fill the info struct with zeros - mainly for the strings */
|
||||||
|
@ -87,7 +93,7 @@ static void callback(unsigned int progress, unsigned int max)
|
||||||
{
|
{
|
||||||
int percent = (progress * 100) / max;
|
int percent = (progress * 100) / max;
|
||||||
|
|
||||||
printf("Progress: %u of %u (%d%%)\r", progress, max, percent);
|
printf("[INFO] Progress: %u of %u (%d%%)\r", progress, max, percent);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,18 +163,16 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
fprintf(stderr, "[INFO] Sending firmware...\n");
|
fprintf(stderr, "[INFO] Sending firmware...\n");
|
||||||
if (mtp_sendnk(tmp, fwsize, &callback))
|
if (mtp_sendnk(tmp, fwsize, &callback))
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, "[ERR] Error occured during sending.\n");
|
fprintf(stderr, "[ERR] Error occured during sending.\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep the progress line onscreen */
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
if (!DeleteFile(szTempName))
|
if (!DeleteFile(szTempName))
|
||||||
|
@ -177,3 +181,51 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename)
|
||||||
|
{
|
||||||
|
wchar_t *fn;
|
||||||
|
|
||||||
|
fn = (LPWSTR)malloc(strlen(filename)*2+1);
|
||||||
|
mbstowcs(fn, filename, strlen(filename)*2+1);
|
||||||
|
|
||||||
|
if (mtp_init(mtp_info) < 0) {
|
||||||
|
fprintf(stderr,"[ERR] Can not init MTP\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* Scan for attached MTP devices. */
|
||||||
|
if (mtp_scan(mtp_info) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"[ERR] No devices found\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "[INFO] Sending firmware...\n");
|
||||||
|
if (mtp_sendnk(fn, filesize(filename), &callback))
|
||||||
|
{
|
||||||
|
/* keep progress on screen */
|
||||||
|
printf("\n");
|
||||||
|
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "[ERR] Error occured during sending.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
mtp_finished(mtp_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int filesize(const char* filename)
|
||||||
|
{
|
||||||
|
struct _stat sb;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = _stat(filename, &sb);
|
||||||
|
if(res == -1) {
|
||||||
|
fprintf(stderr, "Error getting filesize!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return sb.st_size;
|
||||||
|
}
|
||||||
|
|
|
@ -188,6 +188,10 @@
|
||||||
RelativePath="..\bootimg.c"
|
RelativePath="..\bootimg.c"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\main.c"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\mtp_win32.c"
|
RelativePath="..\mtp_win32.c"
|
||||||
>
|
>
|
||||||
|
@ -198,6 +202,10 @@
|
||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\beastpatcher.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\bootimg.h"
|
RelativePath="..\bootimg.h"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue