2012-09-04 11:05:27 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 Travis Geiselbrecht
|
|
|
|
|
*
|
2019-07-05 17:22:23 -07:00
|
|
|
* Use of this source code is governed by a MIT-style
|
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
|
* https://opensource.org/licenses/MIT
|
2012-09-04 11:05:27 -07:00
|
|
|
*/
|
2019-06-17 18:28:51 -07:00
|
|
|
#include <lk/debug.h>
|
|
|
|
|
#include <lk/trace.h>
|
|
|
|
|
#include <lk/err.h>
|
2012-09-04 11:05:27 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <kernel/thread.h>
|
|
|
|
|
#include <platform.h>
|
2021-10-21 23:18:09 -07:00
|
|
|
#include <platform/stm32.h>
|
2012-09-04 11:05:27 -07:00
|
|
|
#include <dev/flash_nor.h>
|
|
|
|
|
#include <stm32f10x_rcc.h>
|
|
|
|
|
#include <stm32f10x_flash.h>
|
|
|
|
|
#include <misc.h>
|
|
|
|
|
|
|
|
|
|
/* flash size and page size determined dynamically */
|
|
|
|
|
#define FLASH_SIZE ((*(REG16(0x1FFFF7E0))) * (size_t)1024)
|
|
|
|
|
#define FLASH_PAGE_SIZE ((size_t)((FLASH_SIZE > 131072) ? 2048 : 1024))
|
|
|
|
|
|
|
|
|
|
struct flash_nor_bank flash[1];
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
void stm32_flash_nor_early_init(void) {
|
2016-02-14 12:24:01 -08:00
|
|
|
FLASH_Lock(); // make sure it's locked
|
2012-09-04 11:05:27 -07:00
|
|
|
|
2016-02-14 12:24:01 -08:00
|
|
|
flash[0].base = 0x08000000;
|
|
|
|
|
flash[0].len = FLASH_SIZE;
|
|
|
|
|
flash[0].page_size = FLASH_PAGE_SIZE;
|
|
|
|
|
flash[0].flags = 0;
|
2012-09-04 11:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
void stm32_flash_nor_init(void) {
|
2016-02-14 12:24:01 -08:00
|
|
|
TRACEF("flash size %zu\n", FLASH_SIZE);
|
|
|
|
|
TRACEF("page size %zu\n", FLASH_PAGE_SIZE);
|
2012-09-04 11:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
const struct flash_nor_bank *flash_nor_get_bank(unsigned int bank) {
|
2016-02-14 12:24:01 -08:00
|
|
|
if (bank != 0)
|
|
|
|
|
return NULL;
|
2012-09-04 11:05:27 -07:00
|
|
|
|
2016-02-14 12:24:01 -08:00
|
|
|
return &flash[0];
|
2012-09-04 11:05:27 -07:00
|
|
|
}
|
|
|
|
|
|