199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt,##args); } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Some random address used by U-Boot. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Clear the checksum field (in the local copy) so as to calculate the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CRC with the same initial contents as at the time when the sig was
199767f8919635c4928607450d9e0abb932109ceToomas Soome checksum = crc32((void *)&s, sizeof(struct api_signature));
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Searches for the U-Boot API signature
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returns 1/0 depending on found/not found result
199767f8919635c4928607450d9e0abb932109ceToomas Soome sp = (void *)(uboot_address & API_SIG_SEARCH_MASK);
199767f8919635c4928607450d9e0abb932109ceToomas Soome spend = sp + API_SIG_SEARCH_LEN - API_SIG_MAGLEN;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!bcmp(sp, API_SIG_MAGIC, API_SIG_MAGLEN)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome/****************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome ****************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/****************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome ****************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome/****************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome ****************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soomeunsigned long
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!syscall(API_GET_TIMER, NULL, &cur, &base))
199767f8919635c4928607450d9e0abb932109ceToomas Soome/****************************************************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Devices are identified by handles: numbers 0, 1, 2, ..., UB_MAX_DEV-1
199767f8919635c4928607450d9e0abb932109ceToomas Soome ***************************************************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((i < 0 || i >= UB_MAX_DEV) ? NULL : &devices[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Enumerates the devices: fills out device_info elements in the devices[]
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returns: number of devices found
199767f8919635c4928607450d9e0abb932109ceToomas Soome memset(&devices, 0, sizeof(struct device_info) * UB_MAX_DEV);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* take another device_info */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* pass on the previous cookie */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * handle: 0-based id of the device
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returns: 0 when OK, err otherwise
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Validates device for read/write, it has to:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - have sane handle
199767f8919635c4928607450d9e0abb932109ceToomas Soome * - be opened
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returns: 0/1 accordingly
199767f8919635c4928607450d9e0abb932109ceToomas Soomeub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start,
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!syscall(API_DEV_READ, &err, di, buf, &len, &start, &act_len))
199767f8919635c4928607450d9e0abb932109ceToomas Soomeub_dev_recv(int handle, void *buf, int len, int *rlen)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!syscall(API_DEV_READ, &err, di, buf, &len, &act_len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!syscall(API_DEV_WRITE, &err, di, buf, &len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("IDE");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("SCSI");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("USB");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("MMC");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("SATA");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("Unknown");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("FLASH");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("DRAM");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("SRAM");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ("Unknown");
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < 6; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" type\t\t= %s\n", ub_stor_type(di->type));
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" blk size\t\t= %ld\n", di->di_stor.block_size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" blk count\t\t= %ld\n", di->di_stor.block_count);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" clkbus\t= %ld MHz\n", si->clk_bus / 1000 / 1000);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" clkcpu\t= %ld MHz\n", si->clk_cpu / 1000 / 1000);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" start\t= 0x%08lx\n", si->mr[i].start);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" type\t= %s\n", ub_mem_type(si->mr[i].flags));
199767f8919635c4928607450d9e0abb932109ceToomas Soome/****************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome ****************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It's OK to pass only the name piece as last (and not the whole
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 'name=val' string), since the API_ENUM_ENV call uses envmatch()
199767f8919635c4928607450d9e0abb932109ceToomas Soome * internally, which handles such case
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* no more env. variables to enumerate */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* next enumerated env var */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0, str = env; *str != '=' && *str != '\0';)