1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <g_dnl.h>
#ifdef CONFIG_FASTBOOT_STORAGE_NAND
#include <nand.h>
#endif
#include "bcb.h"
#ifndef CONFIG_FASTBOOT_STORAGE_NAND
int bcb_read_command(char *command)
{
int ret = 0;
char *p_block = NULL;
uint offset_in_block = 0;
uint blk_size = 0;
if (command == NULL)
return -1;
ret = bcb_rw_block(true, &p_block, &blk_size, NULL, MISC_COMMAND, 32);
if (ret) {
printf("read_bootctl, bcb_rw_block read failed\n");
return -1;
}
offset_in_block = MISC_COMMAND%blk_size;
memcpy(command, p_block + offset_in_block, 32);
free(p_block);
return 0;
}
int bcb_write_command(char *bcb_command)
{
int ret = 0;
char *p_block = NULL;
uint offset_in_block = 0;
uint blk_size = 0;
if (bcb_command == NULL)
return -1;
ret = bcb_rw_block(true, &p_block, &blk_size, NULL, MISC_COMMAND, 32);
if (ret) {
printf("write_bootctl, bcb_rw_block read failed\n");
return -1;
}
offset_in_block = MISC_COMMAND%blk_size;
memcpy(p_block + offset_in_block, bcb_command, 32);
ret = bcb_rw_block(false, NULL, NULL, p_block, MISC_COMMAND, 32);
if (ret) {
free(p_block);
printf("write_bootctl, bcb_rw_block write failed\n");
return -1;
}
free(p_block);
return 0;
}
#else
#define ALIGN_BYTES 64
#define MISC_PAGES 3
int bcb_read_command(char *command)
{
char read_cmd[128];
char *addr_str;
char *nand_str;
ulong misc_info_size;
nand_info_t *nand = &nand_info[0];
if (command == NULL)
return -1;
memset(read_cmd, 0, 128);
misc_info_size = MISC_PAGES * nand->writesize;
nand_str = (char *)memalign(ALIGN_BYTES, misc_info_size);
sprintf(read_cmd, "nand read 0x%x ${misc_nand_offset} \
0x%x", nand_str, misc_info_size);
run_command(read_cmd, 0);
/* The offset of bootloader_message is 1 PAGE.
* The offset of bootloader_message and the size of misc info
* need align with user space and recovery.
*/
addr_str = nand_str + nand->writesize;
memcpy(command, (char *)addr_str, 32);
free(nand_str);
return 0;
}
int bcb_write_command(char *command)
{
char cmd[128];
char *addr_str;
char *nand_str;
ulong misc_info_size;
nand_info_t *nand = &nand_info[0];
if (command == NULL)
return -1;
memset(cmd, 0, 128);
misc_info_size = MISC_PAGES * nand->writesize;
nand_str = (char *)memalign(ALIGN_BYTES, misc_info_size);
sprintf(cmd, "nand read 0x%x ${misc_nand_offset} \
0x%x", nand_str, misc_info_size);
run_command(cmd, 0);
/* the offset of bootloader_message is 1 PAGE*/
addr_str = nand_str + nand->writesize;
memcpy((char *)addr_str, command, 32);
/* erase 3 pages which hold BCB struct.*/
sprintf(cmd, "nand erase ${misc_nand_offset} 0x%x",nand->erasesize);
run_command(cmd, 0);
sprintf(cmd, "nand write 0x%x ${misc_nand_offset} 0x%x",nand_str, misc_info_size);
run_command(cmd, 0);
free(nand_str);
return 0;
}
#endif
|