int saveenv(void) { struct block_dev_desc_t *sata = NULL; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); printf("Writing to SATA(%d)... ", sata_curr_device); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) block_dev_desc_t *sata = NULL; char buf[CONFIG_ENV_SIZE]; int ret; if (sata_curr_device == -1) { if (sata_initialize()) return; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return; } sata = sata_get_dev(sata_curr_device); if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) return use_default(); ret = env_import(buf, 1); if (ret) gd->env_valid = 1; #endif }
void env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) struct block_dev_desc_t *sata = NULL; int i = 0; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr)) return use_default(); if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) return use_default(); gd->env_valid = 1; #endif }
static int env_sata_save(void) { ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); struct blk_desc *sata = NULL; int env_sata, ret; if (sata_initialize()) return 1; env_sata = sata_get_env_dev(); sata = sata_get_dev(env_sata); if (sata == NULL) { printf("Unknown SATA(%d) device for environment!\n", env_sata); return 1; } ret = env_export(env_new); if (ret) return 1; printf("Writing to SATA(%d)...", env_sata); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, &env_new)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
/* * now we can use a disk, and get the real environment. */ void env_relocate_spec(void) { #if defined(CONFIG_CMD_SATA) extern void sata_initialize(void); #endif block_dev_desc_t *dev_desc = NULL; int blksread; env_t env; char envbuf[CONFIG_ENV_SIZE]; env_t *envptr = (env_t *)envbuf; /* try to find the device. */ dev_desc = get_dev(CONFIG_SYS_DISK_ENV_INTERFACE, CONFIG_SYS_DISK_ENV_DEV); if (dev_desc == NULL) { printf("Cannot find device %s%d\n", CONFIG_SYS_DISK_ENV_INTERFACE, CONFIG_SYS_DISK_ENV_DEV); set_default_env(NULL); return; } /* at this point we have to init the device. no generic way to do it. */ #if defined(CONFIG_CMD_SATA) sata_initialize(); #else #error Disk env currently only implemented for sata devices #endif /* before sanity checking, see if the device is ready */ if ((dev_desc->blksz == 0) || (dev_desc->lba == 0) || (dev_desc->type == DEV_TYPE_UNKNOWN)) { printf("device %s %d is not available\n", CONFIG_SYS_DISK_ENV_INTERFACE, CONFIG_SYS_DISK_ENV_DEV); set_default_env(NULL); return; } /* some sanity checking, just in case. */ if (CONFIG_ENV_SIZE % dev_desc->blksz) { printf("Env size (%dK) is not a multiple of block size (%luK)\n", CONFIG_ENV_SIZE >> 10, dev_desc->blksz >> 10); set_default_env(NULL); return; }
int saveenv(void) { block_dev_desc_t *sata = NULL; env_t env_new; ssize_t len; char *res; if (sata_curr_device == -1) { if (sata_initialize()) return 1; sata_curr_device = CONFIG_SATA_ENV_DEV; } if (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE) { printf("Unknown SATA(%d) device for environment!\n", sata_curr_device); return 1; } sata = sata_get_dev(sata_curr_device); res = (char *)&env_new.data; len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); if (len < 0) { error("Cannot export environment: errno = %d\n", errno); return 1; } env_new.crc = crc32(0, env_new.data, ENV_SIZE); printf("Writing to SATA(%d)...", sata_curr_device); if (write_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, &env_new)) { puts("failed\n"); return 1; } puts("done\n"); return 0; }
int sata_probe(int devnum) { #ifdef CONFIG_AHCI struct udevice *dev; int rc; rc = uclass_get_device(UCLASS_AHCI, devnum, &dev); if (rc) rc = uclass_find_first_device(UCLASS_AHCI, &dev); if (rc) { printf("Cannot probe SATA device %d (err=%d)\n", devnum, rc); return CMD_RET_FAILURE; } rc = sata_scan(dev); if (rc) { printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc); return CMD_RET_FAILURE; } return 0; #else return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS; #endif }
static void env_sata_load(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *sata = NULL; int env_sata; if (sata_initialize()) return -EIO; env_sata = sata_get_env_dev(); sata = sata_get_dev(env_sata); if (sata == NULL) { printf("Unknown SATA(%d) device for environment!\n", env_sata); return -EIO; } if (read_env(sata, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) { set_default_env(NULL); return -EIO; } return env_import(buf, 1); }
static int splash_init_sata(void) { return sata_initialize(); }
static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int rc = 0; if (argc == 2 && strcmp(argv[1], "init") == 0) return sata_initialize(); /* If the user has not yet run `sata init`, do it now */ if (sata_curr_device == -1) if (sata_initialize()) return 1; switch (argc) { case 0: case 1: return CMD_RET_USAGE; case 2: if (strncmp(argv[1],"inf", 3) == 0) { int i; putc('\n'); for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; ++i) { if (sata_dev_desc[i].type == DEV_TYPE_UNKNOWN) continue; printf ("SATA device %d: ", i); dev_print(&sata_dev_desc[i]); } return 0; } else if (strncmp(argv[1],"dev", 3) == 0) { if ((sata_curr_device < 0) || (sata_curr_device >= CONFIG_SYS_SATA_MAX_DEVICE)) { puts("\nno SATA devices available\n"); return 1; } printf("\nSATA device %d: ", sata_curr_device); dev_print(&sata_dev_desc[sata_curr_device]); return 0; } else if (strncmp(argv[1],"part",4) == 0) { int dev, ok; for (ok = 0, dev = 0; dev < CONFIG_SYS_SATA_MAX_DEVICE; ++dev) { if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { ++ok; if (dev) putc ('\n'); print_part(&sata_dev_desc[dev]); } } if (!ok) { puts("\nno SATA devices available\n"); rc ++; } return rc; } return CMD_RET_USAGE; case 3: if (strncmp(argv[1], "dev", 3) == 0) { int dev = (int)simple_strtoul(argv[2], NULL, 10); printf("\nSATA device %d: ", dev); if (dev >= CONFIG_SYS_SATA_MAX_DEVICE) { puts ("unknown device\n"); return 1; } dev_print(&sata_dev_desc[dev]); if (sata_dev_desc[dev].type == DEV_TYPE_UNKNOWN) return 1; sata_curr_device = dev; puts("... is now current device\n"); return 0; } else if (strncmp(argv[1], "part", 4) == 0) { int dev = (int)simple_strtoul(argv[2], NULL, 10); if (sata_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { print_part(&sata_dev_desc[dev]); } else { printf("\nSATA device %d not available\n", dev); rc = 1; } return rc; } return CMD_RET_USAGE; default: /* at least 4 args */ if (strcmp(argv[1], "read") == 0) { ulong addr = simple_strtoul(argv[2], NULL, 16); ulong cnt = simple_strtoul(argv[4], NULL, 16); ulong n; lbaint_t blk = simple_strtoul(argv[3], NULL, 16); printf("\nSATA read: device %d block # %ld, count %ld ... ", sata_curr_device, blk, cnt); n = sata_read(sata_curr_device, blk, cnt, (u32 *)addr); /* flush cache after read */ flush_cache(addr, cnt * sata_dev_desc[sata_curr_device].blksz); printf("%ld blocks read: %s\n", n, (n==cnt) ? "OK" : "ERROR"); return (n == cnt) ? 0 : 1; } else if (strcmp(argv[1], "write") == 0) { ulong addr = simple_strtoul(argv[2], NULL, 16); ulong cnt = simple_strtoul(argv[4], NULL, 16); ulong n; lbaint_t blk = simple_strtoul(argv[3], NULL, 16); printf("\nSATA write: device %d block # %ld, count %ld ... ", sata_curr_device, blk, cnt); n = sata_write(sata_curr_device, blk, cnt, (u32 *)addr); printf("%ld blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); return (n == cnt) ? 0 : 1; } else { return CMD_RET_USAGE; } return rc; } }