• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014-2016, Armink, <armink.ztl@gmail.com>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * 'Software'), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Function: Initialize interface for this library.
24  * Created on: 2014-09-09
25  */
26 
27 /**
28  *
29  * This all Backup Area Flash storage index. All used flash area configure is under here.
30  * |----------------------------|   Storage Size
31  * | Environment variables area |   ENV area size @see ENV_AREA_SIZE
32  * |      1.system section      |   ENV system section size
33  * |      2:data section        |   ENV_AREA_SIZE - ENV system section size
34  * |----------------------------|
35  * |      Saved log area        |   Log area size @see LOG_AREA_SIZE
36  * |----------------------------|
37  * |(IAP)Downloaded application |   IAP already downloaded application, unfixed size
38  * |----------------------------|
39  *
40  * @note all area size must be aligned with EF_ERASE_MIN_SIZE
41  * @note EasyFlash will use ram to buffered the ENV. At some time flash's EF_ERASE_MIN_SIZE is so big,
42  *       and you want use ENV size is less than it. So you must defined ENV_USER_SETTING_SIZE for ENV.
43  * @note ENV area size has some limitations in different modes.
44  *       1.Normal mode: no more limitations
45  *       2.Wear leveling mode: system section will used an flash section and the data section will used at least 2 flash sections
46  *       3.Power fail safeguard mode: ENV area will has an backup. It is twice as normal mode.
47  *       4.wear leveling and power fail safeguard mode: The required capacity will be 2 times the total capacity in wear leveling mode.
48  *       For example:
49  *       The EF_ERASE_MIN_SIZE is 128K and the ENV_USER_SETTING_SIZE: 2K. The ENV_AREA_SIZE in different mode you can define
50  *       1.Normal mode: 1*EF_ERASE_MIN_SIZE
51  *       2.Wear leveling mode: 3*EF_ERASE_MIN_SIZE (It has 2 data section to store ENV. So ENV can erase at least 200,000 times)
52  *       3.Power fail safeguard mode: 2*EF_ERASE_MIN_SIZE
53  *       4.Wear leveling and power fail safeguard mode: 6*EF_ERASE_MIN_SIZE
54  * @note the log area size must be more than twice of EF_ERASE_MIN_SIZE
55  */
56 #include <easyflash.h>
57 
58 /**
59  * EasyFlash system initialize.
60  *
61  * @return result
62  */
easyflash_init(void)63 EfErrCode easyflash_init(void)
64 {
65 	extern EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size);
66 	extern EfErrCode ef_env_init(ef_env const * default_env, size_t default_env_size);
67 	extern EfErrCode ef_iap_init(void);
68 	extern EfErrCode ef_log_init(void);
69 
70 	size_t default_env_set_size = 0;
71 	const ef_env *default_env_set;
72 	EfErrCode result = EF_NO_ERR;
73 
74 	result = ef_port_init(&default_env_set, &default_env_set_size);
75 
76 #ifdef EF_USING_ENV
77 	if (result == EF_NO_ERR)
78 		result = ef_env_init(default_env_set, default_env_set_size);
79 #endif
80 
81 #ifdef EF_USING_IAP
82 	if (result == EF_NO_ERR)
83 		result = ef_iap_init();
84 #endif
85 
86 #ifdef EF_USING_LOG
87 	if (result == EF_NO_ERR)
88 		result = ef_log_init();
89 #endif
90 
91 	if (result == EF_NO_ERR)
92 		EF_INFO("EasyFlash V%s is initialize success.\n", EF_SW_VERSION);
93 	else
94 		EF_INFO("EasyFlash V%s is initialize fail.\n", EF_SW_VERSION);
95 	EF_INFO("You can get the latest version on https://github.com/armink/EasyFlash .\n");
96 
97 	return result;
98 }
99 // eof
100 
101