9
0
Fork 0

Merge branch 'for-next/misc'

This commit is contained in:
Sascha Hauer 2014-05-05 13:32:37 +02:00
commit bf1d71d5e1
19 changed files with 432 additions and 61 deletions

View File

@ -79,7 +79,6 @@ config ARCH_HIGHBANK
config ARCH_IMX config ARCH_IMX
bool "Freescale iMX-based" bool "Freescale iMX-based"
select GENERIC_GPIO
select GPIOLIB select GPIOLIB
select COMMON_CLK select COMMON_CLK
select CLKDEV_LOOKUP select CLKDEV_LOOKUP
@ -132,7 +131,6 @@ config ARCH_SOCFPGA
select CPU_V7 select CPU_V7
select COMMON_CLK select COMMON_CLK
select CLKDEV_LOOKUP select CLKDEV_LOOKUP
select GENERIC_GPIO
select GPIOLIB select GPIOLIB
select HAVE_PBL_MULTI_IMAGES select HAVE_PBL_MULTI_IMAGES

389
commands/2048.c Normal file
View File

@ -0,0 +1,389 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Maurits van der Schee
*
* 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
*
* ============================================================================
* Name : 2048.c
* Author : Maurits van der Schee
* Description : Console version of the game "2048" for GNU/Linux
* ============================================================================
*/
#include <common.h>
#include <readkey.h>
#include <command.h>
#include <stdlib.h>
#define SIZE 4
static uint32_t score;
static void getColor(uint16_t value, char *color, size_t length)
{
uint8_t original[] = {8,255,1,255,2,255,3,255,4,255,5,255,6,255,7,255,9,0,10,0,11,0,12,0,13,0,14,0,255,0,255,0};
uint8_t *scheme = original;
uint8_t *background = scheme+0;
uint8_t *foreground = scheme+1;
if (value > 0) while (value >>= 1) {
if (background+2<scheme+sizeof(original)) {
background+=2;
foreground+=2;
}
}
snprintf(color,length,"\033[38;5;%d;48;5;%dm",*foreground,*background);
}
static void drawBoard(uint16_t board[SIZE][SIZE])
{
int8_t x,y;
char color[40], reset[] = "\033[m";
printf("\033[H");
printf("2048.c %17d pts\n\n",score);
for (y=0;y<SIZE;y++) {
for (x=0;x<SIZE;x++) {
getColor(board[x][y],color,40);
printf("%s",color);
printf(" ");
printf("%s",reset);
}
printf("\n");
for (x=0;x<SIZE;x++) {
getColor(board[x][y],color,40);
printf("%s",color);
if (board[x][y]!=0) {
char s[8];
int8_t t;
snprintf(s,8,"%u",board[x][y]);
t = 7-strlen(s);
printf("%*s%s%*s",t-t/2,"",s,t/2,"");
} else {
printf(" · ");
}
printf("%s",reset);
}
printf("\n");
for (x=0;x<SIZE;x++) {
getColor(board[x][y],color,40);
printf("%s",color);
printf(" ");
printf("%s",reset);
}
printf("\n");
}
printf("\n");
printf(" ←,↑,→,↓ or q \n");
printf("\033[A");
}
static int8_t findTarget(uint16_t array[SIZE],int8_t x,int8_t stop)
{
int8_t t;
/* if the position is already on the first, don't evaluate */
if (x==0) {
return x;
}
for(t=x-1;t>=0;t--) {
if (array[t]!=0) {
if (array[t]!=array[x]) {
/* merge is not possible, take next position */
return t+1;
}
return t;
} else {
/* we should not slide further, return this one */
if (t==stop) {
return t;
}
}
}
/* we did not find a */
return x;
}
static bool slideArray(uint16_t array[SIZE])
{
bool success = false;
int8_t x,t,stop=0;
for (x=0;x<SIZE;x++) {
if (array[x]!=0) {
t = findTarget(array,x,stop);
/* if target is not original position, then move or merge */
if (t!=x) {
/* if target is not zero, set stop to avoid double merge */
if (array[t]!=0) {
score+=array[t]+array[x];
stop = t+1;
}
array[t]+=array[x];
array[x]=0;
success = true;
}
}
}
return success;
}
static void rotateBoard(uint16_t board[SIZE][SIZE])
{
int8_t i,j,n=SIZE;
uint16_t tmp;
for (i=0; i<n/2; i++){
for (j=i; j<n-i-1; j++){
tmp = board[i][j];
board[i][j] = board[j][n-i-1];
board[j][n-i-1] = board[n-i-1][n-j-1];
board[n-i-1][n-j-1] = board[n-j-1][i];
board[n-j-1][i] = tmp;
}
}
}
static bool moveUp(uint16_t board[SIZE][SIZE])
{
bool success = false;
int8_t x;
for (x=0;x<SIZE;x++) {
success |= slideArray(board[x]);
}
return success;
}
static bool moveLeft(uint16_t board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
return success;
}
static bool moveDown(uint16_t board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
rotateBoard(board);
return success;
}
static bool moveRight(uint16_t board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
return success;
}
static bool findPairDown(uint16_t board[SIZE][SIZE])
{
bool success = false;
int8_t x,y;
for (x=0;x<SIZE;x++) {
for (y=0;y<SIZE-1;y++) {
if (board[x][y]==board[x][y+1]) return true;
}
}
return success;
}
static int16_t countEmpty(uint16_t board[SIZE][SIZE])
{
int8_t x,y;
int16_t count=0;
for (x=0;x<SIZE;x++) {
for (y=0;y<SIZE;y++) {
if (board[x][y]==0) {
count++;
}
}
}
return count;
}
static bool gameEnded(uint16_t board[SIZE][SIZE])
{
bool ended = true;
if (countEmpty(board)>0) return false;
if (findPairDown(board)) return false;
rotateBoard(board);
if (findPairDown(board)) ended = false;
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
return ended;
}
static void addRandom(uint16_t board[SIZE][SIZE])
{
int8_t x,y;
int16_t r,len=0;
uint16_t n,list[SIZE*SIZE][2];
for (x=0;x<SIZE;x++) {
for (y=0;y<SIZE;y++) {
if (board[x][y]==0) {
list[len][0]=x;
list[len][1]=y;
len++;
}
}
}
if (len>0) {
r = rand()%len;
x = list[r][0];
y = list[r][1];
n = ((rand()%10)/9+1)*2;
board[x][y]=n;
}
}
static int test(void)
{
uint16_t array[SIZE];
uint16_t data[] = {
0,0,0,2, 2,0,0,0,
0,0,2,2, 4,0,0,0,
0,2,0,2, 4,0,0,0,
2,0,0,2, 4,0,0,0,
2,0,2,0, 4,0,0,0,
2,2,2,0, 4,2,0,0,
2,0,2,2, 4,2,0,0,
2,2,0,2, 4,2,0,0,
2,2,2,2, 4,4,0,0,
4,4,2,2, 8,4,0,0,
2,2,4,4, 4,8,0,0,
8,0,2,2, 8,4,0,0,
4,0,2,2, 4,4,0,0
};
uint16_t *in,*out;
uint16_t t,tests;
uint8_t i;
bool success = true;
tests = (sizeof(data)/sizeof(data[0]))/(2*SIZE);
for (t=0;t<tests;t++) {
in = data+t*2*SIZE;
out = in + SIZE;
for (i=0;i<SIZE;i++) {
array[i] = in[i];
}
slideArray(array);
for (i=0;i<SIZE;i++) {
if (array[i] != out[i]) {
success = false;
}
}
if (success==false) {
for (i=0;i<SIZE;i++) {
printf("%d ",in[i]);
}
printf("=> ");
for (i=0;i<SIZE;i++) {
printf("%d ",array[i]);
}
printf("expected ");
for (i=0;i<SIZE;i++) {
printf("%d ",in[i]);
}
printf("=> ");
for (i=0;i<SIZE;i++) {
printf("%d ",out[i]);
}
printf("\n");
break;
}
}
if (success) {
printf("All %u tests executed successfully\n",tests);
}
return !success;
}
static int do_2048(int argc, char *argv[])
{
uint16_t board[SIZE][SIZE];
char c;
bool success;
if (argc == 2 && strcmp(argv[1],"test")==0) {
return test();
}
printf("\033[?25l\033[2J\033[H");
memset(board,0,sizeof(board));
addRandom(board);
addRandom(board);
drawBoard(board);
while (true) {
c=read_key();
switch(c) {
case BB_KEY_LEFT: /* left arrow */
success = moveLeft(board); break;
case BB_KEY_RIGHT: /* right arrow */
success = moveRight(board); break;
case BB_KEY_UP: /* up arrow */
success = moveUp(board); break;
case BB_KEY_DOWN: /* down arrow */
success = moveDown(board); break;
default: success = false;
}
if (success) {
drawBoard(board);
udelay(150000);
addRandom(board);
drawBoard(board);
if (gameEnded(board)) {
printf(" GAME OVER \n");
break;
}
}
if (c=='q') {
printf(" QUIT \n");
break;
}
}
printf("\033[?25h");
return 0;
}
BAREBOX_CMD_HELP_START(2048)
BAREBOX_CMD_HELP_USAGE("2048\n")
BAREBOX_CMD_HELP_SHORT("The 2048 game\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(2048)
.cmd = do_2048,
.usage = "Usage: 2048",
BAREBOX_CMD_HELP(cmd_2048_help)
BAREBOX_CMD_END

View File

@ -597,6 +597,12 @@ config CMD_MEMTEST
flags support, the memtest is running twice with cache enabled flags support, the memtest is running twice with cache enabled
and with cache disabled and with cache disabled
config CMD_2048
tristate
prompt "2048"
help
Console version of the game "2048" for GNU/Linux
endmenu endmenu
menu "video command" menu "video command"

View File

@ -95,3 +95,4 @@ obj-$(CONFIG_CMD_BOOT) += boot.o
obj-$(CONFIG_CMD_DEVINFO) += devinfo.o obj-$(CONFIG_CMD_DEVINFO) += devinfo.o
obj-$(CONFIG_CMD_READF) += readf.o obj-$(CONFIG_CMD_READF) += readf.o
obj-$(CONFIG_CMD_MENUTREE) += menutree.o obj-$(CONFIG_CMD_MENUTREE) += menutree.o
obj-$(CONFIG_CMD_2048) += 2048.o

View File

@ -31,8 +31,7 @@
static int do_mount(int argc, char *argv[]) static int do_mount(int argc, char *argv[])
{ {
int opt; int opt, verbose = 0;
int ret = 0, verbose = 0;
struct driver_d *drv; struct driver_d *drv;
const char *type = NULL; const char *type = NULL;
const char *mountpoint, *dev; const char *mountpoint, *dev;
@ -113,11 +112,7 @@ static int do_mount(int argc, char *argv[])
mountpoint = argv[optind + 1]; mountpoint = argv[optind + 1];
} }
if ((ret = mount(dev, type, mountpoint, fsoptions))) { return mount(dev, type, mountpoint, fsoptions);
perror("mount");
return 1;
}
return 0;
} }
BAREBOX_CMD_HELP_START(mount) BAREBOX_CMD_HELP_START(mount)

View File

@ -23,16 +23,10 @@
static int do_umount(int argc, char *argv[]) static int do_umount(int argc, char *argv[])
{ {
int ret = 0;
if (argc != 2) if (argc != 2)
return COMMAND_ERROR_USAGE; return COMMAND_ERROR_USAGE;
if ((ret = umount(argv[1]))) { return umount(argv[1]);
perror("umount");
return 1;
}
return 0;
} }
static const __maybe_unused char cmd_umount_help[] = static const __maybe_unused char cmd_umount_help[] =

View File

@ -31,7 +31,6 @@ static int do_usbserial(int argc, char *argv[])
{ {
int opt; int opt;
struct usb_serial_pdata pdata; struct usb_serial_pdata pdata;
char *argstr;
char *manufacturer = "barebox"; char *manufacturer = "barebox";
const char *productname = barebox_get_model(); const char *productname = barebox_get_model();
u16 idVendor = 0, idProduct = 0; u16 idVendor = 0, idProduct = 0;
@ -68,8 +67,6 @@ static int do_usbserial(int argc, char *argv[])
} }
} }
argstr = argv[optind];
pdata.manufacturer = manufacturer; pdata.manufacturer = manufacturer;
pdata.productname = productname; pdata.productname = productname;
pdata.idVendor = idVendor; pdata.idVendor = idVendor;

