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
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pstdint.h: A portable stdint.h
|
pstdint.h: A portable stdint.h
|
||||||
|
|
||||||
This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h
|
This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h
|
||||||
|
|
||||||
Copyright (c) 2005-2007 Paul Hsieh
|
Copyright (c) 2005-2007 Paul Hsieh
|
||||||
Licensed under the BSD License. See file header for details.
|
Licensed under the BSD License. See file header for details.
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
||||||
|
@ -74,8 +76,8 @@ int mtp_scan(struct mtp_info_t* mtp_info)
|
||||||
if (mtp_info->device == NULL)
|
if (mtp_info->device == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* NOTE: These strings are filled with zeros in mtp_init() */
|
/* NOTE: These strings are filled with zeros in mtp_init() */
|
||||||
#ifndef REALLYOLDMTP
|
#ifndef REALLYOLDMTP
|
||||||
|
@ -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;
|
||||||
|
@ -149,10 +164,10 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
genfile->filesize = fwsize;
|
genfile->filesize = fwsize;
|
||||||
|
|
||||||
#ifdef OLDMTP
|
#ifdef OLDMTP
|
||||||
ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
|
ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
|
||||||
fileno(fwfile), genfile, progress, NULL, 0);
|
fileno(fwfile), genfile, progress, NULL, 0);
|
||||||
#else
|
#else
|
||||||
ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
|
ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
|
||||||
fileno(fwfile), genfile, progress, NULL);
|
fileno(fwfile), genfile, progress, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,179 +1,231 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* __________ __ ___.
|
* __________ __ ___.
|
||||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009, Dave Chapman
|
* Copyright (c) 2009, Dave Chapman
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
* met:
|
* met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above
|
* * Redistributions in binary form must reproduce the above
|
||||||
* copyright notice, this list of conditions and the following
|
* copyright notice, this list of conditions and the following
|
||||||
* disclaimer in the documentation and/or other materials provided
|
* disclaimer in the documentation and/or other materials provided
|
||||||
* with the distribution.
|
* with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <tchar.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "mtp_common.h"
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "../MTP_DLL/MTP_DLL.h"
|
#include "mtp_common.h"
|
||||||
|
|
||||||
int mtp_init(struct mtp_info_t* mtp_info)
|
#include "../MTP_DLL/MTP_DLL.h"
|
||||||
{
|
|
||||||
/* Fill the info struct with zeros - mainly for the strings */
|
|
||||||
memset(mtp_info, 0, sizeof(struct mtp_info_t));
|
static int filesize(const char* filename);
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
int mtp_init(struct mtp_info_t* mtp_info)
|
||||||
}
|
{
|
||||||
|
/* Fill the info struct with zeros - mainly for the strings */
|
||||||
int mtp_finished(struct mtp_info_t* mtp_info)
|
memset(mtp_info, 0, sizeof(struct mtp_info_t));
|
||||||
{
|
|
||||||
(void)mtp_info;
|
return 0;
|
||||||
|
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
int mtp_finished(struct mtp_info_t* mtp_info)
|
||||||
int mtp_scan(struct mtp_info_t* mtp_info)
|
{
|
||||||
{
|
(void)mtp_info;
|
||||||
wchar_t name[256];
|
|
||||||
wchar_t manufacturer[256];
|
return 0;
|
||||||
DWORD version;
|
}
|
||||||
int num = 0;
|
|
||||||
|
int mtp_scan(struct mtp_info_t* mtp_info)
|
||||||
num = mtp_description(name, manufacturer, &version);
|
{
|
||||||
|
wchar_t name[256];
|
||||||
wcstombs(mtp_info->manufacturer, manufacturer, 200);
|
wchar_t manufacturer[256];
|
||||||
wcstombs(mtp_info->modelname, name, 200);
|
DWORD version;
|
||||||
|
int num = 0;
|
||||||
sprintf(mtp_info->version, "%x", (unsigned int)version);
|
|
||||||
return (num > 0) ? num : -1;
|
num = mtp_description(name, manufacturer, &version);
|
||||||
|
|
||||||
}
|
wcstombs(mtp_info->manufacturer, manufacturer, 200);
|
||||||
|
wcstombs(mtp_info->modelname, name, 200);
|
||||||
static void callback(unsigned int progress, unsigned int max)
|
|
||||||
{
|
sprintf(mtp_info->version, "%x", (unsigned int)version);
|
||||||
int percent = (progress * 100) / max;
|
return (num > 0) ? num : -1;
|
||||||
|
|
||||||
printf("Progress: %u of %u (%d%%)\r", progress, max, percent);
|
}
|
||||||
fflush(stdout);
|
|
||||||
}
|
static void callback(unsigned int progress, unsigned int max)
|
||||||
|
{
|
||||||
|
int percent = (progress * 100) / max;
|
||||||
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
|
||||||
int fwsize)
|
printf("[INFO] Progress: %u of %u (%d%%)\r", progress, max, percent);
|
||||||
{
|
fflush(stdout);
|
||||||
HANDLE hTempFile;
|
}
|
||||||
DWORD dwRetVal;
|
|
||||||
DWORD dwBytesWritten;
|
|
||||||
UINT uRetVal;
|
int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
|
||||||
TCHAR szTempName[1024];
|
int fwsize)
|
||||||
TCHAR lpPathBuffer[1024];
|
{
|
||||||
BOOL fSuccess;
|
HANDLE hTempFile;
|
||||||
wchar_t *tmp;
|
DWORD dwRetVal;
|
||||||
int ret;
|
DWORD dwBytesWritten;
|
||||||
|
UINT uRetVal;
|
||||||
(void)mtp_info;
|
TCHAR szTempName[1024];
|
||||||
|
TCHAR lpPathBuffer[1024];
|
||||||
/* Get the path for temporary files */
|
BOOL fSuccess;
|
||||||
dwRetVal = GetTempPath(sizeof(lpPathBuffer), lpPathBuffer);
|
wchar_t *tmp;
|
||||||
if (dwRetVal > sizeof(lpPathBuffer) || (dwRetVal == 0))
|
int ret;
|
||||||
{
|
|
||||||
fprintf(stderr, "[ERR] GetTempPath failed (%d)\n", (int)GetLastError());
|
(void)mtp_info;
|
||||||
return -1;
|
|
||||||
}
|
/* Get the path for temporary files */
|
||||||
|
dwRetVal = GetTempPath(sizeof(lpPathBuffer), lpPathBuffer);
|
||||||
/* Create the temporary file */
|
if (dwRetVal > sizeof(lpPathBuffer) || (dwRetVal == 0))
|
||||||
uRetVal = GetTempFileName(lpPathBuffer, TEXT("NKBIN"), 0, szTempName);
|
{
|
||||||
if (uRetVal == 0)
|
fprintf(stderr, "[ERR] GetTempPath failed (%d)\n", (int)GetLastError());
|
||||||
{
|
return -1;
|
||||||
fprintf(stderr, "[ERR] GetTempFileName failed (%d)\n", (int)GetLastError());
|
}
|
||||||
return -1;
|
|
||||||
}
|
/* Create the temporary file */
|
||||||
|
uRetVal = GetTempFileName(lpPathBuffer, TEXT("NKBIN"), 0, szTempName);
|
||||||
/* Now create the file */
|
if (uRetVal == 0)
|
||||||
hTempFile = CreateFile((LPTSTR) szTempName, // file name
|
{
|
||||||
GENERIC_READ | GENERIC_WRITE, // open r-w
|
fprintf(stderr, "[ERR] GetTempFileName failed (%d)\n", (int)GetLastError());
|
||||||
0, // do not share
|
return -1;
|
||||||
NULL, // default security
|
}
|
||||||
CREATE_ALWAYS, // overwrite existing
|
|
||||||
FILE_ATTRIBUTE_NORMAL,// normal file
|
/* Now create the file */
|
||||||
NULL); // no template
|
hTempFile = CreateFile((LPTSTR) szTempName, // file name
|
||||||
if (hTempFile == INVALID_HANDLE_VALUE)
|
GENERIC_READ | GENERIC_WRITE, // open r-w
|
||||||
{
|
0, // do not share
|
||||||
fprintf(stderr, "[ERR] Could not create %s\n", szTempName);
|
NULL, // default security
|
||||||
return -1;
|
CREATE_ALWAYS, // overwrite existing
|
||||||
}
|
FILE_ATTRIBUTE_NORMAL,// normal file
|
||||||
|
NULL); // no template
|
||||||
fSuccess = WriteFile(hTempFile, fwbuf, fwsize, &dwBytesWritten, NULL);
|
if (hTempFile == INVALID_HANDLE_VALUE)
|
||||||
if (!fSuccess)
|
{
|
||||||
{
|
fprintf(stderr, "[ERR] Could not create %s\n", szTempName);
|
||||||
fprintf(stderr, "[ERR] WriteFile failed (%d)\n", (int)GetLastError());
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
fSuccess = WriteFile(hTempFile, fwbuf, fwsize, &dwBytesWritten, NULL);
|
||||||
fSuccess = CloseHandle (hTempFile);
|
if (!fSuccess)
|
||||||
if (!fSuccess)
|
{
|
||||||
{
|
fprintf(stderr, "[ERR] WriteFile failed (%d)\n", (int)GetLastError());
|
||||||
fprintf(stderr, "[ERR] CloseHandle failed (%d)\n", (int)GetLastError());
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
fSuccess = CloseHandle (hTempFile);
|
||||||
tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1);
|
if (!fSuccess)
|
||||||
mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1);
|
{
|
||||||
|
fprintf(stderr, "[ERR] CloseHandle failed (%d)\n", (int)GetLastError());
|
||||||
fprintf(stderr, "[INFO] Sending firmware...\n");
|
return -1;
|
||||||
if (mtp_sendnk(tmp, fwsize, &callback))
|
}
|
||||||
{
|
|
||||||
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1);
|
||||||
ret = 0;
|
mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1);
|
||||||
}
|
|
||||||
else
|
fprintf(stderr, "[INFO] Sending firmware...\n");
|
||||||
{
|
if (mtp_sendnk(tmp, fwsize, &callback))
|
||||||
fprintf(stderr, "[ERR] Error occured during sending.\n");
|
{
|
||||||
ret = -1;
|
fprintf(stderr, "\n");
|
||||||
}
|
fprintf(stderr, "[INFO] Firmware sent successfully\n");
|
||||||
|
ret = 0;
|
||||||
/* Keep the progress line onscreen */
|
}
|
||||||
printf("\n");
|
else
|
||||||
|
{
|
||||||
free(tmp);
|
fprintf(stderr, "\n");
|
||||||
|
fprintf(stderr, "[ERR] Error occured during sending.\n");
|
||||||
if (!DeleteFile(szTempName))
|
ret = -1;
|
||||||
fprintf(stderr,"[WARN] Could not remove temporary file %s\n",szTempName);
|
}
|
||||||
|
free(tmp);
|
||||||
return ret;
|
|
||||||
}
|
if (!DeleteFile(szTempName))
|
||||||
|
fprintf(stderr,"[WARN] Could not remove temporary file %s\n",szTempName);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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