-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmd_jffs2load.c
70 lines (58 loc) · 1.61 KB
/
cmd_jffs2load.c
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
/*
* Command for accessing SPI flash.
*
* Copyright (C) 2008 Atmel Corporation
* Licensed under the GPL-2 or later.
*/
#include <common.h>
#include <spi_flash.h>
#include <asm/io.h>
#ifndef CONFIG_SF_DEFAULT_SPEED
# define CONFIG_SF_DEFAULT_SPEED 1000000
#endif
#ifndef CONFIG_SF_DEFAULT_MODE
# define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
#endif
#ifndef CONFIG_SF_DEFAULT_CS
# define CONFIG_SF_DEFAULT_CS 0
#endif
#ifndef CONFIG_SF_DEFAULT_BUS
# define CONFIG_SF_DEFAULT_BUS 0
#endif
static struct spi_flash *flash;
flash_info_t flash_info[1];
static int flash_num = 0;
void* norflash_memory_map_init()
{
int ret = 1;
void *buf;
struct spi_flash *new;
new = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
if (!new) {
printf("Failed to initialize SPI flash at %u:%u\n", CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS);
return NULL;
}
if (flash)
spi_flash_free(flash);
flash = new;
flash_info[flash_num].size = flash->size;
flash_info[flash_num].sector_count = flash->size / flash->sector_size;
flash_info[flash_num].start[0] = 0;
/* flash memory map */
buf = map_physmem(CONFIG_START_VIRTUAL_ADDRESS, CONFIG_JFFS2_PART_SIZE, MAP_WRBACK);
if (!buf) {
puts("Failed to map physical memory\n");
return NULL;
}
ret = spi_flash_read(flash, CONFIG_JFFS2_PART_OFFSET, CONFIG_JFFS2_PART_SIZE, buf);
if (ret) {
printf("SF: spi_flash_read %s\n", ret ? "ERROR" : "OK");
return NULL;
}
flash_info[flash_num].start[0] = (unsigned long*)buf;
return buf;
}
void norflash_memory_map_deinit(void *buf)
{
unmap_physmem(buf, CONFIG_JFFS2_PART_SIZE);
}