Blame view
env/sata.c
2.83 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
125d193c4 common: env: supp... |
2 3 |
/* * (C) Copyright 2010-2016 Freescale Semiconductor, Inc. |
125d193c4 common: env: supp... |
4 5 6 7 8 9 10 11 12 13 14 15 16 |
*/ /* #define DEBUG */ #include <common.h> #include <command.h> #include <environment.h> #include <linux/stddef.h> #include <errno.h> #include <memalign.h> #include <sata.h> #include <search.h> |
097bf5dcf MLK-22293-5 env: ... |
17 18 19 |
#ifdef CONFIG_DM_SCSI #include <scsi.h> #endif |
125d193c4 common: env: supp... |
20 21 22 23 24 25 26 27 |
#if defined(CONFIG_ENV_SIZE_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) #error ENV REDUND not supported #endif #if !defined(CONFIG_ENV_OFFSET) || !defined(CONFIG_ENV_SIZE) #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined #endif |
125d193c4 common: env: supp... |
28 29 30 31 |
__weak int sata_get_env_dev(void) { return CONFIG_SYS_SATA_ENV_DEV; } |
125d193c4 common: env: supp... |
32 33 34 35 36 37 38 39 40 41 42 43 44 |
#ifdef CONFIG_CMD_SAVEENV static inline int write_env(struct blk_desc *sata, unsigned long size, unsigned long offset, void *buffer) { uint blk_start, blk_cnt, n; blk_start = ALIGN(offset, sata->blksz) / sata->blksz; blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; n = blk_dwrite(sata, blk_start, blk_cnt, buffer); return (n == blk_cnt) ? 0 : -1; } |
e5bce247b env: Switch over ... |
45 |
static int env_sata_save(void) |
125d193c4 common: env: supp... |
46 47 48 49 |
{ ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); struct blk_desc *sata = NULL; int env_sata, ret; |
097bf5dcf MLK-22293-5 env: ... |
50 |
#ifndef CONFIG_DM_SCSI |
125d193c4 common: env: supp... |
51 52 53 54 55 56 |
if (sata_initialize()) return 1; env_sata = sata_get_env_dev(); sata = sata_get_dev(env_sata); |
097bf5dcf MLK-22293-5 env: ... |
57 58 59 60 61 62 |
#else scsi_scan(false); env_sata = sata_get_env_dev(); sata = blk_get_dev("scsi", env_sata); #endif |
125d193c4 common: env: supp... |
63 64 65 66 67 68 69 70 71 72 73 74 |
if (sata == NULL) { printf("Unknown SATA(%d) device for environment! ", env_sata); return 1; } ret = env_export(env_new); if (ret) return 1; printf("Writing to SATA(%d)...", env_sata); |
565d9002a MLK-22279-1 env: ... |
75 |
if (write_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), (u_char *)env_new)) { |
125d193c4 common: env: supp... |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
puts("failed "); return 1; } puts("done "); return 0; } #endif /* CONFIG_CMD_SAVEENV */ static inline int read_env(struct blk_desc *sata, unsigned long size, unsigned long offset, void *buffer) { uint blk_start, blk_cnt, n; blk_start = ALIGN(offset, sata->blksz) / sata->blksz; blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; n = blk_dread(sata, blk_start, blk_cnt, buffer); return (n == blk_cnt) ? 0 : -1; } |
ffdc4c02e MLK-18141-1 env: ... |
99 |
static int env_sata_load(void) |
125d193c4 common: env: supp... |
100 101 102 103 |
{ ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *sata = NULL; int env_sata; |
097bf5dcf MLK-22293-5 env: ... |
104 |
#ifndef CONFIG_DM_SCSI |
125d193c4 common: env: supp... |
105 |
if (sata_initialize()) |
c59519919 env: Adjust the l... |
106 |
return -EIO; |
125d193c4 common: env: supp... |
107 108 109 110 |
env_sata = sata_get_env_dev(); sata = sata_get_dev(env_sata); |
097bf5dcf MLK-22293-5 env: ... |
111 112 113 114 115 116 |
#else scsi_scan(false); env_sata = sata_get_env_dev(); sata = blk_get_dev("scsi", env_sata); #endif |
125d193c4 common: env: supp... |
117 |
if (sata == NULL) { |
c59519919 env: Adjust the l... |
118 119 120 |
printf("Unknown SATA(%d) device for environment! ", env_sata); return -EIO; |
125d193c4 common: env: supp... |
121 |
} |
565d9002a MLK-22279-1 env: ... |
122 |
if (read_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), buf)) { |
c5d548a9f env: common: acce... |
123 |
set_default_env(NULL, 0); |
c59519919 env: Adjust the l... |
124 125 |
return -EIO; } |
125d193c4 common: env: supp... |
126 |
|
2166ebf78 env: make env dri... |
127 |
return env_import(buf, 1); |
125d193c4 common: env: supp... |
128 |
} |
4415f1d1f env: Create a loc... |
129 130 131 |
U_BOOT_ENV_LOCATION(sata) = { .location = ENVL_ESATA, |
ac358beb8 env: Drop the env... |
132 |
ENV_NAME("SATA") |
e5bce247b env: Switch over ... |
133 134 |
.load = env_sata_load, .save = env_save_ptr(env_sata_save), |
4415f1d1f env: Create a loc... |
135 |
}; |