Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
6cd3111d
Commit
6cd3111d
authored
Sep 22, 2016
by
Johny Mattsson
Browse files
Platform interface to flash partition info.
parent
8e23335c
Changes
2
Show whitespace changes
Inline
Side-by-side
components/platform/include/platform.h
View file @
6cd3111d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#define _PLATFORM_H_
#define _PLATFORM_H_
#include <stdint.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "sdkconfig.h"
#include "cpu_esp32.h"
#include "cpu_esp32.h"
...
@@ -17,8 +18,21 @@ enum
...
@@ -17,8 +18,21 @@ enum
PLATFORM_UNDERFLOW
=
-
1
PLATFORM_UNDERFLOW
=
-
1
};
};
int
platform_init
(
void
);
#if CONFIG_NODE_DEBUG
# define NODE_DBG printf
#else
# define NODE_DBG(...) do{}while(0)
#endif
#if CONFIG_NODE_ERR
# define NODE_ERR printf
#else
# define NODE_ERR(...) do{}while(0)
#endif
int
platform_init
(
void
);
// *****************************************************************************
// *****************************************************************************
// UART subsection
// UART subsection
...
@@ -54,7 +68,6 @@ void platform_uart_send( unsigned id, uint8_t data );
...
@@ -54,7 +68,6 @@ void platform_uart_send( unsigned id, uint8_t data );
int
platform_uart_set_flow_control
(
unsigned
id
,
int
type
);
int
platform_uart_set_flow_control
(
unsigned
id
,
int
type
);
// Internal flash erase/write functions
// Internal flash erase/write functions
uint32_t
platform_flash_get_first_free_block_address
(
uint32_t
*
psect
);
uint32_t
platform_flash_get_first_free_block_address
(
uint32_t
*
psect
);
...
@@ -76,17 +89,25 @@ int platform_flash_erase_sector( uint32_t sector_id );
...
@@ -76,17 +89,25 @@ int platform_flash_erase_sector( uint32_t sector_id );
*/
*/
uint32_t
platform_flash_mapped2phys
(
uint32_t
mapped_addr
);
uint32_t
platform_flash_mapped2phys
(
uint32_t
mapped_addr
);
#if CONFIG_NODE_DEBUG
# define NODE_DBG printf
#else
# define NODE_DBG(...) do{}while(0)
#endif
#if CONFIG_NODE_ERR
// Internal flash partitions
# define NODE_ERR printf
typedef
struct
{
#else
uint8_t
label
[
16
];
# define NODE_ERR(...) do{}while(0)
uint32_t
offs
;
#endif
uint32_t
size
;
uint8_t
type
;
uint8_t
subtype
;
}
platform_partition_t
;
/**
* Obtain partition information for the internal flash.
* @param idx Which partition index to load info for.
* @param info Buffer to store the info in.
* @returns True if the partition info was loaded, false if not (e.g. no such
* partition idx).
*/
bool
platform_partition_info
(
uint8_t
idx
,
platform_partition_t
*
info
);
// *****************************************************************************
// *****************************************************************************
...
...
components/platform/platform_partition.c
0 → 100644
View file @
6cd3111d
/*
* Copyright 2016 Dius Computing Pty Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* - Neither the name of the copyright holders nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Johny Mattsson <jmattsson@dius.com.au>
*/
#include "platform.h"
#include <string.h>
#include "../../bootloader/src/main/bootloader_config.h"
#include "esp_spi_flash.h"
static
inline
bool
possible_idx
(
uint8_t
idx
)
{
return
((
idx
+
1
)
*
sizeof
(
partition_info_t
))
<
SPI_FLASH_SEC_SIZE
;
}
bool
platform_partition_info
(
uint8_t
idx
,
platform_partition_t
*
info
)
{
if
(
!
possible_idx
(
idx
))
return
false
;
partition_info_t
pi
;
esp_err_t
err
=
spi_flash_read
(
PARTITION_ADD
+
idx
*
sizeof
(
pi
),
(
uint32_t
*
)
&
pi
,
sizeof
(
pi
));
if
(
err
!=
ESP_OK
)
return
false
;
if
(
pi
.
magic
!=
PARTITION_MAGIC
)
return
false
;
memcpy
(
info
->
label
,
pi
.
label
,
sizeof
(
info
->
label
));
info
->
offs
=
pi
.
pos
.
offset
;
info
->
size
=
pi
.
pos
.
size
;
info
->
type
=
pi
.
type
;
info
->
subtype
=
pi
.
subtype
;
return
true
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment