Commit 7b054153 authored by NiteHawk's avatar NiteHawk
Browse files

Merge pull request #40 from n1tehawk/travis-ci

Add continuous integration support (Travis CI), fix Mac OS X build
parents b59f4584 ed94fc2f
# use container-based infrastructure
sudo: false
language: c
os:
- linux
- osx
# take care of the libusb dependency for Linux
addons:
apt:
packages:
- libusb-1.0-0-dev
# take care of the libusb dependency for Mac OS X
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update;
brew install libusb;
fi
# build by simply using the Makefile
script:
- make
- make misc
......@@ -18,9 +18,16 @@
CC = gcc
CFLAGS = -g -O0 -Wall -Wextra
CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200112L
CFLAGS += -std=c99 $(DEFINES)
CFLAGS += -Iinclude/
DEFINES = -D_POSIX_C_SOURCE=200112L
# Define _BSD_SOURCE, necessary to expose all endian conversions properly.
# See http://linux.die.net/man/3/endian
DEFINES += -D_BSD_SOURCE
# glibc 2.20+ also requires _DEFAULT_SOURCE
DEFINES += -D_DEFAULT_SOURCE
# Tools useful on host and target
TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part
......
......@@ -15,12 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Needs _BSD_SOURCE for htole and letoh */
/* glibc 2.20+ also requires _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#define _NETBSD_SOURCE
#include <libusb.h>
#include <stdint.h>
#include <stdbool.h>
......@@ -34,12 +28,29 @@
#include <unistd.h>
#include <sys/stat.h>
#include "endian_compat.h"
#include "portable_endian.h"
#include "progress.h"
static const uint16_t AW_USB_VENDOR_ID = 0x1F3A;
static const uint16_t AW_USB_PRODUCT_ID = 0xEFE8;
/* a helper function to report libusb errors */
void usb_error(int rc, const char *caption, int exitcode)
{
if (caption)
fprintf(stderr, "%s ", caption);
#if defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01000102)
fprintf(stderr, "ERROR %d: %s\n", rc, libusb_strerror(rc));
#else
/* assume that libusb_strerror() is missing in the libusb API */
fprintf(stderr, "ERROR %d\n", rc);
#endif
if (exitcode != 0)
exit(exitcode);
}
struct aw_usb_request {
char signature[8];
uint32_t length;
......@@ -97,10 +108,8 @@ void usb_bulk_send(libusb_device_handle *usb, int ep, const void *data,
while (length > 0) {
chunk = length < max_chunk ? length : max_chunk;
rc = libusb_bulk_transfer(usb, ep, (void *)data, chunk, &sent, timeout);
if (rc != 0) {
fprintf(stderr, "libusb usb_bulk_send error %d\n", rc);
exit(2);
}
if (rc != 0)
usb_error(rc, "usb_bulk_send()", 2);
length -= sent;
data += sent;
......@@ -114,10 +123,8 @@ void usb_bulk_recv(libusb_device_handle *usb, int ep, void *data, int length)
int rc, recv;
while (length > 0) {
rc = libusb_bulk_transfer(usb, ep, data, length, &recv, timeout);
if (rc != 0) {
fprintf(stderr, "usb_bulk_recv error %d\n", rc);
exit(2);
}
if (rc != 0)
usb_error(rc, "usb_bulk_recv()", 2);
length -= recv;
data += recv;
}
......@@ -1321,11 +1328,8 @@ static libusb_device_handle *open_fel_device(int busnum, int devnum,
libusb_device **list;
rc = libusb_get_device_list(NULL, &list);
if (rc < 0) {
fprintf(stderr, "libusb_get_device_list() ERROR: %s\n",
libusb_strerror(rc));
exit(1);
}
if (rc < 0)
usb_error(rc, "libusb_get_device_list()", 1);
for (i = 0; i < rc; i++) {
if (libusb_get_bus_number(list[i]) == busnum
&& libusb_get_device_address(list[i]) == devnum) {
......@@ -1341,11 +1345,8 @@ static libusb_device_handle *open_fel_device(int busnum, int devnum,
}
/* open handle to this specific device (incrementing its refcount) */
rc = libusb_open(list[i], &result);
if (rc != 0) {
fprintf(stderr, "libusb_open() ERROR: %s\n",
libusb_strerror(rc));
exit(1);
}
if (rc != 0)
usb_error(rc, "libusb_open()", 1);
break;
}
}
......
/*
* Copyright (C) 2012 Eric Molitor <eric@molitor.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef SUNXI_ENDIAN_COMPAT_H_
#define SUNXI_ENDIAN_COMPAT_H_
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#define htole32(x) CFSwapInt32HostToLittle(x)
#define le32toh(x) CFSwapInt32LittleToHost(x)
#define htole16(x) CFSwapInt16HostToLittle(x)
#define le16toh(x) CFSwapInt16LittleToHost(x)
#else
#include <endian.h>
#endif
#endif
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
#endif
#if defined(__linux__) || defined(__CYGWIN__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#elif defined(__OpenBSD__)
# include <sys/endian.h>
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)
# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)
# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)
#elif defined(__WINDOWS__)
# include <winsock2.h>
# include <sys/param.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# define htobe16(x) htons(x)
# define htole16(x) (x)
# define be16toh(x) ntohs(x)
# define le16toh(x) (x)
# define htobe32(x) htonl(x)
# define htole32(x) (x)
# define be32toh(x) ntohl(x)
# define le32toh(x) (x)
# define htobe64(x) htonll(x)
# define htole64(x) (x)
# define be64toh(x) ntohll(x)
# define le64toh(x) (x)
# elif BYTE_ORDER == BIG_ENDIAN
/* that would be xbox 360 */
# define htobe16(x) (x)
# define htole16(x) __builtin_bswap16(x)
# define be16toh(x) (x)
# define le16toh(x) __builtin_bswap16(x)
# define htobe32(x) (x)
# define htole32(x) __builtin_bswap32(x)
# define be32toh(x) (x)
# define le32toh(x) __builtin_bswap32(x)
# define htobe64(x) (x)
# define htole64(x) __builtin_bswap64(x)
# define be64toh(x) (x)
# define le64toh(x) __builtin_bswap64(x)
# else
# error byte order not supported
# endif
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#else
# error platform not supported
#endif
#endif
......@@ -50,8 +50,10 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h> /* BLKRRPART */
#ifdef __linux__
# include <sys/ioctl.h>
# include <sys/mount.h> /* BLKRRPART */
#endif
#include "nand-common.h"
// so far, only known formats are for A10 and A20
......@@ -249,8 +251,10 @@ static int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, u
write(fd,mbr,MBR_SIZE);
}
#ifdef __linux__
if (ioctl(fd, BLKRRPART, NULL))
perror("Failed rereading partition table");
#endif
return 1;
}
......@@ -312,7 +316,9 @@ int nand_part (int argc, char **argv, const char *cmd, int fd, int force)
if (writembrs(fd, names, start, lens, user_types, argc, partoffset, force)) {
printf("\nverifying new partition tables:\n");
checkmbrs(fd);
#ifdef __linux__
printf("rereading partition table... returned %d\n", ioctl(fd, BLKRRPART, 0));
#endif
}
}
close(fd);
......
......@@ -15,17 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Needs _BSD_SOURCE for htole and letoh */
/* glibc 2.20+ also requires _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "endian_compat.h"
#include "portable_endian.h"
struct phoenix_ptable {
char signature[16]; /* "PHOENIX_CARD_IMG" */
......
......@@ -17,11 +17,6 @@
* MA 02111-1307 USA
*/
/* needs _BSD_SOURCE for htole and letoh */
/* glibc 2.20+ also requires _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
......@@ -34,7 +29,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "endian_compat.h"
#include "portable_endian.h"
#define PIO_REG_SIZE 0x228 /*0x300*/
#define PIO_PORT_SIZE 0x24
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment