summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2020-07-19 16:58:40 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-16 10:00:31 +0000
commitc5f38f5cae150f82803c669c639a48960bfbb809 (patch)
treed5738e4de43afe65cb344a6b8db7327ff5d2b71f
parent8aecb453fcb26a406d121389c854fa29056f5664 (diff)
downloadchrome-ec-c5f38f5cae150f82803c669c639a48960bfbb809.tar.gz
bmi260: move BMI260 init file into .init.rom section
Increases Volteer RO and RW flash spaces by 7088 bytes each. This is the net gain after including the init_rom layer. BUG=b:160330682 BRANCH=none TEST=make buildall TEST=On volteer run "ectool motionsense" and "ectool motionsense lid_angle". Verify both RO and RW images. TEST=Program RO image with predecessor CL:2311268. Program this CL into AP firmware image and verify EC software sync updates to RW image. TEST=Verify BMI260 operation with CONFIG_CHIP_INIT_ROM_REGION disabled using volteer_tcpmv1 board. Conflicts: board/eldrid/board.h: eldrid not in branch. board/volteer/board.h: sensors were not enabled. third_party/bmi260/accelgyro_bmi260_config_tbin.h: branch does not have e0bf946ced: rom resident section. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I6849b6c9e96756266528b39ab5e53268dce2a13c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2311756 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org> (cherry picked from commit 06f584a8b508e881680c222498702f5148330a3f) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3214009 Tested-by: Rong Chang <rongchang@chromium.org> Auto-Submit: Rong Chang <rongchang@chromium.org> Commit-Queue: Rong Chang <rongchang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3631909 Tested-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Reviewed-by: Henry Sun <henrysun@google.com> Commit-Queue: Henry Sun <henrysun@google.com>
-rw-r--r--driver/accelgyro_bmi260.c76
-rw-r--r--third_party/bmi260/accelgyro_bmi260_config_tbin.h6
2 files changed, 67 insertions, 15 deletions
diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c
index f5bf1dd1cf..4fc1b4dbda 100644
--- a/driver/accelgyro_bmi260.c
+++ b/driver/accelgyro_bmi260.c
@@ -15,6 +15,7 @@
#include "endian.h"
#include "hwtimer.h"
#include "i2c.h"
+#include "init_rom.h"
#include "math_util.h"
#include "spi.h"
#include "task.h"
@@ -375,6 +376,15 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
}
#endif /* CONFIG_ACCEL_INTERRUPTS */
+#if defined(CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG) || \
+ defined(CONFIG_CHIP_INIT_ROM_REGION)
+#define BMI_RAM_BUFFER_SIZE 256
+static uint8_t bmi_ram_buffer[BMI_RAM_BUFFER_SIZE];
+#else
+#define BMI_RAM_BUFFER_SIZE 0
+static uint8_t *bmi_ram_buffer;
+#endif
+
/*
* TODO(b/160330682): Eliminate or reduce size of BMI260 initialization file.
* Remove this option once the BMI260 initialization file is moved to the
@@ -389,8 +399,6 @@ INCBIN(bmi260_config,
"third_party/bmi260/accelgyro_bmi260_config_compressed.bin");
#define COMPRESS_KEY 0xE9EA
-#define BMI_BUFFER_SIZE 256
-static uint8_t bmi_buffer[BMI_BUFFER_SIZE];
static int bmi_buffer_bytes;
static int bmi_config_offset;
@@ -429,10 +437,10 @@ static int enqueue_bmi_data(const struct motion_sensor_t *s, uint32_t *data)
{
int ret;
- memcpy(&bmi_buffer[bmi_buffer_bytes], data, 4);
+ memcpy(&bmi_ram_buffer[bmi_buffer_bytes], data, 4);
bmi_buffer_bytes += 4;
- if (bmi_buffer_bytes >= BMI_BUFFER_SIZE) {
+ if (bmi_buffer_bytes >= BMI_RAM_BUFFER_SIZE) {
ret = write_bmi_data(s);
if (ret)
return ret;
@@ -536,16 +544,33 @@ static int bmi_compressed_config_load(const struct motion_sensor_t *s)
static int bmi_config_load(const struct motion_sensor_t *s)
{
- int ret;
+ int ret = EC_SUCCESS;
uint16_t i;
-
+ const uint8_t *bmi_config = NULL;
/*
* Due to i2c transaction timeout limit,
* burst_write_len should not be above 2048 to prevent timeout.
*/
- const int burst_write_len = 2048;
+ int burst_write_len = 2048;
+
+ /*
+ * The BMI config data may be linked into .rodata or the .init_rom
+ * section. Get the actual memory mapped address.
+ */
+ bmi_config = init_rom_map(g_bmi260_config_tbin,
+ g_bmi260_config_tbin_len);
+
+ /*
+ * init_rom_map() only returns NULL when the CONFIG_CHIP_INIT_ROM_REGION
+ * option is enabled and flash memory is not memory mapped. In this
+ * case copy the BMI config data through a RAM buffer and limit the
+ * I2C burst to the size of the RAM buffer.
+ */
+ if (!bmi_config)
+ burst_write_len = MIN(BMI_RAM_BUFFER_SIZE, burst_write_len);
+
/* We have to write the config even bytes of data every time */
- BUILD_ASSERT((burst_write_len & 1) == 0);
+ ASSERT(((burst_write_len & 1) == 0) && (burst_write_len != 0));
for (i = 0; i < g_bmi260_config_tbin_len; i += burst_write_len) {
uint8_t addr[2];
@@ -558,15 +583,38 @@ static int bmi_config_load(const struct motion_sensor_t *s)
BMI260_INIT_ADDR_0, addr, 2);
if (ret)
break;
- ret = bmi_write_n(s->port, s->addr,
- BMI260_INIT_DATA, &g_bmi260_config_tbin[i],
- len);
+
+ if (!bmi_config) {
+ /*
+ * init_rom region isn't memory mapped. Copy the
+ * data through a RAM buffer.
+ */
+ ret = init_rom_copy((int)&g_bmi260_config_tbin[i], len,
+ bmi_ram_buffer);
+ if (ret)
+ break;
+
+ ret = bmi_write_n(s->port, s->addr,
+ BMI260_INIT_DATA,
+ bmi_ram_buffer, len);
+ } else {
+ ret = bmi_write_n(s->port, s->addr,
+ BMI260_INIT_DATA,
+ &bmi_config[i], len);
+ }
+
if (ret)
- return ret;
-;
+ break;
}
- return EC_SUCCESS;
+ /*
+ * Unmap the BMI config data, required when init_rom_map() returns
+ * a non NULL value.
+ */
+ if (bmi_config)
+ init_rom_unmap(g_bmi260_config_tbin, g_bmi260_config_tbin_len);
+
+ return ret;
}
#endif /* CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG */
diff --git a/third_party/bmi260/accelgyro_bmi260_config_tbin.h b/third_party/bmi260/accelgyro_bmi260_config_tbin.h
index f55f399f5c..5ba8e020d0 100644
--- a/third_party/bmi260/accelgyro_bmi260_config_tbin.h
+++ b/third_party/bmi260/accelgyro_bmi260_config_tbin.h
@@ -12,7 +12,11 @@
#include "common.h"
-const unsigned char g_bmi260_config_tbin[] = {
+#ifndef __init_rom
+#define __init_rom
+#endif
+
+const unsigned char __init_rom g_bmi260_config_tbin[] = {
0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x63, 0xb3, 0xc8, 0x2e, 0x00, 0x2e,
0x80, 0x2e, 0x15, 0x03, 0x80, 0x2e, 0xbb, 0xb4, 0x80, 0x2e, 0x91, 0x03,
0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0xe7, 0xb3, 0x50, 0x30, 0x21, 0x2e,