LIBS += drivers/mtd/onenand/libonenand.a
LIBS += drivers/mtd/spi/libspi_flash.a
LIBS += drivers/net/libnet.a
+LIBS += drivers/net/phy/libphy.a
LIBS += drivers/net/sk98lin/libsk98lin.a
LIBS += drivers/pci/libpci.a
LIBS += drivers/pcmcia/libpcmcia.a
AOBJS =
+# core
COBJS-y += main.o
-COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o
COBJS-y += circbuf.o
+COBJS-y += console.o
+COBJS-y += command.o
+COBJS-y += devices.o
+COBJS-y += dlmalloc.o
+COBJS-y += exports.o
+COBJS-y += hush.o
+COBJS-y += image.o
+COBJS-y += memsize.o
+COBJS-y += s_record.o
+COBJS-y += serial.o
+COBJS-y += xyzModem.o
+
+# environment
+COBJS-y += environment.o
+COBJS-y += env_common.o
+COBJS-y += env_dataflash.o
+COBJS-y += env_eeprom.o
+COBJS-y += env_flash.o
+COBJS-y += env_nand.o
+COBJS-y += env_nvram.o
+COBJS-y += env_onenand.o
+COBJS-y += env_sf.o
+COBJS-y += env_nowhere.o
+
+# command
COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o
-COBJS-y += cmd_autoscript.o
+COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o
COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o
-COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o
+COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
-COBJS-y += image.o
-COBJS-y += gunzip.o
COBJS-y += cmd_boot.o
COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
COBJS-y += cmd_bootm.o
COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
COBJS-y += cmd_load.o
COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
+COBJS-y += cmd_mac.o
COBJS-y += cmd_mem.o
+COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o
+COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o
COBJS-$(CONFIG_CMD_MII) += cmd_mii.o
COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o
COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o
+COBJS-$(CONFIG_MP) += cmd_mp.o
COBJS-y += cmd_nand.o
COBJS-$(CONFIG_CMD_NET) += cmd_net.o
COBJS-y += cmd_nvedit.o
COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o
COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o
COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o
+COBJS-$(CONFIG_CMD_SF) += cmd_sf.o
COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o
COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o
COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o
COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o
-COBJS-$(CONFIG_CMD_USB) += cmd_usb.o
+ifdef CONFIG_CMD_USB
+COBJS-y += cmd_usb.o
+COBJS-y += usb.o
+COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o
+endif
COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
COBJS-y += cmd_vfd.o
-COBJS-y += command.o
-COBJS-y += console.o
-COBJS-y += devices.o
-COBJS-y += dlmalloc.o
COBJS-$(CONFIG_CMD_DOC) += docecc.o
-COBJS-y += environment.o
-COBJS-y += env_common.o
-COBJS-y += env_nand.o
-COBJS-y += env_dataflash.o
-COBJS-y += env_flash.o
-COBJS-y += env_eeprom.o
-COBJS-y += env_onenand.o
-COBJS-y += env_sf.o
-COBJS-y += env_nvram.o
-COBJS-y += env_nowhere.o
-COBJS-y += exports.o
COBJS-y += flash.o
-COBJS-y += hush.o
COBJS-y += kgdb.o
COBJS-$(CONFIG_LCD) += lcd.o
-COBJS-y += lists.o
COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
-COBJS-y += memsize.o
-COBJS-$(CONFIG_BITBANGMII) += miiphybb.o
-COBJS-y += miiphyutil.o
-COBJS-y += s_record.o
-COBJS-y += serial.o
-COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o
-COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
-ifdef CONFIG_CMD_USB
-COBJS-y += usb.o
-COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o
-endif
COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
-COBJS-y += crc16.o
-COBJS-y += xyzModem.o
-COBJS-y += cmd_mac.o
-COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o
-COBJS-$(CONFIG_MP) += cmd_mp.o
-COBJS-$(CONFIG_CMD_SF) += cmd_sf.o
COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
+COBJS-y += $(COBJS-yy)
COBJS := $(COBJS-y)
SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
#include <hush.h>
#endif
-#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)
-
int
autoscript (ulong addr, const char *fit_uname)
{
return rcode;
}
-#endif
-
/**************************************************/
#if defined(CONFIG_CMD_AUTOSCRIPT)
int
extern void _do_coninfo (void);
int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[])
{
- int i, l;
+ int l;
+ struct list_head *list = device_get_list();
+ struct list_head *pos;
+ device_t *dev;
/* Scan for valid output and input devices */
puts ("List of available devices:\n");
- for (i = 1; i <= ListNumItems (devlist); i++) {
- device_t *dev = ListGetPtrToItem (devlist, i);
+ list_for_each(pos, list) {
+ dev = list_entry(pos, device_t, list);
printf ("%-8s %08x %c%c%c ",
dev->name,
#include <common.h>
#include <command.h>
#include <devices.h>
-
-#if defined(CONFIG_CMD_TERMINAL)
+#include <serial.h>
int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
{
- int i, l;
int last_tilde = 0;
device_t *dev = NULL;
return -1;
/* Scan for selected output/input device */
- for (i = 1; i <= ListNumItems (devlist); i++) {
- device_t *tmp = ListGetPtrToItem (devlist, i);
- if (!strcmp(tmp->name, argv[1])) {
- dev = tmp;
- break;
- }
- }
+ dev = device_get_by_name(argv[1]);
if (!dev)
return -1;
"terminal - start terminal emulator\n",
""
);
-
-#endif /* CONFIG_CMD_TERMINAL */
/** U-Boot INIT FUNCTIONS *************************************************/
+device_t *search_device (int flags, char *name)
+{
+ device_t *dev;
+
+ dev = device_get_by_name(name);
+
+ if(dev && (dev->flags & flags))
+ return dev;
+
+ return NULL;
+}
+
int console_assign (int file, char *devname)
{
- int flag, i;
+ int flag;
+ device_t *dev;
/* Check for valid file */
switch (file) {
/* Check for valid device name */
- for (i = 1; i <= ListNumItems (devlist); i++) {
- device_t *dev = ListGetPtrToItem (devlist, i);
-
- if (strcmp (devname, dev->name) == 0) {
- if (dev->flags & flag)
- return console_setfile (file, dev);
+ dev = search_device(flag, devname);
- return -1;
- }
- }
+ if(dev)
+ return console_setfile (file, dev);
return -1;
}
return (0);
}
-#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE)
-/* search a device */
-device_t *search_device (int flags, char *name)
-{
- int i, items;
- device_t *dev = NULL;
-
- items = ListNumItems (devlist);
- if (name == NULL)
- return dev;
-
- for (i = 1; i <= items; i++) {
- dev = ListGetPtrToItem (devlist, i);
- if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
- break;
- }
- }
- return dev;
-}
-#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */
-
#ifdef CFG_CONSOLE_IS_IN_ENV
/* Called after the relocation - use desired console functions */
int console_init_r (void)
int console_init_r (void)
{
device_t *inputdev = NULL, *outputdev = NULL;
- int i, items = ListNumItems (devlist);
+ int i;
+ struct list_head *list = device_get_list();
+ struct list_head *pos;
+ device_t *dev;
#ifdef CONFIG_SPLASH_SCREEN
/* suppress all output if splash screen is enabled and we have
#endif
/* Scan devices looking for input and output devices */
- for (i = 1;
- (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
- i++
- ) {
- device_t *dev = ListGetPtrToItem (devlist, i);
+ list_for_each(pos, list) {
+ dev = list_entry(pos, device_t, list);
if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
inputdev = dev;
if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
outputdev = dev;
}
+ if(inputdev && outputdev)
+ break;
}
/* Initializes output console first */
+++ /dev/null
-/*
- *==========================================================================
- *
- * crc16.c
- *
- * 16 bit CRC with polynomial x^16+x^12+x^5+1
- *
- *==========================================================================
- *####ECOSGPLCOPYRIGHTBEGIN####
- * -------------------------------------------
- * This file is part of eCos, the Embedded Configurable Operating System.
- * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
- * Copyright (C) 2002 Gary Thomas
- *
- * eCos 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 2 or (at your option) any later version.
- *
- * eCos 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 eCos; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- *
- * As a special exception, if other files instantiate templates or use macros
- * or inline functions from this file, or you compile this file and link it
- * with other works to produce a work based on this file, this file does not
- * by itself cause the resulting work to be covered by the GNU General Public
- * License. However the source code for this file must still be made available
- * in accordance with section (3) of the GNU General Public License.
- *
- * This exception does not invalidate any other reasons why a work based on
- * this file might be covered by the GNU General Public License.
- *
- * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
- * at http: *sources.redhat.com/ecos/ecos-license/
- * -------------------------------------------
- *####ECOSGPLCOPYRIGHTEND####
- *==========================================================================
- *#####DESCRIPTIONBEGIN####
- *
- * Author(s): gthomas
- * Contributors: gthomas,asl
- * Date: 2001-01-31
- * Purpose:
- * Description:
- *
- * This code is part of eCos (tm).
- *
- *####DESCRIPTIONEND####
- *
- *==========================================================================
- */
-
-#include "crc.h"
-
-/* Table of CRC constants - implements x^16+x^12+x^5+1 */
-static const uint16_t crc16_tab[] = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
- 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
- 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
- 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
- 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
- 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
- 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
- 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
- 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
- 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
- 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
- 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
- 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
- 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
- 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
- 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
- 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
- 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
- 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
- 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
- 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
- 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
- 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
-};
-
-uint16_t
-cyg_crc16(unsigned char *buf, int len)
-{
- int i;
- uint16_t cksum;
-
- cksum = 0;
- for (i = 0; i < len; i++) {
- cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8);
- }
- return cksum;
-}
DECLARE_GLOBAL_DATA_PTR;
-list_t devlist = 0;
+static device_t devs;
device_t *stdio_devices[] = { NULL, NULL, NULL };
char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
#ifdef CFG_DEVICE_NULLDEV
void nulldev_putc(const char c)
{
- /* nulldev is empty! */
+ /* nulldev is empty! */
}
void nulldev_puts(const char *s)
{
- /* nulldev is empty! */
+ /* nulldev is empty! */
}
int nulldev_input(void)
{
- /* nulldev is empty! */
- return 0;
+ /* nulldev is empty! */
+ return 0;
}
#endif
* DEVICES
**************************************************************************
*/
+struct list_head* device_get_list(void)
+{
+ return &(devs.list);
+}
+
+device_t* device_get_by_name(char* name)
+{
+ struct list_head *pos;
+ device_t *dev;
+
+ if(!name)
+ return NULL;
+
+ list_for_each(pos, &(devs.list)) {
+ dev = list_entry(pos, device_t, list);
+ if(strcmp(dev->name, name) == 0)
+ return dev;
+ }
+
+ return NULL;
+}
+
int device_register (device_t * dev)
{
- ListInsertItem (devlist, dev, LIST_END);
+ list_add(&(dev->list), &(devs.list));
return 0;
}
#ifdef CFG_DEVICE_DEREGISTER
int device_deregister(char *devname)
{
- int i,l,dev_index;
- device_t *dev = NULL;
+ int l;
+ struct list_head *pos;
+ device_t *dev;
char temp_names[3][8];
- dev_index = -1;
- for (i=1; i<=ListNumItems(devlist); i++) {
- dev = ListGetPtrToItem (devlist, i);
- if(strcmp(dev->name,devname)==0) {
- dev_index=i;
- break;
- }
- }
- if(dev_index<0) /* device not found */
- return 0;
+ dev = device_get_by_name(devname);
+
+ if(!dev) /* device not found */
+ return -1;
/* get stdio devices (ListRemoveItem changes the dev list) */
for (l=0 ; l< MAX_FILES; l++) {
if (stdio_devices[l] == dev) {
stdio_devices[l]->name,
sizeof(stdio_devices[l]->name));
}
- ListRemoveItem(devlist,NULL,dev_index);
+
+ list_del(&(dev->list));
+
/* reassign Device list */
- for (i=1; i<=ListNumItems(devlist); i++) {
- dev = ListGetPtrToItem (devlist, i);
+ list_for_each(pos, &(devs.list)) {
+ dev = list_entry(pos, device_t, list);
for (l=0 ; l< MAX_FILES; l++) {
- if(strcmp(dev->name,temp_names[l])==0) {
+ if(strcmp(dev->name, temp_names[l]) == 0)
stdio_devices[l] = dev;
- }
}
}
return 0;
int devices_init (void)
{
-#ifndef CONFIG_ARM /* already relocated for current ARM implementation */
+#ifndef CONFIG_ARM /* already relocated for current ARM implementation */
ulong relocation_offset = gd->reloc_off;
int i;
#endif
/* Initialize the list */
- devlist = ListCreate (sizeof (device_t));
+ INIT_LIST_HEAD(&(devs.list));
- if (devlist == NULL) {
- eputs ("Cannot initialize the list of devices!\n");
- return -1;
- }
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
#endif
return (0);
}
-
-int devices_done (void)
-{
- ListDispose (devlist);
-
- return 0;
-}
+++ /dev/null
-/*
- * (C) Copyright 2000-2006
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program 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 2 of
- * the License, or (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <watchdog.h>
-#include <command.h>
-#include <image.h>
-#include <malloc.h>
-#include <zlib.h>
-
-#define ZALLOC_ALIGNMENT 16
-#define HEAD_CRC 2
-#define EXTRA_FIELD 4
-#define ORIG_NAME 8
-#define COMMENT 0x10
-#define RESERVED 0xe0
-#define DEFLATED 8
-
-int gunzip(void *, int, unsigned char *, unsigned long *);
-void *zalloc(void *, unsigned, unsigned);
-void zfree(void *, void *, unsigned);
-
-void *zalloc(void *x, unsigned items, unsigned size)
-{
- void *p;
-
- size *= items;
- size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
-
- p = malloc (size);
-
- return (p);
-}
-
-void zfree(void *x, void *addr, unsigned nb)
-{
- free (addr);
-}
-
-int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
-{
- z_stream s;
- int r, i, flags;
-
- /* skip header */
- i = 10;
- flags = src[3];
- if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
- puts ("Error: Bad gzipped data\n");
- return (-1);
- }
- if ((flags & EXTRA_FIELD) != 0)
- i = 12 + src[10] + (src[11] << 8);
- if ((flags & ORIG_NAME) != 0)
- while (src[i++] != 0)
- ;
- if ((flags & COMMENT) != 0)
- while (src[i++] != 0)
- ;
- if ((flags & HEAD_CRC) != 0)
- i += 2;
- if (i >= *lenp) {
- puts ("Error: gunzip out of data in header\n");
- return (-1);
- }
-
- s.zalloc = zalloc;
- s.zfree = zfree;
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- s.outcb = (cb_func)WATCHDOG_RESET;
-#else
- s.outcb = Z_NULL;
-#endif /* CONFIG_HW_WATCHDOG */
-
- r = inflateInit2(&s, -MAX_WBITS);
- if (r != Z_OK) {
- printf ("Error: inflateInit2() returned %d\n", r);
- return (-1);
- }
- s.next_in = src + i;
- s.avail_in = *lenp - i;
- s.next_out = dst;
- s.avail_out = dstlen;
- r = inflate(&s, Z_FINISH);
- if (r != Z_OK && r != Z_STREAM_END) {
- printf ("Error: inflate() returned %d\n", r);
- return (-1);
- }
- *lenp = s.next_out - (unsigned char *) dst;
- inflateEnd(&s);
-
- return (0);
-}
+++ /dev/null
-#include <common.h>
-#include <malloc.h>
-#include <lists.h>
-
-#define MAX(a,b) (((a)>(b)) ? (a) : (b))
-#define MIN(a,b) (((a)<(b)) ? (a) : (b))
-#define CAT4CHARS(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d)
-
-/* increase list size by 10% every time it is full */
-#define kDefaultAllocationPercentIncrease 10
-
-/* always increase list size by 4 items when it is full */
-#define kDefaultAllocationminNumItemsIncrease 4
-
-/*
- * how many items to expand the list by when it becomes full
- * = current listSize (in items) + (hiword percent of list size) + loword
- */
-#define NUMITEMSPERALLOC(list) MAX(((*list)->listSize * \
- ((*list)->percentIncrease + 100)) / 100, \
- (*list)->minNumItemsIncrease )
-
-#define ITEMPTR(list,item) &(((char *)&(*list)->itemList)[(*(list))->itemSize * (item)])
-
-#define LIST_SIGNATURE CAT4CHARS('L', 'I', 'S', 'T');
-
-#define calloc(size,num) malloc(size*num)
-
-/********************************************************************/
-
-Handle NewHandle (unsigned int numBytes)
-{
- void *memPtr;
- HandleRecord *hanPtr;
-
- memPtr = calloc (numBytes, 1);
- hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord), 1);
- if (hanPtr && (memPtr || numBytes == 0)) {
- hanPtr->ptr = memPtr;
- hanPtr->size = numBytes;
- return (Handle) hanPtr;
- } else {
- free (memPtr);
- free (hanPtr);
- return NULL;
- }
-}
-/********************************************************************/
-
-void DisposeHandle (Handle handle)
-{
- if (handle) {
- free (*handle);
- free ((void *) handle);
- }
-}
-/********************************************************************/
-
-unsigned int GetHandleSize (Handle handle)
-{
- return ((HandleRecord *) handle)->size;
-}
-/********************************************************************/
-
-int SetHandleSize (Handle handle, unsigned int newSize)
-{
- HandleRecord *hanRecPtr = (HandleRecord *) handle;
- void *newPtr, *oldPtr;
- unsigned int oldSize;
-
-
- oldPtr = hanRecPtr->ptr;
- oldSize = hanRecPtr->size;
-
- if (oldSize == newSize)
- return 1;
-
- if (oldPtr == NULL) {
- newPtr = malloc (newSize);
- } else {
- newPtr = realloc (oldPtr, newSize);
- }
- if (newPtr || (newSize == 0)) {
- hanRecPtr->ptr = newPtr;
- hanRecPtr->size = newSize;
- if (newSize > oldSize)
- memset ((char *) newPtr + oldSize, 0, newSize - oldSize);
- return 1;
- } else
- return 0;
-}
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-/* Used to compare list elements by their raw data contents */
-static int ListMemBlockCmp (void *a, void *b, int size)
-{
- return memcmp (a, b, size);
-}
-
-/***************************************************************************/
-
-/*
- * Binary search numElements of size elementSize in array for a match
- * to the. item. Return the index of the element that matches
- * (0 - numElements - 1). If no match is found return the -i-1 where
- * i is the index (0 - numElements) where the item should be placed.
- * (*theCmp)(a,b) should return <0 if a<b, 0 if a==b, >0 if a>b.
- *
- * This function is like the C-Library function bsearch() except that
- * this function returns the index where the item should be placed if
- * it is not found.
- */
-int BinSearch ( void *array, int numElements, int elementSize,
- void *itemPtr, CompareFunction compareFunction)
-{
- int low, high, mid, cmp;
- void *arrayItemPtr;
-
- for (low = 0, high = numElements - 1, mid = 0, cmp = -1; low <= high;) {
- mid = (low + high) >> 1;
-
- arrayItemPtr = (void *) (((char *) array) + (mid * elementSize));
- cmp = compareFunction
- ? compareFunction (itemPtr, arrayItemPtr)
- : ListMemBlockCmp (itemPtr, arrayItemPtr, elementSize);
- if (cmp == 0) {
- return mid;
- } else if (cmp < 0) {
- high = mid - 1;
- } else {
- low = mid + 1;
- }
- }
- if (cmp > 0)
- mid++;
-
- return -mid - 1;
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
-
-/*******************************************************************************/
-
-/*
- * If numNewItems == 0 then expand the list by the number of items
- * indicated by its allocation policy.
- * If numNewItems > 0 then expand the list by exactly the number of
- * items indicated.
- * If numNewItems < 0 then expand the list by the absolute value of
- * numNewItems plus the number of items indicated by its allocation
- * policy.
- * Returns 1 for success, 0 if out of memory
-*/
-static int ExpandListSpace (list_t list, int numNewItems)
-{
- if (numNewItems == 0) {
- numNewItems = NUMITEMSPERALLOC (list);
- } else if (numNewItems < 0) {
- numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list);
- }
-
- if (SetHandleSize ((Handle) list,
- sizeof (ListStruct) +
- ((*list)->listSize +
- numNewItems) * (*list)->itemSize)) {
- (*list)->listSize += numNewItems;
- return 1;
- } else {
- return 0;
- }
-}
-
-/*******************************/
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-/*
- * This function reallocate the list, minus any currently unused
- * portion of its allotted memory.
- */
-void ListCompact (list_t list)
-{
-
- if (!SetHandleSize ((Handle) list,
- sizeof (ListStruct) +
- (*list)->numItems * (*list)->itemSize)) {
- return;
- }
-
- (*list)->listSize = (*list)->numItems;
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
-
-/*******************************/
-
-list_t ListCreate (int elementSize)
-{
- list_t list;
-
- list = (list_t) (NewHandle (sizeof (ListStruct))); /* create empty list */
- if (list) {
- (*list)->signature = LIST_SIGNATURE;
- (*list)->numItems = 0;
- (*list)->listSize = 0;
- (*list)->itemSize = elementSize;
- (*list)->percentIncrease = kDefaultAllocationPercentIncrease;
- (*list)->minNumItemsIncrease =
- kDefaultAllocationminNumItemsIncrease;
- }
-
- return list;
-}
-
-/*******************************/
-
-void ListSetAllocationPolicy (list_t list, int minItemsPerAlloc,
- int percentIncreasePerAlloc)
-{
- (*list)->percentIncrease = percentIncreasePerAlloc;
- (*list)->minNumItemsIncrease = minItemsPerAlloc;
-}
-
-/*******************************/
-
-void ListDispose (list_t list)
-{
- DisposeHandle ((Handle) list);
-}
-/*******************************/
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-void ListDisposePtrList (list_t list)
-{
- int index;
- int numItems;
-
- if (list) {
- numItems = ListNumItems (list);
-
- for (index = 1; index <= numItems; index++)
- free (*(void **) ListGetPtrToItem (list, index));
-
- ListDispose (list);
- }
-}
-
-/*******************************/
-
-/*
- * keeps memory, resets the number of items to 0
- */
-void ListClear (list_t list)
-{
- if (!list)
- return;
- (*list)->numItems = 0;
-}
-
-/*******************************/
-
-/*
- * copy is only as large as necessary
- */
-list_t ListCopy (list_t originalList)
-{
- list_t tempList = NULL;
- int numItems;
-
- if (!originalList)
- return NULL;
-
- tempList = ListCreate ((*originalList)->itemSize);
- if (tempList) {
- numItems = ListNumItems (originalList);
-
- if (!SetHandleSize ((Handle) tempList,
- sizeof (ListStruct) +
- numItems * (*tempList)->itemSize)) {
- ListDispose (tempList);
- return NULL;
- }
-
- (*tempList)->numItems = (*originalList)->numItems;
- (*tempList)->listSize = (*originalList)->numItems;
- (*tempList)->itemSize = (*originalList)->itemSize;
- (*tempList)->percentIncrease = (*originalList)->percentIncrease;
- (*tempList)->minNumItemsIncrease =
- (*originalList)->minNumItemsIncrease;
-
- memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0),
- numItems * (*tempList)->itemSize);
- }
-
- return tempList;
-}
-
-/********************************/
-
-/*
- * list1 = list1 + list2
- */
-int ListAppend (list_t list1, list_t list2)
-{
- int numItemsL1, numItemsL2;
-
- if (!list2)
- return 1;
-
- if (!list1)
- return 0;
- if ((*list1)->itemSize != (*list2)->itemSize)
- return 0;
-
- numItemsL1 = ListNumItems (list1);
- numItemsL2 = ListNumItems (list2);
-
- if (numItemsL2 == 0)
- return 1;
-
- if (!SetHandleSize ((Handle) list1,
- sizeof (ListStruct) + (numItemsL1 + numItemsL2) *
- (*list1)->itemSize)) {
- return 0;
- }
-
- (*list1)->numItems = numItemsL1 + numItemsL2;
- (*list1)->listSize = numItemsL1 + numItemsL2;
-
- memmove (ITEMPTR (list1, numItemsL1),
- ITEMPTR (list2, 0),
- numItemsL2 * (*list2)->itemSize);
-
- return 1;
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
-
-/*******************************/
-
-/*
- * returns 1 if the item is inserted, returns 0 if out of memory or
- * bad arguments were passed.
- */
-int ListInsertItem (list_t list, void *ptrToItem, int itemPosition)
-{
- return ListInsertItems (list, ptrToItem, itemPosition, 1);
-}
-
-/*******************************/
-
-int ListInsertItems (list_t list, void *ptrToItems, int firstItemPosition,
- int numItemsToInsert)
-{
- int numItems = (*list)->numItems;
-
- if (firstItemPosition == numItems + 1)
- firstItemPosition = LIST_END;
- else if (firstItemPosition > numItems)
- return 0;
-
- if ((*list)->numItems >= (*list)->listSize) {
- if (!ExpandListSpace (list, -numItemsToInsert))
- return 0;
- }
-
- if (firstItemPosition == LIST_START) {
- if (numItems == 0) {
- /* special case for empty list */
- firstItemPosition = LIST_END;
- } else {
- firstItemPosition = 1;
- }
- }
-
- if (firstItemPosition == LIST_END) { /* add at the end of the list */
- if (ptrToItems)
- memcpy (ITEMPTR (list, numItems), ptrToItems,
- (*list)->itemSize * numItemsToInsert);
- else
- memset (ITEMPTR (list, numItems), 0,
- (*list)->itemSize * numItemsToInsert);
-
- (*list)->numItems += numItemsToInsert;
- } else { /* move part of list up to make room for new item */
- memmove (ITEMPTR (list, firstItemPosition - 1 + numItemsToInsert),
- ITEMPTR (list, firstItemPosition - 1),
- (numItems + 1 - firstItemPosition) * (*list)->itemSize);
-
- if (ptrToItems)
- memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems,
- (*list)->itemSize * numItemsToInsert);
- else
- memset (ITEMPTR (list, firstItemPosition - 1), 0,
- (*list)->itemSize * numItemsToInsert);
-
- (*list)->numItems += numItemsToInsert;
- }
-
- return 1;
-}
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-/*******************************/
-
-int ListEqual (list_t list1, list_t list2)
-{
- if (list1 == list2)
- return 1;
-
- if (list1 == NULL || list2 == NULL)
- return 0;
-
- if ((*list1)->itemSize == (*list1)->itemSize) {
- if ((*list1)->numItems == (*list2)->numItems) {
- return (memcmp (ITEMPTR (list1, 0), ITEMPTR (list2, 0),
- (*list1)->itemSize * (*list1)->numItems) == 0);
- }
- }
-
- return 0;
-}
-
-/*******************************/
-
-/*
- * The item pointed to by ptrToItem is copied over the current item
- * at itemPosition
- */
-void ListReplaceItem (list_t list, void *ptrToItem, int itemPosition)
-{
- ListReplaceItems (list, ptrToItem, itemPosition, 1);
-}
-
-/*******************************/
-
-/*
- * The item pointed to by ptrToItems is copied over the current item
- * at itemPosition
- */
-void ListReplaceItems ( list_t list, void *ptrToItems,
- int firstItemPosition, int numItemsToReplace)
-{
-
- if (firstItemPosition == LIST_END)
- firstItemPosition = (*list)->numItems;
- else if (firstItemPosition == LIST_START)
- firstItemPosition = 1;
-
- memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems,
- (*list)->itemSize * numItemsToReplace);
-}
-
-/*******************************/
-
-void ListGetItem (list_t list, void *itemDestination, int itemPosition)
-{
- ListGetItems (list, itemDestination, itemPosition, 1);
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
-
-/*******************************/
-
-#if defined(CFG_ALL_LIST_FUNCTIONS) || defined(CFG_DEVICE_DEREGISTER)
-
-void ListRemoveItem (list_t list, void *itemDestination, int itemPosition)
-{
- ListRemoveItems (list, itemDestination, itemPosition, 1);
-}
-
-/*******************************/
-
-void ListRemoveItems (list_t list, void *itemsDestination,
- int firstItemPosition, int numItemsToRemove)
-{
- int firstItemAfterChunk, numToMove;
-
- if (firstItemPosition == LIST_START)
- firstItemPosition = 1;
- else if (firstItemPosition == LIST_END)
- firstItemPosition = (*list)->numItems;
-
- if (itemsDestination != NULL)
- memcpy (itemsDestination, ITEMPTR (list, firstItemPosition - 1),
- (*list)->itemSize * numItemsToRemove);
-
- firstItemAfterChunk = firstItemPosition + numItemsToRemove;
- numToMove = (*list)->numItems - (firstItemAfterChunk - 1);
-
- if (numToMove > 0) {
- /*
- * move part of list down to cover hole left by removed item
- */
- memmove (ITEMPTR (list, firstItemPosition - 1),
- ITEMPTR (list, firstItemAfterChunk - 1),
- (*list)->itemSize * numToMove);
- }
-
- (*list)->numItems -= numItemsToRemove;
-}
-#endif /* CFG_ALL_LIST_FUNCTIONS || CFG_DEVICE_DEREGISTER */
-
-/*******************************/
-
-void ListGetItems (list_t list, void *itemsDestination,
- int firstItemPosition, int numItemsToGet)
-{
-
- if (firstItemPosition == LIST_START)
- firstItemPosition = 1;
- else if (firstItemPosition == LIST_END)
- firstItemPosition = (*list)->numItems;
-
- memcpy (itemsDestination,
- ITEMPTR (list, firstItemPosition - 1),
- (*list)->itemSize * numItemsToGet);
-}
-
-/*******************************/
-
-/*
- * Returns a pointer to the item at itemPosition. returns null if an
- * errors occurred.
- */
-void *ListGetPtrToItem (list_t list, int itemPosition)
-{
- if (itemPosition == LIST_START)
- itemPosition = 1;
- else if (itemPosition == LIST_END)
- itemPosition = (*list)->numItems;
-
- return ITEMPTR (list, itemPosition - 1);
-}
-
-/*******************************/
-
-/*
- * returns a pointer the lists data (abstraction violation for
- * optimization)
- */
-void *ListGetDataPtr (list_t list)
-{
- return &((*list)->itemList[0]);
-}
-
-/********************************/
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-int ListApplyToEach (list_t list, int ascending,
- ListApplicationFunc funcToApply,
- void *callbackData)
-{
- int result = 0, index;
-
- if (!list || !funcToApply)
- goto Error;
-
- if (ascending) {
- for (index = 1; index <= ListNumItems (list); index++) {
- result = funcToApply (index,
- ListGetPtrToItem (list, index),
- callbackData);
- if (result < 0)
- goto Error;
- }
- } else {
- for (index = ListNumItems (list);
- index > 0 && index <= ListNumItems (list);
- index--) {
- result = funcToApply (index,
- ListGetPtrToItem (list, index),
- callbackData);
- if (result < 0)
- goto Error;
- }
- }
-
-Error:
- return result;
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
-
-/********************************/
-
-int ListGetItemSize (list_t list)
-{
- return (*list)->itemSize;
-}
-
-/********************************/
-
-int ListNumItems (list_t list)
-{
- return (*list)->numItems;
-}
-
-/*******************************/
-
-#ifdef CFG_ALL_LIST_FUNCTIONS
-
-void ListRemoveDuplicates (list_t list, CompareFunction compareFunction)
-{
- int numItems, index, startIndexForFind, duplicatesIndex;
-
- numItems = ListNumItems (list);
-
- for (index = 1; index < numItems; index++) {
- startIndexForFind = index + 1;
- while (startIndexForFind <= numItems) {
- duplicatesIndex =
- ListFindItem (list,
- ListGetPtrToItem (list, index),
- startIndexForFind,
- compareFunction);
- if (duplicatesIndex > 0) {
- ListRemoveItem (list, NULL, duplicatesIndex);
- numItems--;
- startIndexForFind = duplicatesIndex;
- } else {
- break;
- }
- }
- }
-}
-
-/*******************************/
-
-
-/*******************************/
-
-int ListFindItem (list_t list, void *ptrToItem, int startingPosition,
- CompareFunction compareFunction)
-{
- int numItems, size, index, cmp;
- void *listItemPtr;
-
- if ((numItems = (*list)->numItems) == 0)
- return 0;
-
- size = (*list)->itemSize;
-
- if (startingPosition == LIST_START)
- startingPosition = 1;
- else if (startingPosition == LIST_END)
- startingPosition = numItems;
-
- for (index = startingPosition; index <= numItems; index++) {
- listItemPtr = ITEMPTR (list, index - 1);
- cmp = compareFunction
- ? compareFunction (ptrToItem, listItemPtr)
- : ListMemBlockCmp (ptrToItem, listItemPtr, size);
- if (cmp == 0)
- return index;
- }
-
- return 0;
-}
-
-/*******************************/
-
-int ShortCompare (void *a, void *b)
-{
- if (*(short *) a < *(short *) b)
- return -1;
- if (*(short *) a > *(short *) b)
- return 1;
- return 0;
-}
-
-/*******************************/
-
-int IntCompare (void *a, void *b)
-{
- if (*(int *) a < *(int *) b)
- return -1;
- if (*(int *) a > *(int *) b)
- return 1;
- return 0;
-}
-
-/*******************************/
-
-int CStringCompare (void *a, void *b)
-{
- return strcmp (*(char **) a, *(char **) b);
-}
-
-/*******************************/
-
-
-int ListBinSearch (list_t list, void *ptrToItem,
- CompareFunction compareFunction)
-{
- int index;
-
- index = BinSearch (ITEMPTR (list, 0),
- (int) (*list)->numItems,
- (int) (*list)->itemSize, ptrToItem,
- compareFunction);
-
- if (index >= 0)
- index++; /* lists start from 1 */
- else
- index = 0; /* item not found */
-
- return index;
-}
-
-/**************************************************************************/
-
-/*
- * Reserves memory for numItems in the list. If it succeeds then
- * numItems items can be inserted without possibility of an out of
- * memory error (useful to simplify error recovery in complex
- * functions). Returns 1 if success, 0 if out of memory.
- */
-int ListPreAllocate (list_t list, int numItems)
-{
- if ((*list)->listSize - (*list)->numItems < numItems) {
- return ExpandListSpace (list,
- numItems - ((*list)->listSize -
- (*list)->numItems));
- } else {
- return 1; /* enough items are already pre-allocated */
- }
-}
-
-#endif /* CFG_ALL_LIST_FUNCTIONS */
+++ /dev/null
-/*
- * (C) Copyright 2001
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program 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 2 of
- * the License, or (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-/*
- * This provides a bit-banged interface to the ethernet MII management
- * channel.
- */
-
-#include <common.h>
-#include <ioports.h>
-#include <ppc_asm.tmpl>
-
-/*****************************************************************************
- *
- * Utility to send the preamble, address, and register (common to read
- * and write).
- */
-static void miiphy_pre (char read, unsigned char addr, unsigned char reg)
-{
- int j; /* counter */
-#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
- volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
-#endif
-
- /*
- * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure.
- * The IEEE spec says this is a PHY optional requirement. The AMD
- * 79C874 requires one after power up and one after a MII communications
- * error. This means that we are doing more preambles than we need,
- * but it is safer and will be much more robust.
- */
-
- MDIO_ACTIVE;
- MDIO (1);
- for (j = 0; j < 32; j++) {
- MDC (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- }
-
- /* send the start bit (01) and the read opcode (10) or write (10) */
- MDC (0);
- MDIO (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- MDC (0);
- MDIO (1);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- MDC (0);
- MDIO (read);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- MDC (0);
- MDIO (!read);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
-
- /* send the PHY address */
- for (j = 0; j < 5; j++) {
- MDC (0);
- if ((addr & 0x10) == 0) {
- MDIO (0);
- } else {
- MDIO (1);
- }
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- addr <<= 1;
- }
-
- /* send the register address */
- for (j = 0; j < 5; j++) {
- MDC (0);
- if ((reg & 0x10) == 0) {
- MDIO (0);
- } else {
- MDIO (1);
- }
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- reg <<= 1;
- }
-}
-
-
-/*****************************************************************************
- *
- * Read a MII PHY register.
- *
- * Returns:
- * 0 on success
- */
-int bb_miiphy_read (char *devname, unsigned char addr,
- unsigned char reg, unsigned short *value)
-{
- short rdreg; /* register working value */
- int j; /* counter */
-#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
- volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
-#endif
-
- miiphy_pre (1, addr, reg);
-
- /* tri-state our MDIO I/O pin so we can read */
- MDC (0);
- MDIO_TRISTATE;
- MIIDELAY;
- MDC (1);
- MIIDELAY;
-
- /* check the turnaround bit: the PHY should be driving it to zero */
- if (MDIO_READ != 0) {
- /* puts ("PHY didn't drive TA low\n"); */
- for (j = 0; j < 32; j++) {
- MDC (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- }
- return (-1);
- }
-
- MDC (0);
- MIIDELAY;
-
- /* read 16 bits of register data, MSB first */
- rdreg = 0;
- for (j = 0; j < 16; j++) {
- MDC (1);
- MIIDELAY;
- rdreg <<= 1;
- rdreg |= MDIO_READ;
- MDC (0);
- MIIDELAY;
- }
-
- MDC (1);
- MIIDELAY;
- MDC (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
-
- *value = rdreg;
-
-#ifdef DEBUG
- printf ("miiphy_read(0x%x) @ 0x%x = 0x%04x\n", reg, addr, *value);
-#endif
-
- return 0;
-}
-
-
-/*****************************************************************************
- *
- * Write a MII PHY register.
- *
- * Returns:
- * 0 on success
- */
-int bb_miiphy_write (char *devname, unsigned char addr,
- unsigned char reg, unsigned short value)
-{
- int j; /* counter */
-#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
- volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
-#endif
-
- miiphy_pre (0, addr, reg);
-
- /* send the turnaround (10) */
- MDC (0);
- MDIO (1);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- MDC (0);
- MDIO (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
-
- /* write 16 bits of register data, MSB first */
- for (j = 0; j < 16; j++) {
- MDC (0);
- if ((value & 0x00008000) == 0) {
- MDIO (0);
- } else {
- MDIO (1);
- }
- MIIDELAY;
- MDC (1);
- MIIDELAY;
- value <<= 1;
- }
-
- /*
- * Tri-state the MDIO line.
- */
- MDIO_TRISTATE;
- MDC (0);
- MIIDELAY;
- MDC (1);
- MIIDELAY;
-
- return 0;
-}
#include <common.h>
#include <miiphy.h>
-#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
#include <asm/types.h>
#include <linux/list.h>
#include <malloc.h>
}
}
#endif
-#endif /* CONFIG_MII */
+++ /dev/null
-/*
- * (C) Copyright 2001, 2002
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program 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 2 of
- * the License, or (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
- * This has been changed substantially by Gerald Van Baren, Custom IDEAS,
- * Neil Russell.
- */
-
-#include <common.h>
-#ifdef CONFIG_MPC8260 /* only valid for MPC8260 */
-#include <ioports.h>
-#endif
-#ifdef CONFIG_AT91RM9200 /* need this for the at91rm9200 */
-#include <asm/io.h>
-#include <asm/arch/hardware.h>
-#endif
-#ifdef CONFIG_IXP425 /* only valid for IXP425 */
-#include <asm/arch/ixp425.h>
-#endif
-#ifdef CONFIG_LPC2292
-#include <asm/arch/hardware.h>
-#endif
-#include <i2c.h>
-
-/* #define DEBUG_I2C */
-
-#ifdef DEBUG_I2C
-DECLARE_GLOBAL_DATA_PTR;
-#endif
-
-
-/*-----------------------------------------------------------------------
- * Definitions
- */
-
-#define RETRIES 0
-
-
-#define I2C_ACK 0 /* PD_SDA level to ack a byte */
-#define I2C_NOACK 1 /* PD_SDA level to noack a byte */
-
-
-#ifdef DEBUG_I2C
-#define PRINTD(fmt,args...) do { \
- if (gd->have_console) \
- printf (fmt ,##args); \
- } while (0)
-#else
-#define PRINTD(fmt,args...)
-#endif
-
-/*-----------------------------------------------------------------------
- * Local functions
- */
-static void send_reset (void);
-static void send_start (void);
-static void send_stop (void);
-static void send_ack (int);
-static int write_byte (uchar byte);
-static uchar read_byte (int);
-
-
-/*-----------------------------------------------------------------------
- * Send a reset sequence consisting of 9 clocks with the data signal high
- * to clock any confused device back into an idle state. Also send a
- * <stop> at the end of the sequence for belts & suspenders.
- */
-static void send_reset(void)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
- int j;
-
- I2C_SCL(1);
- I2C_SDA(1);
-#ifdef I2C_INIT
- I2C_INIT;
-#endif
- I2C_TRISTATE;
- for(j = 0; j < 9; j++) {
- I2C_SCL(0);
- I2C_DELAY;
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_DELAY;
- }
- send_stop();
- I2C_TRISTATE;
-}
-
-/*-----------------------------------------------------------------------
- * START: High -> Low on SDA while SCL is High
- */
-static void send_start(void)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
-
- I2C_DELAY;
- I2C_SDA(1);
- I2C_ACTIVE;
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_SDA(0);
- I2C_DELAY;
-}
-
-/*-----------------------------------------------------------------------
- * STOP: Low -> High on SDA while SCL is High
- */
-static void send_stop(void)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
-
- I2C_SCL(0);
- I2C_DELAY;
- I2C_SDA(0);
- I2C_ACTIVE;
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_SDA(1);
- I2C_DELAY;
- I2C_TRISTATE;
-}
-
-
-/*-----------------------------------------------------------------------
- * ack should be I2C_ACK or I2C_NOACK
- */
-static void send_ack(int ack)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
-
- I2C_SCL(0);
- I2C_DELAY;
- I2C_ACTIVE;
- I2C_SDA(ack);
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_DELAY;
- I2C_SCL(0);
- I2C_DELAY;
-}
-
-
-/*-----------------------------------------------------------------------
- * Send 8 bits and look for an acknowledgement.
- */
-static int write_byte(uchar data)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
- int j;
- int nack;
-
- I2C_ACTIVE;
- for(j = 0; j < 8; j++) {
- I2C_SCL(0);
- I2C_DELAY;
- I2C_SDA(data & 0x80);
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_DELAY;
-
- data <<= 1;
- }
-
- /*
- * Look for an <ACK>(negative logic) and return it.
- */
- I2C_SCL(0);
- I2C_DELAY;
- I2C_SDA(1);
- I2C_TRISTATE;
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- I2C_DELAY;
- nack = I2C_READ;
- I2C_SCL(0);
- I2C_DELAY;
- I2C_ACTIVE;
-
- return(nack); /* not a nack is an ack */
-}
-
-
-/*-----------------------------------------------------------------------
- * if ack == I2C_ACK, ACK the byte so can continue reading, else
- * send I2C_NOACK to end the read.
- */
-static uchar read_byte(int ack)
-{
-#ifdef CONFIG_MPC8260
- volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
-#endif
-#ifdef CONFIG_8xx
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
- int data;
- int j;
-
- /*
- * Read 8 bits, MSB first.
- */
- I2C_TRISTATE;
- I2C_SDA(1);
- data = 0;
- for(j = 0; j < 8; j++) {
- I2C_SCL(0);
- I2C_DELAY;
- I2C_SCL(1);
- I2C_DELAY;
- data <<= 1;
- data |= I2C_READ;
- I2C_DELAY;
- }
- send_ack(ack);
-
- return(data);
-}
-
-/*=====================================================================*/
-/* Public Functions */
-/*=====================================================================*/
-
-/*-----------------------------------------------------------------------
- * Initialization
- */
-void i2c_init (int speed, int slaveaddr)
-{
- /*
- * WARNING: Do NOT save speed in a static variable: if the
- * I2C routines are called before RAM is initialized (to read
- * the DIMM SPD, for instance), RAM won't be usable and your
- * system will crash.
- */
- send_reset ();
-}
-
-/*-----------------------------------------------------------------------
- * Probe to see if a chip is present. Also good for checking for the
- * completion of EEPROM writes since the chip stops responding until
- * the write completes (typically 10mSec).
- */
-int i2c_probe(uchar addr)
-{
- int rc;
-
- /*
- * perform 1 byte write transaction with just address byte
- * (fake write)
- */
- send_start();
- rc = write_byte ((addr << 1) | 0);
- send_stop();
-
- return (rc ? 1 : 0);
-}
-
-/*-----------------------------------------------------------------------
- * Read bytes
- */
-int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
-{
- int shift;
- PRINTD("i2c_read: chip %02X addr %02X alen %d buffer %p len %d\n",
- chip, addr, alen, buffer, len);
-
-#ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW
- /*
- * EEPROM chips that implement "address overflow" are ones
- * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
- * address and the extra bits end up in the "chip address"
- * bit slots. This makes a 24WC08 (1Kbyte) chip look like
- * four 256 byte chips.
- *
- * Note that we consider the length of the address field to
- * still be one byte because the extra address bits are
- * hidden in the chip address.
- */
- chip |= ((addr >> (alen * 8)) & CFG_I2C_EEPROM_ADDR_OVERFLOW);
-
- PRINTD("i2c_read: fix addr_overflow: chip %02X addr %02X\n",
- chip, addr);
-#endif
-
- /*
- * Do the addressing portion of a write cycle to set the
- * chip's address pointer. If the address length is zero,
- * don't do the normal write cycle to set the address pointer,
- * there is no address pointer in this chip.
- */
- send_start();
- if(alen > 0) {
- if(write_byte(chip << 1)) { /* write cycle */
- send_stop();
- PRINTD("i2c_read, no chip responded %02X\n", chip);
- return(1);
- }
- shift = (alen-1) * 8;
- while(alen-- > 0) {
- if(write_byte(addr >> shift)) {
- PRINTD("i2c_read, address not <ACK>ed\n");
- return(1);
- }
- shift -= 8;
- }
- send_stop(); /* reportedly some chips need a full stop */
- send_start();
- }
- /*
- * Send the chip address again, this time for a read cycle.
- * Then read the data. On the last byte, we do a NACK instead
- * of an ACK(len == 0) to terminate the read.
- */
- write_byte((chip << 1) | 1); /* read cycle */
- while(len-- > 0) {
- *buffer++ = read_byte(len == 0);
- }
- send_stop();
- return(0);
-}
-
-/*-----------------------------------------------------------------------
- * Write bytes
- */
-int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
-{
- int shift, failures = 0;
-
- PRINTD("i2c_write: chip %02X addr %02X alen %d buffer %p len %d\n",
- chip, addr, alen, buffer, len);
-
- send_start();
- if(write_byte(chip << 1)) { /* write cycle */
- send_stop();
- PRINTD("i2c_write, no chip responded %02X\n", chip);
- return(1);
- }
- shift = (alen-1) * 8;
- while(alen-- > 0) {
- if(write_byte(addr >> shift)) {
- PRINTD("i2c_write, address not <ACK>ed\n");
- return(1);
- }
- shift -= 8;
- }
-
- while(len-- > 0) {
- if(write_byte(*buffer++)) {
- failures++;
- }
- }
- send_stop();
- return(failures);
-}
-
-/*-----------------------------------------------------------------------
- * Read a register
- */
-uchar i2c_reg_read(uchar i2c_addr, uchar reg)
-{
- uchar buf;
-
- i2c_read(i2c_addr, reg, 1, &buf, 1);
-
- return(buf);
-}
-
-/*-----------------------------------------------------------------------
- * Write a register
- */
-void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
- i2c_write(i2c_addr, reg, 1, &val, 1);
-}
+++ /dev/null
-/*
- * (C) Copyright 2002
- *
- * Influenced by code from:
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program 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 2 of
- * the License, or (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-#include <spi.h>
-
-#include <malloc.h>
-
-/*-----------------------------------------------------------------------
- * Definitions
- */
-
-#ifdef DEBUG_SPI
-#define PRINTD(fmt,args...) printf (fmt ,##args)
-#else
-#define PRINTD(fmt,args...)
-#endif
-
-struct soft_spi_slave {
- struct spi_slave slave;
- unsigned int mode;
-};
-
-static inline struct soft_spi_slave *to_soft_spi(struct spi_slave *slave)
-{
- return container_of(slave, struct soft_spi_slave, slave);
-}
-
-/*=====================================================================*/
-/* Public Functions */
-/*=====================================================================*/
-
-/*-----------------------------------------------------------------------
- * Initialization
- */
-void spi_init (void)
-{
-#ifdef SPI_INIT
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-
- SPI_INIT;
-#endif
-}
-
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
- unsigned int max_hz, unsigned int mode)
-{
- struct soft_spi_slave *ss;
-
- if (!spi_cs_is_valid(bus, cs))
- return NULL;
-
- ss = malloc(sizeof(struct soft_spi_slave));
- if (!ss)
- return NULL;
-
- ss->slave.bus = bus;
- ss->slave.cs = cs;
- ss->mode = mode;
-
- /* TODO: Use max_hz to limit the SCK rate */
-
- return &ss->slave;
-}
-
-void spi_free_slave(struct spi_slave *slave)
-{
- struct soft_spi_slave *ss = to_soft_spi(slave);
-
- free(ss);
-}
-
-int spi_claim_bus(struct spi_slave *slave)
-{
-#ifdef CFG_IMMR
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
- struct soft_spi_slave *ss = to_soft_spi(slave);
-
- /*
- * Make sure the SPI clock is in idle state as defined for
- * this slave.
- */
- if (ss->mode & SPI_CPOL)
- SPI_SCL(1);
- else
- SPI_SCL(0);
-
- return 0;
-}
-
-void spi_release_bus(struct spi_slave *slave)
-{
- /* Nothing to do */
-}
-
-/*-----------------------------------------------------------------------
- * SPI transfer
- *
- * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
- * "bitlen" bits in the SPI MISO port. That's just the way SPI works.
- *
- * The source of the outgoing bits is the "dout" parameter and the
- * destination of the input bits is the "din" parameter. Note that "dout"
- * and "din" can point to the same memory location, in which case the
- * input data overwrites the output data (since both are buffered by
- * temporary variables, this is OK).
- */
-int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
- const void *dout, void *din, unsigned long flags)
-{
-#ifdef CFG_IMMR
- volatile immap_t *immr = (immap_t *)CFG_IMMR;
-#endif
- struct soft_spi_slave *ss = to_soft_spi(slave);
- uchar tmpdin = 0;
- uchar tmpdout = 0;
- const u8 *txd = dout;
- u8 *rxd = din;
- int cpol = ss->mode & SPI_CPOL;
- int cpha = ss->mode & SPI_CPHA;
- unsigned int j;
-
- PRINTD("spi_xfer: slave %u:%u dout %08X din %08X bitlen %u\n",
- slave->bus, slave->cs, *(uint *)txd, *(uint *)rxd, bitlen);
-
- if (flags & SPI_XFER_BEGIN)
- spi_cs_activate(slave);
-
- for(j = 0; j < bitlen; j++) {
- /*
- * Check if it is time to work on a new byte.
- */
- if((j % 8) == 0) {
- tmpdout = *txd++;
- if(j != 0) {
- *rxd++ = tmpdin;
- }
- tmpdin = 0;
- }
-
- if (!cpha)
- SPI_SCL(!cpol);
- SPI_SDA(tmpdout & 0x80);
- SPI_DELAY;
- if (cpha)
- SPI_SCL(!cpol);
- else
- SPI_SCL(cpol);
- tmpdin <<= 1;
- tmpdin |= SPI_READ;
- tmpdout <<= 1;
- SPI_DELAY;
- if (cpha)
- SPI_SCL(cpol);
- }
- /*
- * If the number of bits isn't a multiple of 8, shift the last
- * bits over to left-justify them. Then store the last byte
- * read in.
- */
- if((bitlen % 8) != 0)
- tmpdin <<= 8 - (bitlen % 8);
- *rxd++ = tmpdin;
-
- if (flags & SPI_XFER_END)
- spi_cs_deactivate(slave);
-
- return(0);
-}
/* search for keyboard and register it if found */
int drv_usb_kbd_init(void)
{
- int error,i,index;
+ int error,i;
device_t usb_kbd_dev,*old_dev;
struct usb_device *dev;
char *stdinname = getenv ("stdin");
if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */
/* check, if it is already registered */
USB_KBD_PRINTF("USB KBD found set up device.\n");
- for (index=1; index<=ListNumItems(devlist); index++) {
- old_dev = ListGetPtrToItem(devlist, index);
- if(strcmp(old_dev->name,DEVNAME)==0) {
- /* ok, already registered, just return ok */
- USB_KBD_PRINTF("USB KBD is already registered.\n");
- return 1;
- }
+ old_dev = device_get_by_name(DEVNAME);
+ if(old_dev) {
+ /* ok, already registered, just return ok */
+ USB_KBD_PRINTF("USB KBD is already registered.\n");
+ return 1;
}
/* register the keyboard */
USB_KBD_PRINTF("USB KBD register.\n");
COBJS-$(CONFIG_I2C_MXC) += mxc_i2c.o
COBJS-$(CONFIG_DRIVER_OMAP1510_I2C) += omap1510_i2c.o
COBJS-$(CONFIG_DRIVER_OMAP24XX_I2C) += omap24xx_i2c.o
+COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o
COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
COBJS := $(COBJS-y)
--- /dev/null
+/*
+ * (C) Copyright 2001, 2002
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * This has been changed substantially by Gerald Van Baren, Custom IDEAS,
+ * Neil Russell.
+ */
+
+#include <common.h>
+#ifdef CONFIG_MPC8260 /* only valid for MPC8260 */
+#include <ioports.h>
+#endif
+#ifdef CONFIG_AT91RM9200 /* need this for the at91rm9200 */
+#include <asm/io.h>
+#include <asm/arch/hardware.h>
+#endif
+#ifdef CONFIG_IXP425 /* only valid for IXP425 */
+#include <asm/arch/ixp425.h>
+#endif
+#ifdef CONFIG_LPC2292
+#include <asm/arch/hardware.h>
+#endif
+#include <i2c.h>
+
+/* #define DEBUG_I2C */
+
+#ifdef DEBUG_I2C
+DECLARE_GLOBAL_DATA_PTR;
+#endif
+
+
+/*-----------------------------------------------------------------------
+ * Definitions
+ */
+
+#define RETRIES 0
+
+
+#define I2C_ACK 0 /* PD_SDA level to ack a byte */
+#define I2C_NOACK 1 /* PD_SDA level to noack a byte */
+
+
+#ifdef DEBUG_I2C
+#define PRINTD(fmt,args...) do { \
+ if (gd->have_console) \
+ printf (fmt ,##args); \
+ } while (0)
+#else
+#define PRINTD(fmt,args...)
+#endif
+
+/*-----------------------------------------------------------------------
+ * Local functions
+ */
+static void send_reset (void);
+static void send_start (void);
+static void send_stop (void);
+static void send_ack (int);
+static int write_byte (uchar byte);
+static uchar read_byte (int);
+
+
+/*-----------------------------------------------------------------------
+ * Send a reset sequence consisting of 9 clocks with the data signal high
+ * to clock any confused device back into an idle state. Also send a
+ * <stop> at the end of the sequence for belts & suspenders.
+ */
+static void send_reset(void)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+ int j;
+
+ I2C_SCL(1);
+ I2C_SDA(1);
+#ifdef I2C_INIT
+ I2C_INIT;
+#endif
+ I2C_TRISTATE;
+ for(j = 0; j < 9; j++) {
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_DELAY;
+ }
+ send_stop();
+ I2C_TRISTATE;
+}
+
+/*-----------------------------------------------------------------------
+ * START: High -> Low on SDA while SCL is High
+ */
+static void send_start(void)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+
+ I2C_DELAY;
+ I2C_SDA(1);
+ I2C_ACTIVE;
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_SDA(0);
+ I2C_DELAY;
+}
+
+/*-----------------------------------------------------------------------
+ * STOP: Low -> High on SDA while SCL is High
+ */
+static void send_stop(void)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_SDA(0);
+ I2C_ACTIVE;
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_SDA(1);
+ I2C_DELAY;
+ I2C_TRISTATE;
+}
+
+
+/*-----------------------------------------------------------------------
+ * ack should be I2C_ACK or I2C_NOACK
+ */
+static void send_ack(int ack)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_ACTIVE;
+ I2C_SDA(ack);
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_DELAY;
+ I2C_SCL(0);
+ I2C_DELAY;
+}
+
+
+/*-----------------------------------------------------------------------
+ * Send 8 bits and look for an acknowledgement.
+ */
+static int write_byte(uchar data)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+ int j;
+ int nack;
+
+ I2C_ACTIVE;
+ for(j = 0; j < 8; j++) {
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_SDA(data & 0x80);
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_DELAY;
+
+ data <<= 1;
+ }
+
+ /*
+ * Look for an <ACK>(negative logic) and return it.
+ */
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_SDA(1);
+ I2C_TRISTATE;
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ I2C_DELAY;
+ nack = I2C_READ;
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_ACTIVE;
+
+ return(nack); /* not a nack is an ack */
+}
+
+
+/*-----------------------------------------------------------------------
+ * if ack == I2C_ACK, ACK the byte so can continue reading, else
+ * send I2C_NOACK to end the read.
+ */
+static uchar read_byte(int ack)
+{
+#ifdef CONFIG_MPC8260
+ volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
+#endif
+#ifdef CONFIG_8xx
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+ int data;
+ int j;
+
+ /*
+ * Read 8 bits, MSB first.
+ */
+ I2C_TRISTATE;
+ I2C_SDA(1);
+ data = 0;
+ for(j = 0; j < 8; j++) {
+ I2C_SCL(0);
+ I2C_DELAY;
+ I2C_SCL(1);
+ I2C_DELAY;
+ data <<= 1;
+ data |= I2C_READ;
+ I2C_DELAY;
+ }
+ send_ack(ack);
+
+ return(data);
+}
+
+/*=====================================================================*/
+/* Public Functions */
+/*=====================================================================*/
+
+/*-----------------------------------------------------------------------
+ * Initialization
+ */
+void i2c_init (int speed, int slaveaddr)
+{
+ /*
+ * WARNING: Do NOT save speed in a static variable: if the
+ * I2C routines are called before RAM is initialized (to read
+ * the DIMM SPD, for instance), RAM won't be usable and your
+ * system will crash.
+ */
+ send_reset ();
+}
+
+/*-----------------------------------------------------------------------
+ * Probe to see if a chip is present. Also good for checking for the
+ * completion of EEPROM writes since the chip stops responding until
+ * the write completes (typically 10mSec).
+ */
+int i2c_probe(uchar addr)
+{
+ int rc;
+
+ /*
+ * perform 1 byte write transaction with just address byte
+ * (fake write)
+ */
+ send_start();
+ rc = write_byte ((addr << 1) | 0);
+ send_stop();
+
+ return (rc ? 1 : 0);
+}
+
+/*-----------------------------------------------------------------------
+ * Read bytes
+ */
+int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
+{
+ int shift;
+ PRINTD("i2c_read: chip %02X addr %02X alen %d buffer %p len %d\n",
+ chip, addr, alen, buffer, len);
+
+#ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW
+ /*
+ * EEPROM chips that implement "address overflow" are ones
+ * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
+ * address and the extra bits end up in the "chip address"
+ * bit slots. This makes a 24WC08 (1Kbyte) chip look like
+ * four 256 byte chips.
+ *
+ * Note that we consider the length of the address field to
+ * still be one byte because the extra address bits are
+ * hidden in the chip address.
+ */
+ chip |= ((addr >> (alen * 8)) & CFG_I2C_EEPROM_ADDR_OVERFLOW);
+
+ PRINTD("i2c_read: fix addr_overflow: chip %02X addr %02X\n",
+ chip, addr);
+#endif
+
+ /*
+ * Do the addressing portion of a write cycle to set the
+ * chip's address pointer. If the address length is zero,
+ * don't do the normal write cycle to set the address pointer,
+ * there is no address pointer in this chip.
+ */
+ send_start();
+ if(alen > 0) {
+ if(write_byte(chip << 1)) { /* write cycle */
+ send_stop();
+ PRINTD("i2c_read, no chip responded %02X\n", chip);
+ return(1);
+ }
+ shift = (alen-1) * 8;
+ while(alen-- > 0) {
+ if(write_byte(addr >> shift)) {
+ PRINTD("i2c_read, address not <ACK>ed\n");
+ return(1);
+ }
+ shift -= 8;
+ }
+ send_stop(); /* reportedly some chips need a full stop */
+ send_start();
+ }
+ /*
+ * Send the chip address again, this time for a read cycle.
+ * Then read the data. On the last byte, we do a NACK instead
+ * of an ACK(len == 0) to terminate the read.
+ */
+ write_byte((chip << 1) | 1); /* read cycle */
+ while(len-- > 0) {
+ *buffer++ = read_byte(len == 0);
+ }
+ send_stop();
+ return(0);
+}
+
+/*-----------------------------------------------------------------------
+ * Write bytes
+ */
+int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
+{
+ int shift, failures = 0;
+
+ PRINTD("i2c_write: chip %02X addr %02X alen %d buffer %p len %d\n",
+ chip, addr, alen, buffer, len);
+
+ send_start();
+ if(write_byte(chip << 1)) { /* write cycle */
+ send_stop();
+ PRINTD("i2c_write, no chip responded %02X\n", chip);
+ return(1);
+ }
+ shift = (alen-1) * 8;
+ while(alen-- > 0) {
+ if(write_byte(addr >> shift)) {
+ PRINTD("i2c_write, address not <ACK>ed\n");
+ return(1);
+ }
+ shift -= 8;
+ }
+
+ while(len-- > 0) {
+ if(write_byte(*buffer++)) {
+ failures++;
+ }
+ }
+ send_stop();
+ return(failures);
+}
+
+/*-----------------------------------------------------------------------
+ * Read a register
+ */
+uchar i2c_reg_read(uchar i2c_addr, uchar reg)
+{
+ uchar buf;
+
+ i2c_read(i2c_addr, reg, 1, &buf, 1);
+
+ return(buf);
+}
+
+/*-----------------------------------------------------------------------
+ * Write a register
+ */
+void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
+{
+ i2c_write(i2c_addr, reg, 1, &val, 1);
+}
--- /dev/null
+#
+# (C) Copyright 2008
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program 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 2 of
+# the License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB := $(obj)libphy.a
+
+COBJS-$(CONFIG_BITBANGMII) += miiphybb.o
+
+COBJS := $(COBJS-y)
+SRCS := $(COBJS:.o=.c)
+OBJS := $(addprefix $(obj),$(COBJS))
+
+all: $(LIB)
+
+$(LIB): $(obj).depend $(OBJS)
+ $(AR) $(ARFLAGS) $@ $(OBJS)
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
--- /dev/null
+/*
+ * (C) Copyright 2001
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * This provides a bit-banged interface to the ethernet MII management
+ * channel.
+ */
+
+#include <common.h>
+#include <ioports.h>
+#include <ppc_asm.tmpl>
+
+/*****************************************************************************
+ *
+ * Utility to send the preamble, address, and register (common to read
+ * and write).
+ */
+static void miiphy_pre (char read, unsigned char addr, unsigned char reg)
+{
+ int j; /* counter */
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
+ volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
+#endif
+
+ /*
+ * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure.
+ * The IEEE spec says this is a PHY optional requirement. The AMD
+ * 79C874 requires one after power up and one after a MII communications
+ * error. This means that we are doing more preambles than we need,
+ * but it is safer and will be much more robust.
+ */
+
+ MDIO_ACTIVE;
+ MDIO (1);
+ for (j = 0; j < 32; j++) {
+ MDC (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ }
+
+ /* send the start bit (01) and the read opcode (10) or write (10) */
+ MDC (0);
+ MDIO (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ MDC (0);
+ MDIO (1);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ MDC (0);
+ MDIO (read);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ MDC (0);
+ MDIO (!read);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+
+ /* send the PHY address */
+ for (j = 0; j < 5; j++) {
+ MDC (0);
+ if ((addr & 0x10) == 0) {
+ MDIO (0);
+ } else {
+ MDIO (1);
+ }
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ addr <<= 1;
+ }
+
+ /* send the register address */
+ for (j = 0; j < 5; j++) {
+ MDC (0);
+ if ((reg & 0x10) == 0) {
+ MDIO (0);
+ } else {
+ MDIO (1);
+ }
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ reg <<= 1;
+ }
+}
+
+
+/*****************************************************************************
+ *
+ * Read a MII PHY register.
+ *
+ * Returns:
+ * 0 on success
+ */
+int bb_miiphy_read (char *devname, unsigned char addr,
+ unsigned char reg, unsigned short *value)
+{
+ short rdreg; /* register working value */
+ int j; /* counter */
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
+ volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
+#endif
+
+ miiphy_pre (1, addr, reg);
+
+ /* tri-state our MDIO I/O pin so we can read */
+ MDC (0);
+ MDIO_TRISTATE;
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+
+ /* check the turnaround bit: the PHY should be driving it to zero */
+ if (MDIO_READ != 0) {
+ /* puts ("PHY didn't drive TA low\n"); */
+ for (j = 0; j < 32; j++) {
+ MDC (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ }
+ return (-1);
+ }
+
+ MDC (0);
+ MIIDELAY;
+
+ /* read 16 bits of register data, MSB first */
+ rdreg = 0;
+ for (j = 0; j < 16; j++) {
+ MDC (1);
+ MIIDELAY;
+ rdreg <<= 1;
+ rdreg |= MDIO_READ;
+ MDC (0);
+ MIIDELAY;
+ }
+
+ MDC (1);
+ MIIDELAY;
+ MDC (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+
+ *value = rdreg;
+
+#ifdef DEBUG
+ printf ("miiphy_read(0x%x) @ 0x%x = 0x%04x\n", reg, addr, *value);
+#endif
+
+ return 0;
+}
+
+
+/*****************************************************************************
+ *
+ * Write a MII PHY register.
+ *
+ * Returns:
+ * 0 on success
+ */
+int bb_miiphy_write (char *devname, unsigned char addr,
+ unsigned char reg, unsigned short value)
+{
+ int j; /* counter */
+#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM))
+ volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT);
+#endif
+
+ miiphy_pre (0, addr, reg);
+
+ /* send the turnaround (10) */
+ MDC (0);
+ MDIO (1);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ MDC (0);
+ MDIO (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+
+ /* write 16 bits of register data, MSB first */
+ for (j = 0; j < 16; j++) {
+ MDC (0);
+ if ((value & 0x00008000) == 0) {
+ MDIO (0);
+ } else {
+ MDIO (1);
+ }
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+ value <<= 1;
+ }
+
+ /*
+ * Tri-state the MDIO line.
+ */
+ MDIO_TRISTATE;
+ MDC (0);
+ MIIDELAY;
+ MDC (1);
+ MIIDELAY;
+
+ return 0;
+}
LIB := $(obj)libspi.a
-COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
+COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
+COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
COBJS := $(COBJS-y)
SRCS := $(COBJS:.o=.c)
--- /dev/null
+/*
+ * (C) Copyright 2002
+ *
+ * Influenced by code from:
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <spi.h>
+
+#include <malloc.h>
+
+/*-----------------------------------------------------------------------
+ * Definitions
+ */
+
+#ifdef DEBUG_SPI
+#define PRINTD(fmt,args...) printf (fmt ,##args)
+#else
+#define PRINTD(fmt,args...)
+#endif
+
+struct soft_spi_slave {
+ struct spi_slave slave;
+ unsigned int mode;
+};
+
+static inline struct soft_spi_slave *to_soft_spi(struct spi_slave *slave)
+{
+ return container_of(slave, struct soft_spi_slave, slave);
+}
+
+/*=====================================================================*/
+/* Public Functions */
+/*=====================================================================*/
+
+/*-----------------------------------------------------------------------
+ * Initialization
+ */
+void spi_init (void)
+{
+#ifdef SPI_INIT
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+
+ SPI_INIT;
+#endif
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int mode)
+{
+ struct soft_spi_slave *ss;
+
+ if (!spi_cs_is_valid(bus, cs))
+ return NULL;
+
+ ss = malloc(sizeof(struct soft_spi_slave));
+ if (!ss)
+ return NULL;
+
+ ss->slave.bus = bus;
+ ss->slave.cs = cs;
+ ss->mode = mode;
+
+ /* TODO: Use max_hz to limit the SCK rate */
+
+ return &ss->slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+ struct soft_spi_slave *ss = to_soft_spi(slave);
+
+ free(ss);
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+#ifdef CFG_IMMR
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+ struct soft_spi_slave *ss = to_soft_spi(slave);
+
+ /*
+ * Make sure the SPI clock is in idle state as defined for
+ * this slave.
+ */
+ if (ss->mode & SPI_CPOL)
+ SPI_SCL(1);
+ else
+ SPI_SCL(0);
+
+ return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+ /* Nothing to do */
+}
+
+/*-----------------------------------------------------------------------
+ * SPI transfer
+ *
+ * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
+ * "bitlen" bits in the SPI MISO port. That's just the way SPI works.
+ *
+ * The source of the outgoing bits is the "dout" parameter and the
+ * destination of the input bits is the "din" parameter. Note that "dout"
+ * and "din" can point to the same memory location, in which case the
+ * input data overwrites the output data (since both are buffered by
+ * temporary variables, this is OK).
+ */
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+ const void *dout, void *din, unsigned long flags)
+{
+#ifdef CFG_IMMR
+ volatile immap_t *immr = (immap_t *)CFG_IMMR;
+#endif
+ struct soft_spi_slave *ss = to_soft_spi(slave);
+ uchar tmpdin = 0;
+ uchar tmpdout = 0;
+ const u8 *txd = dout;
+ u8 *rxd = din;
+ int cpol = ss->mode & SPI_CPOL;
+ int cpha = ss->mode & SPI_CPHA;
+ unsigned int j;
+
+ PRINTD("spi_xfer: slave %u:%u dout %08X din %08X bitlen %u\n",
+ slave->bus, slave->cs, *(uint *)txd, *(uint *)rxd, bitlen);
+
+ if (flags & SPI_XFER_BEGIN)
+ spi_cs_activate(slave);
+
+ for(j = 0; j < bitlen; j++) {
+ /*
+ * Check if it is time to work on a new byte.
+ */
+ if((j % 8) == 0) {
+ tmpdout = *txd++;
+ if(j != 0) {
+ *rxd++ = tmpdin;
+ }
+ tmpdin = 0;
+ }
+
+ if (!cpha)
+ SPI_SCL(!cpol);
+ SPI_SDA(tmpdout & 0x80);
+ SPI_DELAY;
+ if (cpha)
+ SPI_SCL(!cpol);
+ else
+ SPI_SCL(cpol);
+ tmpdin <<= 1;
+ tmpdin |= SPI_READ;
+ tmpdout <<= 1;
+ SPI_DELAY;
+ if (cpha)
+ SPI_SCL(cpol);
+ }
+ /*
+ * If the number of bits isn't a multiple of 8, shift the last
+ * bits over to left-justify them. Then store the last byte
+ * read in.
+ */
+ if((bitlen % 8) != 0)
+ tmpdin <<= 8 - (bitlen % 8);
+ *rxd++ = tmpdin;
+
+ if (flags & SPI_XFER_END)
+ spi_cs_deactivate(slave);
+
+ return(0);
+}
#
#
-SUBDIRS := jffs2 cramfs fdos fat reiserfs ext2 yaffs2
+subdirs-$(CONFIG_CMD_CRAMFS) := cramfs
+subdirs-$(CONFIG_CMD_EXT2) += ext2
+subdirs-$(CONFIG_CMD_FAT) += fat
+subdirs-$(CONFIG_CMD_FDOS) += fdos
+subdirs-$(CONFIG_CMD_JFFS2) += jffs2
+subdirs-$(CONFIG_CMD_REISER) += reiserfs
+subdirs-$(CONFIG_YAFFS2) += yaffs2
+
+SUBDIRS := $(subdirs-y)
$(obj).depend all:
@for dir in $(SUBDIRS) ; do \
LIB = $(obj)libcramfs.a
AOBJS =
-COBJS = cramfs.o uncompress.o
+COBJS-$(CONFIG_CMD_CRAMFS) := cramfs.o
+COBJS-$(CONFIG_CMD_CRAMFS) += uncompress.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
+SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
#include <common.h>
#include <malloc.h>
-
-#if defined(CONFIG_CMD_CRAMFS)
-
#include <asm/byteorder.h>
#include <linux/stat.h>
#include <jffs2/jffs2.h>
}
return 1;
}
-
-#endif /* CFG_FS_CRAMFS */
#include <watchdog.h>
#include <zlib.h>
-#if defined(CONFIG_CMD_CRAMFS)
-
static z_stream stream;
void *zalloc(void *, unsigned, unsigned);
inflateEnd (&stream);
return 0;
}
-
-#endif /* CFG_FS_CRAMFS */
LIB = $(obj)libext2fs.a
AOBJS =
-COBJS = ext2fs.o dev.o
+COBJS-$(CONFIG_CMD_EXT2) := ext2fs.o dev.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
+SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
#include <common.h>
-#if defined(CONFIG_CMD_EXT2)
-
#include <config.h>
#include <ext2fs.h>
}
return (1);
}
-#endif
*/
#include <common.h>
-
-#if defined(CONFIG_CMD_EXT2)
#include <ext2fs.h>
#include <malloc.h>
#include <asm/byteorder.h>
ext2fs_root = NULL;
return (0);
}
-
-#endif
LIB = $(obj)libfat.a
AOBJS =
-COBJS = fat.o file.o
+COBJS-$(CONFIG_CMD_FAT) := fat.o file.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
+SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
all: $(LIB) $(AOBJS)
#include <asm/byteorder.h>
#include <part.h>
-#if defined(CONFIG_CMD_FAT)
-
/*
* Convert a string to lowercase.
*/
printf("reading %s\n",filename);
return do_fat_read(filename, buffer, maxsize, LS_NO);
}
-
-#endif
#include <linux/stat.h>
#include <linux/time.h>
-#if defined(CONFIG_CMD_FAT)
-
/* Supported filesystems */
static const struct filesystem filesystems[] = {
{ file_fat_detectfs, file_fat_ls, file_fat_read, "FAT" },
return filesystems[current_filesystem].read(arg, buffer, maxsize);
}
-
-#endif
LIB = $(obj)libfdos.a
AOBJS =
-COBJS = fat.o vfat.o dev.o fdos.o fs.o subdir.o
+COBJS-$(CONFIG_CMD_FDOS) := fat.o vfat.o dev.o fdos.o fs.o subdir.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
+SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
#include "dos.h"
#include "fdos.h"
-#if defined(CONFIG_CMD_FDOS)
-
#define NB_HEADS 2
#define NB_TRACKS 80
#define NB_SECTORS 18
return (0);
}
-
-
-#endif
#include <config.h>
#include <malloc.h>
-#if defined(CONFIG_CMD_FDOS)
-
#include "dos.h"
#include "fdos.h"
}
return (0);
}
-
-#endif
#include <common.h>
#include <config.h>
-
-#if defined(CONFIG_CMD_FDOS)
#include <malloc.h>
+
#include "dos.h"
#include "fdos.h"
free (name);
return (0);
}
-
-#endif
#include <config.h>
#include <malloc.h>
-#if defined(CONFIG_CMD_FDOS)
-
#include "dos.h"
#include "fdos.h"
free (boot);
return (0);
}
-
-#endif
#include <config.h>
#include <malloc.h>
-#if defined(CONFIG_CMD_FDOS)
-
#include "dos.h"
#include "fdos.h"
}
return (read);
}
-#endif
#include <common.h>
#include <config.h>
-
-#if defined(CONFIG_CMD_FDOS)
#include <linux/ctype.h>
#include "dos.h"
}
return (ans);
}
-
-
-#endif
LIB = $(obj)libjffs2.a
AOBJS =
-COBJS-y += jffs2_1pass.o
+ifdef CONFIG_CMD_JFFS2
+COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzari.o
+COBJS-$(CONFIG_JFFS2_LZO_LZARI) += compr_lzo.o
COBJS-y += compr_rtime.o
COBJS-y += compr_rubin.o
COBJS-y += compr_zlib.o
+COBJS-y += jffs2_1pass.o
COBJS-y += mini_inflate.o
-COBJS-y += compr_lzo.o
-COBJS-y += compr_lzari.o
+endif
COBJS := $(COBJS-y)
SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
#include <config.h>
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI)
-
#include <linux/stddef.h>
#include <jffs2/jffs2.h>
{
return Decode(data_in, cpage_out, srclen, destlen);
}
-#endif
#include <config.h>
-#if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_LZO_LZARI)
-
#include <linux/stddef.h>
#include <jffs2/jffs2.h>
#include <jffs2/compr_rubin.h>
lzo_uint outlen = destlen;
return lzo1x_decompress (data_in, srclen, cpage_out, &outlen, NULL);
}
-
-#endif
*/
#include <config.h>
-#if defined(CONFIG_CMD_JFFS2)
-
#include <jffs2/jffs2.h>
void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out,
}
}
}
-
-#endif
*/
#include <config.h>
-#if defined(CONFIG_CMD_JFFS2)
-
#include <jffs2/jffs2.h>
#include <jffs2/compr_rubin.h>
rubin_do_decompress(bits, data_in+8, cpage_out, dstlen);
}
-
-#endif
#include <common.h>
#include <config.h>
-#if defined(CONFIG_CMD_JFFS2)
-
#include <jffs2/jffs2.h>
#include <jffs2/mini_inflate.h>
return (decompress_block(cpage_out, data_in + 2, (void *) ldr_memcpy));
}
-
-#endif
#include <linux/stat.h>
#include <linux/time.h>
#include <watchdog.h>
-
-#if defined(CONFIG_CMD_JFFS2)
-
#include <jffs2/jffs2.h>
#include <jffs2/jffs2_1pass.h>
}
return 1;
}
-
-#endif
#include <common.h>
-#if !defined(CONFIG_NAND_LEGACY) && defined(CONFIG_CMD_JFFS2)
+#if !defined(CONFIG_NAND_LEGACY)
#include <malloc.h>
#include <linux/stat.h>
*/
#include <config.h>
-
-#if defined(CONFIG_CMD_JFFS2)
-
#include <jffs2/mini_inflate.h>
/* The order that the code lengths in section 3.2.7 are in */
#endif
return stream.error ? -stream.error : stream.decoded;
}
-
-#endif
LIB = $(obj)libreiserfs.a
AOBJS =
-COBJS = reiserfs.o dev.o mode_string.o
+COBJS-$(CONFIG_CMD_REISER) := reiserfs.o dev.o mode_string.o
-SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
-OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
+SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
#CPPFLAGS +=
#include <common.h>
-#if defined(CONFIG_CMD_REISER)
-
#include <config.h>
#include <reiserfs.h>
return 1;
}
-
-#endif
#include <common.h>
-#if defined(CONFIG_CMD_REISER)
#include <linux/stat.h>
#if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \
}
#endif
-
-#endif
*/
#include <common.h>
-#if defined(CONFIG_CMD_REISER)
-
#include <malloc.h>
#include <linux/ctype.h>
#include <linux/time.h>
}
return filemax;
}
-
-#endif
* MA 02111-1307 USA
*/
-#include <lists.h>
+#include <linux/list.h>
#ifndef _DEVICES_H_
#define _DEVICES_H_
/* Other functions */
void *priv; /* Private extensions */
+ struct list_head list;
} device_t;
/*
/*
* VARIABLES
*/
-extern list_t devlist;
extern device_t *stdio_devices[];
extern char *stdio_names[MAX_FILES];
*/
int device_register (device_t * dev);
int devices_init (void);
-int devices_done (void);
int device_deregister(char *devname);
+struct list_head* device_get_list(void);
+device_t* device_get_by_name(char* name);
+
#ifdef CONFIG_LCD
int drv_lcd_init (void);
#endif
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
+#include <linux/stddef.h>
+#include <linux/poison.h>
+
#ifndef ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCH
static inline void prefetch(const void *x) {;}
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
-#define INIT_LIST_HEAD(ptr) do { \
- (ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
+static inline void INIT_LIST_HEAD(struct list_head *list)
+{
+ list->next = list;
+ list->prev = list;
+}
/*
* Insert a new entry between two known consecutive entries.
/**
* list_del - deletes entry from list.
* @entry: the element to delete from the list.
- * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
*/
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
- entry->next = (void *) 0;
- entry->prev = (void *) 0;
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
+}
+
+/**
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
+ *
+ * If @old was empty, it will be overwritten.
+ */
+static inline void list_replace(struct list_head *old,
+ struct list_head *new)
+{
+ new->next = old->next;
+ new->next->prev = new;
+ new->prev = old->prev;
+ new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+ struct list_head *new)
+{
+ list_replace(old, new);
+ INIT_LIST_HEAD(old);
}
/**
list_add_tail(list, head);
}
+/**
+ * list_is_last - tests whether @list is the last entry in list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_last(const struct list_head *list,
+ const struct list_head *head)
+{
+ return list->next == head;
+}
+
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
-static inline int list_empty(struct list_head *head)
+static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
-static inline void __list_splice(struct list_head *list,
- struct list_head *head)
+/**
+ * list_empty_careful - tests whether a list is empty and not being modified
+ * @head: the list to test
+ *
+ * Description:
+ * tests whether a list is empty _and_ checks that no other CPU might be
+ * in the process of modifying either member (next or prev)
+ *
+ * NOTE: using list_empty_careful() without synchronization
+ * can only be safe if the only activity that can happen
+ * to the list entry is list_del_init(). Eg. it cannot be used
+ * if another CPU could re-list_add() it.
+ */
+static inline int list_empty_careful(const struct list_head *head)
+{
+ struct list_head *next = head->next;
+ return (next == head) && (next == head->prev);
+}
+
+/**
+ * list_is_singular - tests whether a list has just one entry.
+ * @head: the list to test.
+ */
+static inline int list_is_singular(const struct list_head *head)
+{
+ return !list_empty(head) && (head->next == head->prev);
+}
+
+static inline void __list_cut_position(struct list_head *list,
+ struct list_head *head, struct list_head *entry)
+{
+ struct list_head *new_first = entry->next;
+ list->next = head->next;
+ list->next->prev = list;
+ list->prev = entry;
+ entry->next = list;
+ head->next = new_first;
+ new_first->prev = head;
+}
+
+/**
+ * list_cut_position - cut a list into two
+ * @list: a new list to add all removed entries
+ * @head: a list with entries
+ * @entry: an entry within head, could be the head itself
+ * and if so we won't cut the list
+ *
+ * This helper moves the initial part of @head, up to and
+ * including @entry, from @head to @list. You should
+ * pass on @entry an element you know is on @head. @list
+ * should be an empty list or a list you do not care about
+ * losing its data.
+ *
+ */
+static inline void list_cut_position(struct list_head *list,
+ struct list_head *head, struct list_head *entry)
+{
+ if (list_empty(head))
+ return;
+ if (list_is_singular(head) &&
+ (head->next != entry && head != entry))
+ return;
+ if (entry == head)
+ INIT_LIST_HEAD(list);
+ else
+ __list_cut_position(list, head, entry);
+}
+
+static inline void __list_splice(const struct list_head *list,
+ struct list_head *prev,
+ struct list_head *next)
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
- struct list_head *at = head->next;
- first->prev = head;
- head->next = first;
+ first->prev = prev;
+ prev->next = first;
- last->next = at;
- at->prev = last;
+ last->next = next;
+ next->prev = last;
}
/**
- * list_splice - join two lists
+ * list_splice - join two lists, this is designed for stacks
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
-static inline void list_splice(struct list_head *list, struct list_head *head)
+static inline void list_splice(const struct list_head *list,
+ struct list_head *head)
{
if (!list_empty(list))
- __list_splice(list, head);
+ __list_splice(list, head, head->next);
+}
+
+/**
+ * list_splice_tail - join two lists, each list being a queue
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+static inline void list_splice_tail(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list))
+ __list_splice(list, head->prev, head);
}
/**
struct list_head *head)
{
if (!list_empty(list)) {
- __list_splice(list, head);
+ __list_splice(list, head, head->next);
+ INIT_LIST_HEAD(list);
+ }
+}
+
+/**
+ * list_splice_tail_init - join two lists and reinitialise the emptied list
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ *
+ * Each of the lists is a queue.
+ * The list at @list is reinitialised
+ */
+static inline void list_splice_tail_init(struct list_head *list,
+ struct list_head *head)
+{
+ if (!list_empty(list)) {
+ __list_splice(list, head->prev, head);
INIT_LIST_HEAD(list);
}
}
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
- ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+ container_of(ptr, type, member)
+
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
/**
* list_for_each - iterate over a list
- * @pos: the &struct list_head to use as a loop counter.
+ * @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
- for (pos = (head)->next, prefetch(pos->next); pos != (head); \
- pos = pos->next, prefetch(pos->next))
+ for (pos = (head)->next; prefetch(pos->next), pos != (head); \
+ pos = pos->next)
+
+/**
+ * __list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ *
+ * This variant differs from list_for_each() in that it's the
+ * simplest possible list iteration code, no prefetching is done.
+ * Use this for code that knows the list to be very short (empty
+ * or 1 entry) most of the time.
+ */
+#define __list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
/**
* list_for_each_prev - iterate over a list backwards
- * @pos: the &struct list_head to use as a loop counter.
+ * @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
- for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
- pos = pos->prev, prefetch(pos->prev))
+ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
+ pos = pos->prev)
/**
- * list_for_each_safe - iterate over a list safe against removal of list entry
- * @pos: the &struct list_head to use as a loop counter.
+ * list_for_each_safe - iterate over a list safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
+/**
+ * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_prev_safe(pos, n, head) \
+ for (pos = (head)->prev, n = pos->prev; \
+ prefetch(pos->prev), pos != (head); \
+ pos = n, n = pos->prev)
+
/**
* list_for_each_entry - iterate over list of given type
- * @pos: the type * to use as a loop counter.
+ * @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- prefetch(pos->member.next); \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member), \
- prefetch(pos->member.next))
+ for (pos = list_entry((head)->next, typeof(*pos), member); \
+ prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_reverse(pos, head, member) \
+ for (pos = list_entry((head)->prev, typeof(*pos), member); \
+ prefetch(pos->member.prev), &pos->member != (head); \
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
+ * @pos: the type * to use as a start point
+ * @head: the head of the list
+ * @member: the name of the list_struct within the struct.
+ *
+ * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
+ */
+#define list_prepare_entry(pos, head, member) \
+ ((pos) ? : list_entry(head, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue - continue iteration over list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue(pos, head, member) \
+ for (pos = list_entry(pos->member.next, typeof(*pos), member); \
+ prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_continue_reverse - iterate backwards from the given point
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse(pos, head, member) \
+ for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
+ prefetch(pos->member.prev), &pos->member != (head); \
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_from - iterate over list of given type from the current point
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing from current position.
+ */
+#define list_for_each_entry_from(pos, head, member) \
+ for (; prefetch(pos->member.next), &pos->member != (head); \
+ pos = list_entry(pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @pos: the type * to use as a loop counter.
+ * @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/**
- * list_for_each_entry_continue - iterate over list of given type
- * continuing after existing point
- * @pos: the type * to use as a loop counter.
+ * list_for_each_entry_safe_continue
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type, continuing after current point,
+ * safe against removal of list entry.
+ */
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
+ for (pos = list_entry(pos->member.next, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_from
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate over list of given type from current point, safe against
+ * removal of list entry.
+ */
+#define list_for_each_entry_safe_from(pos, n, head, member) \
+ for (n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_for_each_entry_safe_reverse
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Iterate backwards over list of given type, safe against removal
+ * of list entry.
+ */
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_entry((head)->prev, typeof(*pos), member), \
+ n = list_entry(pos->member.prev, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+
+/*
+ * Double linked lists with a single pointer list head.
+ * Mostly useful for hash tables where the two pointer list head is
+ * too wasteful.
+ * You lose the ability to access the tail in O(1).
+ */
+
+struct hlist_head {
+ struct hlist_node *first;
+};
+
+struct hlist_node {
+ struct hlist_node *next, **pprev;
+};
+
+#define HLIST_HEAD_INIT { .first = NULL }
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+static inline void INIT_HLIST_NODE(struct hlist_node *h)
+{
+ h->next = NULL;
+ h->pprev = NULL;
+}
+
+static inline int hlist_unhashed(const struct hlist_node *h)
+{
+ return !h->pprev;
+}
+
+static inline int hlist_empty(const struct hlist_head *h)
+{
+ return !h->first;
+}
+
+static inline void __hlist_del(struct hlist_node *n)
+{
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+ *pprev = next;
+ if (next)
+ next->pprev = pprev;
+}
+
+static inline void hlist_del(struct hlist_node *n)
+{
+ __hlist_del(n);
+ n->next = LIST_POISON1;
+ n->pprev = LIST_POISON2;
+}
+
+static inline void hlist_del_init(struct hlist_node *n)
+{
+ if (!hlist_unhashed(n)) {
+ __hlist_del(n);
+ INIT_HLIST_NODE(n);
+ }
+}
+
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+ struct hlist_node *first = h->first;
+ n->next = first;
+ if (first)
+ first->pprev = &n->next;
+ h->first = n;
+ n->pprev = &h->first;
+}
+
+/* next must be != NULL */
+static inline void hlist_add_before(struct hlist_node *n,
+ struct hlist_node *next)
+{
+ n->pprev = next->pprev;
+ n->next = next;
+ next->pprev = &n->next;
+ *(n->pprev) = n;
+}
+
+static inline void hlist_add_after(struct hlist_node *n,
+ struct hlist_node *next)
+{
+ next->next = n->next;
+ n->next = next;
+ next->pprev = &n->next;
+
+ if(next->next)
+ next->next->pprev = &next->next;
+}
+
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
+
+#define hlist_for_each(pos, head) \
+ for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
+ pos = pos->next)
+
+#define hlist_for_each_safe(pos, n, head) \
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
+ pos = n)
+
+/**
+ * hlist_for_each_entry - iterate over list of given type
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry(tpos, pos, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ prefetch(pos->next); 1;}) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_continue(tpos, pos, member) \
+ for (pos = (pos)->next; \
+ pos && ({ prefetch(pos->next); 1;}) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_from - iterate over a hlist continuing from current point
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @member: the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry_from(tpos, pos, member) \
+ for (; pos && ({ prefetch(pos->next); 1;}) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = pos->next)
+
+/**
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @tpos: the type * to use as a loop cursor.
+ * @pos: the &struct hlist_node to use as a loop cursor.
+ * @n: another &struct hlist_node to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the hlist_node within the struct.
*/
-#define list_for_each_entry_continue(pos, head, member) \
- for (pos = list_entry(pos->member.next, typeof(*pos), member), \
- prefetch(pos->member.next); \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member), \
- prefetch(pos->member.next))
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ n = pos->next; 1; }) && \
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
+ pos = n)
#endif
--- /dev/null
+#ifndef _LINUX_POISON_H
+#define _LINUX_POISON_H
+
+/********** include/linux/list.h **********/
+/*
+ * used to verify that nobody uses non-initialized list entries.
+ */
+#define LIST_POISON1 ((void *) 0x0)
+#define LIST_POISON2 ((void *) 0x0)
+
+#endif
+++ /dev/null
-#ifndef _LISTS_H_
-#define _LISTS_H_
-
-#define LIST_START -1 /* Handy Constants that substitute for item positions */
-#define LIST_END 0 /* END_OF_LIST means one past current length of list when */
- /* inserting. Otherwise it refers the last item in the list. */
-
-typedef struct
- {
- void *ptr;
- unsigned int size;
- } HandleRecord;
-
-typedef void **Handle;
-
-typedef int (*CompareFunction)(void *data1, void *data2) ;
-
-typedef struct ListStructTag
- {
- int signature; /* debugging aid */
- int percentIncrease; /* %of current size to increase by when list is out of space */
- int minNumItemsIncrease; /* fixed number of items to increase by when list is out of space */
- int listSize; /* number of items than can fit in the currently allocated memory */
- int itemSize; /* the size of each item in the list (same for every item) */
- int numItems; /* number of items currently in the list */
- unsigned char itemList[1]; /* resizable array of list elements */
- } ListStruct;
-
-typedef struct ListStructTag **list_t; /* The list abstract data type */
-typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData);
-
-/* Basic List Operations */
-list_t ListCreate(int elementSize);
-int ListNumItems(list_t list);
-int ListInsertItem(list_t list, void *ptrToItem, int itemPosition);
-int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert);
-void ListDispose(list_t list);
-void *ListGetPtrToItem(list_t list, int itemPosition);
-void ListRemoveItem(list_t list, void *itemDestination, int itemPosition);
-void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove);
-
-#if 0 /* rarely ever used; kept here for reference just in case ... */
-void ListDisposePtrList(list_t list);
-void ListGetItem(list_t list, void *itemDestination, int itemPosition);
-void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition);
-void ListRemoveItem(list_t list, void *itemDestination, int itemPosition);
-void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet);
-void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace);
-void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove);
-list_t ListCopy(list_t originalList);
-int ListAppend(list_t list1, list_t list2);
-void ListClear(list_t list);
-int ListEqual(list_t list1, list_t list2);
-int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction);
-void *ListGetDataPtr(list_t list);
-int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData);
-
-/* List Searching and Sorting */
-int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction);
-void ListRemoveDuplicates(list_t list, CompareFunction compareFunction);
-int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction);
-void ListQuickSort(list_t list, CompareFunction compareFunction);
-void ListHeapSort(list_t list, CompareFunction compareFunction);
-void ListInsertionSort(list_t list, CompareFunction compareFunction);
-int ListIsSorted(list_t list, CompareFunction compareFunction);
-
-/* Advanced List Functions */
-void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc);
-void ListCompact(list_t list);
-int ListPreAllocate(list_t list, int numItems);
-int ListGetItemSize(list_t list);
-int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList);
-int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction);
-int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction);
-#endif /* 0 */
-
-#endif /* _LISTS_H_ */
COBJS-y += bzlib_decompress.o
COBJS-y += bzlib_randtable.o
COBJS-y += bzlib_huffman.o
+COBJS-y += crc16.o
COBJS-y += crc32.o
COBJS-y += ctype.o
COBJS-y += display_options.o
COBJS-y += div64.o
+COBJS-y += gunzip.o
COBJS-y += lmb.o
COBJS-y += ldiv.o
COBJS-$(CONFIG_MD5) += md5.o
--- /dev/null
+/*
+ *==========================================================================
+ *
+ * crc16.c
+ *
+ * 16 bit CRC with polynomial x^16+x^12+x^5+1
+ *
+ *==========================================================================
+ *####ECOSGPLCOPYRIGHTBEGIN####
+ * -------------------------------------------
+ * This file is part of eCos, the Embedded Configurable Operating System.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ * Copyright (C) 2002 Gary Thomas
+ *
+ * eCos 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 2 or (at your option) any later version.
+ *
+ * eCos 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 eCos; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * As a special exception, if other files instantiate templates or use macros
+ * or inline functions from this file, or you compile this file and link it
+ * with other works to produce a work based on this file, this file does not
+ * by itself cause the resulting work to be covered by the GNU General Public
+ * License. However the source code for this file must still be made available
+ * in accordance with section (3) of the GNU General Public License.
+ *
+ * This exception does not invalidate any other reasons why a work based on
+ * this file might be covered by the GNU General Public License.
+ *
+ * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+ * at http: *sources.redhat.com/ecos/ecos-license/
+ * -------------------------------------------
+ *####ECOSGPLCOPYRIGHTEND####
+ *==========================================================================
+ *#####DESCRIPTIONBEGIN####
+ *
+ * Author(s): gthomas
+ * Contributors: gthomas,asl
+ * Date: 2001-01-31
+ * Purpose:
+ * Description:
+ *
+ * This code is part of eCos (tm).
+ *
+ *####DESCRIPTIONEND####
+ *
+ *==========================================================================
+ */
+
+#include "crc.h"
+
+/* Table of CRC constants - implements x^16+x^12+x^5+1 */
+static const uint16_t crc16_tab[] = {
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+};
+
+uint16_t
+cyg_crc16(unsigned char *buf, int len)
+{
+ int i;
+ uint16_t cksum;
+
+ cksum = 0;
+ for (i = 0; i < len; i++) {
+ cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8);
+ }
+ return cksum;
+}
--- /dev/null
+/*
+ * (C) Copyright 2000-2006
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <command.h>
+#include <image.h>
+#include <malloc.h>
+#include <zlib.h>
+
+#define ZALLOC_ALIGNMENT 16
+#define HEAD_CRC 2
+#define EXTRA_FIELD 4
+#define ORIG_NAME 8
+#define COMMENT 0x10
+#define RESERVED 0xe0
+#define DEFLATED 8
+
+int gunzip(void *, int, unsigned char *, unsigned long *);
+void *zalloc(void *, unsigned, unsigned);
+void zfree(void *, void *, unsigned);
+
+void *zalloc(void *x, unsigned items, unsigned size)
+{
+ void *p;
+
+ size *= items;
+ size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
+
+ p = malloc (size);
+
+ return (p);
+}
+
+void zfree(void *x, void *addr, unsigned nb)
+{
+ free (addr);
+}
+
+int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+{
+ z_stream s;
+ int r, i, flags;
+
+ /* skip header */
+ i = 10;
+ flags = src[3];
+ if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
+ puts ("Error: Bad gzipped data\n");
+ return (-1);
+ }
+ if ((flags & EXTRA_FIELD) != 0)
+ i = 12 + src[10] + (src[11] << 8);
+ if ((flags & ORIG_NAME) != 0)
+ while (src[i++] != 0)
+ ;
+ if ((flags & COMMENT) != 0)
+ while (src[i++] != 0)
+ ;
+ if ((flags & HEAD_CRC) != 0)
+ i += 2;
+ if (i >= *lenp) {
+ puts ("Error: gunzip out of data in header\n");
+ return (-1);
+ }
+
+ s.zalloc = zalloc;
+ s.zfree = zfree;
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+ s.outcb = (cb_func)WATCHDOG_RESET;
+#else
+ s.outcb = Z_NULL;
+#endif /* CONFIG_HW_WATCHDOG */
+
+ r = inflateInit2(&s, -MAX_WBITS);
+ if (r != Z_OK) {
+ printf ("Error: inflateInit2() returned %d\n", r);
+ return (-1);
+ }
+ s.next_in = src + i;
+ s.avail_in = *lenp - i;
+ s.next_out = dst;
+ s.avail_out = dstlen;
+ r = inflate(&s, Z_FINISH);
+ if (r != Z_OK && r != Z_STREAM_END) {
+ printf ("Error: inflate() returned %d\n", r);
+ return (-1);
+ }
+ *lenp = s.next_out - (unsigned char *) dst;
+ inflateEnd(&s);
+
+ return (0);
+}