99
99
static int orion_nand_fast_block_write(struct nand_device_s *device, uint8_t *data, int size)
101
101
orion_nand_controller_t *hw = device->controller_priv;
102
target_t *target = hw->target;
103
armv4_5_algorithm_t algo;
104
reg_param_t reg_params[3];
108
static const uint32_t code[] = {
109
0xe4d13001, /* ldrb r3, [r1], #1 */
110
0xe5c03000, /* strb r3, [r0] */
111
0xe2522001, /* subs r2, r2, #1 */
112
0x1afffffb, /* bne 0 */
113
0xeafffffe, /* b . */
115
int code_size = sizeof(code);
117
if (!hw->copy_area) {
118
uint8_t code_buf[code_size];
121
/* make sure we have a working area */
122
if (target_alloc_working_area(target,
123
code_size + device->page_size,
124
&hw->copy_area) != ERROR_OK)
126
return orion_nand_slow_block_write(device, data, size);
129
/* copy target instructions to target endianness */
130
for (i = 0; i < code_size/4; i++)
131
target_buffer_set_u32(target, code_buf + i*4, code[i]);
133
/* write code to working area */
134
retval = target_write_memory(target,
135
hw->copy_area->address,
136
4, code_size/4, code_buf);
137
if (retval != ERROR_OK)
141
/* copy data to target's memory */
142
target_buf = hw->copy_area->address + code_size;
143
retval = target_bulk_write_memory(target, target_buf, size/4, data);
144
if (retval == ERROR_OK && size & 3) {
145
retval = target_write_memory(target,
146
target_buf + (size & ~3),
147
1, size & 3, data + (size & ~3));
149
if (retval != ERROR_OK)
152
algo.common_magic = ARMV4_5_COMMON_MAGIC;
153
algo.core_mode = ARMV4_5_MODE_SVC;
154
algo.core_state = ARMV4_5_STATE_ARM;
156
init_reg_param(®_params[0], "r0", 32, PARAM_IN);
157
init_reg_param(®_params[1], "r1", 32, PARAM_IN);
158
init_reg_param(®_params[2], "r2", 32, PARAM_IN);
160
buf_set_u32(reg_params[0].value, 0, 32, hw->data);
161
buf_set_u32(reg_params[1].value, 0, 32, target_buf);
162
buf_set_u32(reg_params[2].value, 0, 32, size);
164
retval = target_run_algorithm(target, 0, NULL, 3, reg_params,
165
hw->copy_area->address,
166
hw->copy_area->address + code_size - 4,
168
if (retval != ERROR_OK)
169
LOG_ERROR("error executing hosted NAND write");
171
destroy_reg_param(®_params[0]);
172
destroy_reg_param(®_params[1]);
173
destroy_reg_param(®_params[2]);
104
hw->io.chunk_size = device->page_size;
106
retval = arm_nandwrite(&hw->io, data, size);
107
if (retval == ERROR_NAND_NO_BUFFER)
108
retval = orion_nand_slow_block_write(device, data, size);