View File

@ -78,9 +78,6 @@ static void pata_imx_set_bus_timing(void __iomem *base, unsigned long clkrate,
{ {
uint32_t T = 1000000000 / clkrate; uint32_t T = 1000000000 / clkrate;
struct mxc_ata_config_regs *ata_regs;
ata_regs = (struct mxc_ata_config_regs *)base;
if (mode >= ARRAY_SIZE(pio_t1)) if (mode >= ARRAY_SIZE(pio_t1))
return; return;

View File

@ -392,17 +392,13 @@ static int __init imx_keypad_probe(struct device_d *dev)
struct console_device *cdev; struct console_device *cdev;
int error, i; int error, i;
keypad = xzalloc(sizeof(struct imx_keypad));
if (!keypad) {
pr_err("not enough memory for driver data\n");
error = -ENOMEM;
}
if (!keymap_data) { if (!keymap_data) {
pr_err("no keymap defined\n"); pr_err("no keymap defined\n");
return -ENODEV; return -ENODEV;
} }
keypad = xzalloc(sizeof(struct imx_keypad));
keypad->dev = dev; keypad->dev = dev;
keypad->mmio_base = dev_request_mem_region(dev, 0); keypad->mmio_base = dev_request_mem_region(dev, 0);
@ -420,8 +416,8 @@ static int __init imx_keypad_probe(struct device_d *dev)
if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) || if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) ||
keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) { keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
pr_err("invalid key data (too many rows or colums)\n"); pr_err("invalid key data (too many rows or colums)\n");
error = -EINVAL; free(keypad);
//goto failed_clock_put; return -EINVAL;
} }
pr_debug("enabled rows mask: %x\n", keypad->rows_en_mask); pr_debug("enabled rows mask: %x\n", keypad->rows_en_mask);
pr_debug("enabled cols mask: %x\n", keypad->cols_en_mask); pr_debug("enabled cols mask: %x\n", keypad->cols_en_mask);
@ -446,7 +442,6 @@ static int __init imx_keypad_probe(struct device_d *dev)
console_register(&keypad->cdev); console_register(&keypad->cdev);
return poller_register(&keypad->poller); return poller_register(&keypad->poller);
} }
static struct driver_d imx_keypad_driver = { static struct driver_d imx_keypad_driver = {

View File

@ -551,7 +551,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
{ {
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
int i, chips; int i, chips;
int bits, startblock, block, dir; int startblock, block, dir;
int scanlen = mtd->writesize + mtd->oobsize; int scanlen = mtd->writesize + mtd->oobsize;
int bbtblocks; int bbtblocks;
int blocktopage = this->bbt_erase_shift - this->page_shift; int blocktopage = this->bbt_erase_shift - this->page_shift;
@ -575,9 +575,6 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
bbtblocks = mtd->size >> this->bbt_erase_shift; bbtblocks = mtd->size >> this->bbt_erase_shift;
} }
/* Number of bits for each erase block in the bbt */
bits = td->options & NAND_BBT_NRBITS_MSK;
for (i = 0; i < chips; i++) { for (i = 0; i < chips; i++) {
/* Reset version information */ /* Reset version information */
td->version[i] = 0; td->version[i] = 0;

View File

@ -7,11 +7,8 @@
static int mtd_part_read(struct mtd_info *mtd, loff_t from, size_t len, static int mtd_part_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf) size_t *retlen, u_char *buf)
{ {
struct mtd_ecc_stats stats;
int res; int res;
stats = mtd->master->ecc_stats;
if (from >= mtd->size) if (from >= mtd->size)
len = 0; len = 0;
else if (from + len > mtd->size) else if (from + len > mtd->size)

View File

@ -741,8 +741,13 @@ static int cpdma_process(struct cpsw_priv *priv, struct cpdma_chan *chan,
if (buffer) if (buffer)
*buffer = (void *)readl(&desc->sw_buffer); *buffer = (void *)readl(&desc->sw_buffer);
if (status & CPDMA_DESC_OWNER) if (status & CPDMA_DESC_OWNER) {
if (readl(chan->hdp) == 0) {
if (readl(&desc->hw_mode) & CPDMA_DESC_OWNER)
writel((u32)desc, chan->hdp);
}
return -EBUSY; return -EBUSY;
}
chan->head = (void *)readl(&desc->hw_next); chan->head = (void *)readl(&desc->hw_next);

View File

@ -803,4 +803,3 @@ static int __init asix_init(void)
return usb_driver_register(&asix_driver); return usb_driver_register(&asix_driver);
} }
device_initcall(asix_init); device_initcall(asix_init);

View File

@ -34,18 +34,18 @@ static int altera_spi_setup(struct spi_device *spi)
if (spi->bits_per_word != altera_spi->databits) { if (spi->bits_per_word != altera_spi->databits) {
dev_err(master->dev, " master doesn't support %d bits per word requested by %s\n", dev_err(master->dev, " master doesn't support %d bits per word requested by %s\n",
spi->bits_per_word, spi_dev.name); spi->bits_per_word, spi_dev.name);
return -1; return -EINVAL;
} }
if ((spi->mode & (SPI_CPHA | SPI_CPOL)) != altera_spi->mode) { if ((spi->mode & (SPI_CPHA | SPI_CPOL)) != altera_spi->mode) {
dev_err(master->dev, " master doesn't support SPI_MODE%d requested by %s\n", dev_err(master->dev, " master doesn't support SPI_MODE%d requested by %s\n",
spi->mode & (SPI_CPHA | SPI_CPOL), spi_dev.name); spi->mode & (SPI_CPHA | SPI_CPOL), spi_dev.name);
return -1; return -EINVAL;
} }
if (spi->max_speed_hz < altera_spi->speed) { if (spi->max_speed_hz < altera_spi->speed) {
dev_err(master->dev, " frequency is too high for %s\n", spi_dev.name); dev_err(master->dev, " frequency is too high for %s\n", spi_dev.name);
return -1; return -EINVAL;
} }
altera_spi_cs_inactive(spi); altera_spi_cs_inactive(spi);

View File

@ -423,7 +423,7 @@ static void imx_spi_do_transfer(struct spi_device *spi, struct spi_transfer *t)
static int imx_spi_transfer(struct spi_device *spi, struct spi_message *mesg) static int imx_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
{ {
struct imx_spi *imx = container_of(spi->master, struct imx_spi, master); struct imx_spi *imx = container_of(spi->master, struct imx_spi, master);
struct spi_transfer *t = NULL; struct spi_transfer *t;
imx->chipselect(spi, 1); imx->chipselect(spi, 1);

View File

@ -33,14 +33,16 @@
#include <kfifo.h> #include <kfifo.h>
#include <sizes.h> #include <sizes.h>
#define TFTP_PORT 69 /* Well known TFTP port # */ #define TFTP_PORT 69 /* Well known TFTP port number */
#define TIMEOUT 5 /* Seconds to timeout for a lost pkt */
/* Seconds to wait before remote server is allowed to resend a lost packet */
#define TIMEOUT 5
/* After this time without a response from the server we will resend a packet */ /* After this time without a response from the server we will resend a packet */
#define TFTP_RESEND_TIMEOUT SECOND #define TFTP_RESEND_TIMEOUT SECOND
/* After this time without progress we will bail out */ /* After this time without progress we will bail out */
#define TFTP_TIMEOUT (TIMEOUT * SECOND) #define TFTP_TIMEOUT ((TIMEOUT * 3) * SECOND)
/* /*
* TFTP operations. * TFTP operations.

View File

@ -240,8 +240,6 @@ static struct inode *ubifs_findfile(struct super_block *sb, const char *filename
return ubifs_iget(sb, 1); return ubifs_iget(sb, 1);
for (;;) { for (;;) {
struct ubifs_inode *ui;
/* Extract the actual part from the pathname. */ /* Extract the actual part from the pathname. */
next = strchr(name, '/'); next = strchr(name, '/');
if (next) { if (next) {
@ -257,8 +255,6 @@ static struct inode *ubifs_findfile(struct super_block *sb, const char *filename
if (!inode) if (!inode)
break; break;
ui = ubifs_inode(inode);
/* /*
* Check if directory with this name exists * Check if directory with this name exists
*/ */

View File

@ -56,7 +56,6 @@ static inline int parse_header(u8 *input, int *skip, int in_len)
int l; int l;
u8 *parse = input; u8 *parse = input;
u8 *end = input + in_len; u8 *end = input + in_len;
u8 level = 0;
u16 version; u16 version;
/* /*
@ -78,7 +77,7 @@ static inline int parse_header(u8 *input, int *skip, int in_len)
version = get_unaligned_be16(parse); version = get_unaligned_be16(parse);
parse += 7; parse += 7;
if (version >= 0x0940) if (version >= 0x0940)
level = *parse++; parse++;
if (get_unaligned_be32(parse) & HEADER_HAS_FILTER) if (get_unaligned_be32(parse) & HEADER_HAS_FILTER)
parse += 8; /* flags + filter info */ parse += 8; /* flags + filter info */
else else

View File

@ -761,9 +761,12 @@ int main(int argc, char **argv)
infp = fopen(fname, "rb"); infp = fopen(fname, "rb");
if (!infp) { if (!infp) {
perror("fopen"); perror("fopen");
free(inbuf);
return 1; return 1;
} else if (fread(inbuf, 1, insize, infp) != insize) { } else if (fread(inbuf, 1, insize, infp) != insize) {
perror("fread"); perror("fread");
free(inbuf);
fclose(infp);
return 1; return 1;
} }
fclose(infp); fclose(infp);
@ -793,6 +796,7 @@ int main(int argc, char **argv)
return 1; return 1;
} else if (fwrite(info->image->data, 1, outsize, outfp) != outsize) { } else if (fwrite(info->image->data, 1, outsize, outfp) != outsize) {
perror("fwrite"); perror("fwrite");
fclose(outfp);
return 1; return 1;
} }
fclose(outfp); fclose(outfp);