diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index f615a00c2b..e930346032 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -471,7 +471,7 @@ env.Replace(
'-fstack-protector-all '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
- LINKFLAGS=['-Tbuild/firmware/memory.ld', '-Wl,--gc-sections', '-Wl,--print-memory-usage', '-Wl,-Map=build/firmware/firmware.map', '-Wl,--warn-common'],
+ LINKFLAGS=[f'-Tbuild/firmware/{env.get("ENV")["MEMORY_LAYOUT"]}', '-Wl,--gc-sections', '-Wl,--print-memory-usage', '-Wl,-Map=build/firmware/firmware.map', '-Wl,--warn-common'],
CPPPATH=ALLPATHS,
CPPDEFINES=[
'FIRMWARE',
@@ -877,8 +877,8 @@ tools.embed_raw_binary(
env.Depends(obj_program, qstr_generated)
linkerscript_gen = env.Command(
- target='memory.ld',
- source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
+ target=env.get("ENV")["MEMORY_LAYOUT"],
+ source=[f'embed/models/{TREZOR_MODEL}/{env.get("ENV")["MEMORY_LAYOUT"]}', env.get('ENV')['LINKER_SCRIPT'].format(target='firmware')],
action='$CAT $SOURCES > $TARGET',
)
diff --git a/core/SConscript.kernel b/core/SConscript.kernel
index 2660d15f1b..77ae685180 100644
--- a/core/SConscript.kernel
+++ b/core/SConscript.kernel
@@ -308,7 +308,7 @@ env.Replace(
'-ffreestanding '
'-fstack-protector-all '
+ env.get('ENV')["CPU_CCFLAGS"] + CCFLAGS_MOD,
- LINKFLAGS='-T build/kernel/memory.ld -Wl,--gc-sections -Wl,--print-memory-usage '
+ LINKFLAGS=f'-T build/kernel/{env.get("ENV")["MEMORY_LAYOUT"]} -Wl,--gc-sections -Wl,--print-memory-usage '
' -Wl,-Map=build/kernel/kernel.map -Wl,--warn-common -Wl,--undefined=__errno',
CPPPATH=ALLPATHS,
CPPDEFINES=[
@@ -392,8 +392,8 @@ tools.embed_compressed_binary(
)
linkerscript_gen = env.Command(
- target='memory.ld',
- source=[f'embed/models/{TREZOR_MODEL}/memory.ld', env.get('ENV')['LINKER_SCRIPT'].format(target='kernel')],
+ target=env.get("ENV")["MEMORY_LAYOUT"],
+ source=[f'embed/models/{TREZOR_MODEL}/{env.get("ENV")["MEMORY_LAYOUT"]}', env.get('ENV')['LINKER_SCRIPT'].format(target='kernel')],
action='$CAT $SOURCES > $TARGET',
)
diff --git a/core/embed/models/D001/memory.h b/core/embed/models/D001/memory.h
new file mode 100644
index 0000000000..b8c3317ac3
--- /dev/null
+++ b/core/embed/models/D001/memory.h
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE
+// common
+
+#define FLASH_START 0x08000000
+
+// FLASH layout
+#define BOARDLOADER_START 0x08000000
+#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
+#define BOARDLOADER_SECTOR_START 0
+#define BOARDLOADER_SECTOR_END 2
+
+#define BOARDCAPS_START 0x0800BF00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define UNUSED_1_START 0x0800C000
+#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_1_SECTOR_START 3
+#define UNUSED_1_SECTOR_END 3
+
+#define STORAGE_1_START 0x08010000
+#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_1_SECTOR_START 4
+#define STORAGE_1_SECTOR_END 4
+
+#define BOOTLOADER_START 0x08020000
+#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
+#define BOOTLOADER_SECTOR_START 5
+#define BOOTLOADER_SECTOR_END 5
+
+#define FIRMWARE_START 0x08040000
+#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
+#define FIRMWARE_P1_START 0x08040000
+#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
+#define FIRMWARE_P1_SECTOR_START 6
+#define FIRMWARE_P1_SECTOR_END 11
+// part of firmware P1
+#define KERNEL_START 0x08040000
+#define KERNEL_MAXSIZE (4 * 128 * 1024)
+
+#define ASSETS_START 0x08100000
+#define ASSETS_MAXSIZE (3 * 16 * 1024) // 48 kB
+#define ASSETS_SECTOR_START 12
+#define ASSETS_SECTOR_END 14
+
+#define UNUSED_2_START 0x0810C000
+#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_2_SECTOR_START 15
+#define UNUSED_2_SECTOR_END 15
+
+#define STORAGE_2_START 0x08110000
+#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_2_SECTOR_START 16
+#define STORAGE_2_SECTOR_END 16
+
+#define FIRMWARE_P2_START 0x08120000
+#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
+#define FIRMWARE_P2_SECTOR_START 17
+#define FIRMWARE_P2_SECTOR_END 23
+
+// Ram layout - shared boardloader, bootloader, prodtest
+#define S_MAIN_STACK_START 0x10000000
+#define S_MAIN_STACK_SIZE (16 * 1024)
+
+#define S_FB1_RAM_START 0x10004000
+#define S_FB1_RAM_SIZE (0)
+
+#define S_MAIN_RAM_START 0x10004000
+#define S_MAIN_RAM_SIZE (48 * 1024 - 0x100)
+
+// RAM layout - kernel
+#define K_MAIN_STACK_START 0x10000000
+#define K_MAIN_STACK_SIZE (8 * 1024)
+
+#define K_FB1_RAM_START 0x1000C000
+#define K_FB1_RAM_SIZE (0)
+
+#define K_MAIN_RAM_START 0x1000C000
+#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
+
+// RAM layout - common
+#define BOOTARGS_START 0x1000FF00
+#define BOOTARGS_SIZE 0x100
+
+#define DMABUF_RAM_START 0x20000000
+#define DMABUF_RAM_SIZE (1 * 1024)
+
+#define AUX1_RAM_START (0x20000400)
+#define AUX1_RAM_SIZE (191 * 1024)
+
+#define AUX2_RAM_START 0x10002000
+#define AUX2_RAM_SIZE (40 * 1024)
+
+// misc
+#define CODE_ALIGNMENT 0x200
+#define COREAPP_ALIGNMENT 0x200
diff --git a/core/embed/models/D001/memory.ld b/core/embed/models/D001/memory.ld
index 26cd6081c6..81b11a63a6 100644
--- a/core/embed/models/D001/memory.ld
+++ b/core/embed/models/D001/memory.ld
@@ -1,8 +1,6 @@
/* Auto-generated file, do not edit.*/
FLASH_START = 0x8000000;
-NORCOW_SECTOR_SIZE = 0x10000;
-NORCOW_MIN_VERSION = 0x6;
BOARDLOADER_START = 0x8000000;
BOARDLOADER_MAXSIZE = 0xc000;
BOARDLOADER_SECTOR_START = 0x0;
diff --git a/core/embed/models/D001/model_D001.h b/core/embed/models/D001/model_D001.h
index 6e213538e0..96ac927ff2 100644
--- a/core/embed/models/D001/model_D001.h
+++ b/core/embed/models/D001/model_D001.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_D001_H_
-#define MODELS_MODEL_D001_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include "bootloaders/bootloader_hashes.h"
@@ -28,102 +46,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RESET_CONTENT
-// SHARED WITH MAKEFILE
-// common
-
-#define FLASH_START 0x08000000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define NORCOW_MIN_VERSION 0x00000006
-// FLASH layout
-#define BOARDLOADER_START 0x08000000
-#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
-#define BOARDLOADER_SECTOR_START 0
-#define BOARDLOADER_SECTOR_END 2
-
-#define BOARDCAPS_START 0x0800BF00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define UNUSED_1_START 0x0800C000
-#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_1_SECTOR_START 3
-#define UNUSED_1_SECTOR_END 3
-
-#define STORAGE_1_START 0x08010000
-#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_1_SECTOR_START 4
-#define STORAGE_1_SECTOR_END 4
-
-#define BOOTLOADER_START 0x08020000
-#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
-#define BOOTLOADER_SECTOR_START 5
-#define BOOTLOADER_SECTOR_END 5
-
-#define FIRMWARE_START 0x08040000
-#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
-#define FIRMWARE_P1_START 0x08040000
-#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
-#define FIRMWARE_P1_SECTOR_START 6
-#define FIRMWARE_P1_SECTOR_END 11
-// part of firmware P1
-#define KERNEL_START 0x08040000
-#define KERNEL_MAXSIZE (4 * 128 * 1024)
-
-#define ASSETS_START 0x08100000
-#define ASSETS_MAXSIZE (3 * 16 * 1024) // 48 kB
-#define ASSETS_SECTOR_START 12
-#define ASSETS_SECTOR_END 14
-
-#define UNUSED_2_START 0x0810C000
-#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_2_SECTOR_START 15
-#define UNUSED_2_SECTOR_END 15
-
-#define STORAGE_2_START 0x08110000
-#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_2_SECTOR_START 16
-#define STORAGE_2_SECTOR_END 16
-
-#define FIRMWARE_P2_START 0x08120000
-#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
-#define FIRMWARE_P2_SECTOR_START 17
-#define FIRMWARE_P2_SECTOR_END 23
-
-// Ram layout - shared boardloader, bootloader, prodtest
-#define S_MAIN_STACK_START 0x10000000
-#define S_MAIN_STACK_SIZE (16 * 1024)
-
-#define S_FB1_RAM_START 0x10004000
-#define S_FB1_RAM_SIZE (0)
-
-#define S_MAIN_RAM_START 0x10004000
-#define S_MAIN_RAM_SIZE (48 * 1024 - 0x100)
-
-// RAM layout - kernel
-#define K_MAIN_STACK_START 0x10000000
-#define K_MAIN_STACK_SIZE (8 * 1024)
-
-#define K_FB1_RAM_START 0x1000C000
-#define K_FB1_RAM_SIZE (0)
-
-#define K_MAIN_RAM_START 0x1000C000
-#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
-
-// RAM layout - common
-#define BOOTARGS_START 0x1000FF00
-#define BOOTARGS_SIZE 0x100
-
-#define DMABUF_RAM_START 0x20000000
-#define DMABUF_RAM_SIZE (1 * 1024)
-
-#define AUX1_RAM_START (0x20000400)
-#define AUX1_RAM_SIZE (191 * 1024)
-
-#define AUX2_RAM_START 0x10002000
-#define AUX2_RAM_SIZE (40 * 1024)
-
-// misc
-#define CODE_ALIGNMENT 0x200
-#define COREAPP_ALIGNMENT 0x200
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/D002/memory.h b/core/embed/models/D002/memory.h
new file mode 100644
index 0000000000..912bc45660
--- /dev/null
+++ b/core/embed/models/D002/memory.h
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
+// misc
+#define FLASH_START 0x0C004000
+
+// FLASH layout
+#define SECRET_START 0x0C000000
+#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
+#define SECRET_SECTOR_START 0x0
+#define SECRET_SECTOR_END 0x1
+
+// overlaps with secret
+#define BHK_START 0x0C002000
+#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
+#define BHK_SECTOR_START 0x1
+#define BHK_SECTOR_END 0x1
+
+#define BOARDLOADER_START 0x0C004000
+#define BOARDLOADER_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define BOARDLOADER_SECTOR_START 0x2
+#define BOARDLOADER_SECTOR_END 0x9
+
+#define BOARDCAPS_START 0x0C013F00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define BOOTLOADER_START 0x0C014000
+#define BOOTLOADER_MAXSIZE (24 * 8 * 1024) // 192 kB
+#define BOOTLOADER_SECTOR_START 0x0A
+#define BOOTLOADER_SECTOR_END 0x21
+
+#define FIRMWARE_START 0x0C044000
+#define FIRMWARE_MAXSIZE (430 * 8 * 1024) // 3440 kB
+#define FIRMWARE_SECTOR_START 0x22
+#define FIRMWARE_SECTOR_END 0x1CF
+#define KERNEL_START 0x0C044000
+#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
+
+#define STORAGE_1_START 0x0C3A0000
+#define STORAGE_1_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define STORAGE_1_SECTOR_START 0x1D0
+#define STORAGE_1_SECTOR_END 0x1DF
+
+#define STORAGE_2_START 0x0C3C0000
+#define STORAGE_2_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define STORAGE_2_SECTOR_START 0x1E0
+#define STORAGE_2_SECTOR_END 0x1EF
+
+#define ASSETS_START 0x0C3E0000
+#define ASSETS_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define ASSETS_SECTOR_START 0x1F0
+#define ASSETS_SECTOR_END 0x1FF
+
+// RAM layout
+#define BOOTARGS_START 0x30000000
+#define BOOTARGS_SIZE 0x200
+
+#define FB1_RAM_START 0x30000200
+#define FB1_RAM_SIZE (768 * 1024 - 512)
+
+#define MAIN_RAM_START 0x300C0000
+#define MAIN_RAM_SIZE (64 * 1024)
+
+#define FB2_RAM_START 0x300D0000
+#define FB2_RAM_SIZE (768 * 1024)
+
+#define AUX1_RAM_START 0x30190000
+#define AUX1_RAM_SIZE (896 * 1024)
+
+// misc
+#define CODE_ALIGNMENT 0x400
+#define COREAPP_ALIGNMENT 0x2000
diff --git a/core/embed/models/D002/memory.ld b/core/embed/models/D002/memory.ld
index 82056cd7a5..d8d842494b 100644
--- a/core/embed/models/D002/memory.ld
+++ b/core/embed/models/D002/memory.ld
@@ -1,8 +1,6 @@
/* Auto-generated file, do not edit.*/
FLASH_START = 0xc004000;
-NORCOW_SECTOR_SIZE = 0x20000;
-NORCOW_MIN_VERSION = 0x6;
SECRET_START = 0xc000000;
SECRET_MAXSIZE = 0x4000;
SECRET_SECTOR_START = 0x0;
diff --git a/core/embed/models/D002/model_D002.h b/core/embed/models/D002/model_D002.h
index 34a21371f3..257fb8ea41 100644
--- a/core/embed/models/D002/model_D002.h
+++ b/core/embed/models/D002/model_D002.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_DISC2_H_
-#define MODELS_MODEL_DISC2_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include
#include "bootloaders/bootloader_hashes.h"
@@ -30,77 +48,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RESET_CONTENT
-// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
-// misc
-#define FLASH_START 0x0C004000
#define NORCOW_SECTOR_SIZE (16 * 8 * 1024) // 128 kB
#define NORCOW_MIN_VERSION 0x00000006
-// FLASH layout
-#define SECRET_START 0x0C000000
-#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
-#define SECRET_SECTOR_START 0x0
-#define SECRET_SECTOR_END 0x1
-
-// overlaps with secret
-#define BHK_START 0x0C002000
-#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
-#define BHK_SECTOR_START 0x1
-#define BHK_SECTOR_END 0x1
-
-#define BOARDLOADER_START 0x0C004000
-#define BOARDLOADER_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define BOARDLOADER_SECTOR_START 0x2
-#define BOARDLOADER_SECTOR_END 0x9
-
-#define BOARDCAPS_START 0x0C013F00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define BOOTLOADER_START 0x0C014000
-#define BOOTLOADER_MAXSIZE (24 * 8 * 1024) // 192 kB
-#define BOOTLOADER_SECTOR_START 0x0A
-#define BOOTLOADER_SECTOR_END 0x21
-
-#define FIRMWARE_START 0x0C044000
-#define FIRMWARE_MAXSIZE (430 * 8 * 1024) // 3440 kB
-#define FIRMWARE_SECTOR_START 0x22
-#define FIRMWARE_SECTOR_END 0x1CF
-#define KERNEL_START 0x0C044000
-#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
-
-#define STORAGE_1_START 0x0C3A0000
-#define STORAGE_1_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define STORAGE_1_SECTOR_START 0x1D0
-#define STORAGE_1_SECTOR_END 0x1DF
-
-#define STORAGE_2_START 0x0C3C0000
-#define STORAGE_2_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define STORAGE_2_SECTOR_START 0x1E0
-#define STORAGE_2_SECTOR_END 0x1EF
-
-#define ASSETS_START 0x0C3E0000
-#define ASSETS_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define ASSETS_SECTOR_START 0x1F0
-#define ASSETS_SECTOR_END 0x1FF
-
-// RAM layout
-#define BOOTARGS_START 0x30000000
-#define BOOTARGS_SIZE 0x200
-
-#define FB1_RAM_START 0x30000200
-#define FB1_RAM_SIZE (768 * 1024 - 512)
-
-#define MAIN_RAM_START 0x300C0000
-#define MAIN_RAM_SIZE (64 * 1024)
-
-#define FB2_RAM_START 0x300D0000
-#define FB2_RAM_SIZE (768 * 1024)
-
-#define AUX1_RAM_START 0x30190000
-#define AUX1_RAM_SIZE (896 * 1024)
-
-// misc
-#define CODE_ALIGNMENT 0x400
-#define COREAPP_ALIGNMENT 0x2000
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/T2B1/memory.h b/core/embed/models/T2B1/memory.h
new file mode 100644
index 0000000000..22405e6525
--- /dev/null
+++ b/core/embed/models/T2B1/memory.h
@@ -0,0 +1,122 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE
+// common
+
+#define FLASH_START 0x08000000
+#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
+
+// FLASH layout
+#define BOARDLOADER_START 0x08000000
+#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
+#define BOARDLOADER_SECTOR_START 0
+#define BOARDLOADER_SECTOR_END 2
+
+#define BOARDCAPS_START 0x0800BF00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define UNUSED_1_START 0x0800C000
+#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_1_SECTOR_START 3
+#define UNUSED_1_SECTOR_END 3
+
+#define STORAGE_1_START 0x08010000
+#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_1_SECTOR_START 4
+#define STORAGE_1_SECTOR_END 4
+
+#define BOOTLOADER_START 0x08020000
+#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
+#define BOOTLOADER_SECTOR_START 5
+#define BOOTLOADER_SECTOR_END 5
+
+#define FIRMWARE_START 0x08040000
+#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
+#define FIRMWARE_P1_START 0x08040000
+#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
+#define FIRMWARE_P1_SECTOR_START 6
+#define FIRMWARE_P1_SECTOR_END 11
+// part of firmware P1
+#define KERNEL_START 0x08040000
+#define KERNEL_MAXSIZE (4 * 128 * 1024)
+
+#define SECRET_START 0x08100000
+#define SECRET_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define SECRET_SECTOR_START 12
+#define SECRET_SECTOR_END 12
+
+#define ASSETS_START 0x08104000
+#define ASSETS_MAXSIZE (2 * 16 * 1024) // 32 kB
+#define ASSETS_SECTOR_START 13
+#define ASSETS_SECTOR_END 14
+
+#define UNUSED_2_START 0x0810C000
+#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_2_SECTOR_START 15
+#define UNUSED_2_SECTOR_END 15
+
+#define STORAGE_2_START 0x08110000
+#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_2_SECTOR_START 16
+#define STORAGE_2_SECTOR_END 16
+
+#define FIRMWARE_P2_START 0x08120000
+#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
+#define FIRMWARE_P2_SECTOR_START 17
+#define FIRMWARE_P2_SECTOR_END 23
+
+// Ram layout - shared boardloader, bootloader, prodtest
+#define S_MAIN_STACK_START 0x10000000
+#define S_MAIN_STACK_SIZE (16 * 1024)
+
+#define S_FB1_RAM_START 0x10004000
+#define S_FB1_RAM_SIZE (8 * 1024)
+
+#define S_MAIN_RAM_START 0x10006000
+#define S_MAIN_RAM_SIZE (40 * 1024 - 0x100)
+
+// RAM layout - kernel
+#define K_MAIN_STACK_START 0x10000000
+#define K_MAIN_STACK_SIZE (8 * 1024)
+
+#define K_FB1_RAM_START 0x1000A000
+#define K_FB1_RAM_SIZE (8 * 1024)
+
+#define K_MAIN_RAM_START 0x1000C000
+#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
+
+// RAM layout - common
+#define BOOTARGS_START 0x1000FF00
+#define BOOTARGS_SIZE 0x100
+
+#define DMABUF_RAM_START 0x20000000
+#define DMABUF_RAM_SIZE (1 * 1024)
+
+#define AUX1_RAM_START (0x20000400)
+#define AUX1_RAM_SIZE (191 * 1024)
+
+#define AUX2_RAM_START 0x10002000
+#define AUX2_RAM_SIZE (32 * 1024)
+
+// misc
+#define CODE_ALIGNMENT 0x200
+#define COREAPP_ALIGNMENT 0x200
diff --git a/core/embed/models/T2B1/memory.ld b/core/embed/models/T2B1/memory.ld
index 79a02f8f57..3104993d9d 100644
--- a/core/embed/models/T2B1/memory.ld
+++ b/core/embed/models/T2B1/memory.ld
@@ -2,7 +2,6 @@
FLASH_START = 0x8000000;
NORCOW_SECTOR_SIZE = 0x10000;
-NORCOW_MIN_VERSION = 0x3;
BOARDLOADER_START = 0x8000000;
BOARDLOADER_MAXSIZE = 0xc000;
BOARDLOADER_SECTOR_START = 0x0;
diff --git a/core/embed/models/T2B1/model_T2B1.h b/core/embed/models/T2B1/model_T2B1.h
index 79ec713b3a..a003855177 100644
--- a/core/embed/models/T2B1/model_T2B1.h
+++ b/core/embed/models/T2B1/model_T2B1.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_T2B1_H_
-#define MODELS_MODEL_T2B1_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include "bootloaders/bootloader_hashes.h"
@@ -29,107 +47,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RETAIN_CONTENT
#define RSOD_INFINITE_LOOP 1
-// SHARED WITH MAKEFILE
-// common
-
-#define FLASH_START 0x08000000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define NORCOW_MIN_VERSION 0x00000003
-// FLASH layout
-#define BOARDLOADER_START 0x08000000
-#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
-#define BOARDLOADER_SECTOR_START 0
-#define BOARDLOADER_SECTOR_END 2
-
-#define BOARDCAPS_START 0x0800BF00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define UNUSED_1_START 0x0800C000
-#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_1_SECTOR_START 3
-#define UNUSED_1_SECTOR_END 3
-
-#define STORAGE_1_START 0x08010000
-#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_1_SECTOR_START 4
-#define STORAGE_1_SECTOR_END 4
-
-#define BOOTLOADER_START 0x08020000
-#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
-#define BOOTLOADER_SECTOR_START 5
-#define BOOTLOADER_SECTOR_END 5
-
-#define FIRMWARE_START 0x08040000
-#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
-#define FIRMWARE_P1_START 0x08040000
-#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
-#define FIRMWARE_P1_SECTOR_START 6
-#define FIRMWARE_P1_SECTOR_END 11
-// part of firmware P1
-#define KERNEL_START 0x08040000
-#define KERNEL_MAXSIZE (4 * 128 * 1024)
-
-#define SECRET_START 0x08100000
-#define SECRET_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define SECRET_SECTOR_START 12
-#define SECRET_SECTOR_END 12
-
-#define ASSETS_START 0x08104000
-#define ASSETS_MAXSIZE (2 * 16 * 1024) // 32 kB
-#define ASSETS_SECTOR_START 13
-#define ASSETS_SECTOR_END 14
-
-#define UNUSED_2_START 0x0810C000
-#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_2_SECTOR_START 15
-#define UNUSED_2_SECTOR_END 15
-
-#define STORAGE_2_START 0x08110000
-#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_2_SECTOR_START 16
-#define STORAGE_2_SECTOR_END 16
-
-#define FIRMWARE_P2_START 0x08120000
-#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
-#define FIRMWARE_P2_SECTOR_START 17
-#define FIRMWARE_P2_SECTOR_END 23
-
-// Ram layout - shared boardloader, bootloader, prodtest
-#define S_MAIN_STACK_START 0x10000000
-#define S_MAIN_STACK_SIZE (16 * 1024)
-
-#define S_FB1_RAM_START 0x10004000
-#define S_FB1_RAM_SIZE (8 * 1024)
-
-#define S_MAIN_RAM_START 0x10006000
-#define S_MAIN_RAM_SIZE (40 * 1024 - 0x100)
-
-// RAM layout - kernel
-#define K_MAIN_STACK_START 0x10000000
-#define K_MAIN_STACK_SIZE (8 * 1024)
-
-#define K_FB1_RAM_START 0x1000A000
-#define K_FB1_RAM_SIZE (8 * 1024)
-
-#define K_MAIN_RAM_START 0x1000C000
-#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
-
-// RAM layout - common
-#define BOOTARGS_START 0x1000FF00
-#define BOOTARGS_SIZE 0x100
-
-#define DMABUF_RAM_START 0x20000000
-#define DMABUF_RAM_SIZE (1 * 1024)
-
-#define AUX1_RAM_START (0x20000400)
-#define AUX1_RAM_SIZE (191 * 1024)
-
-#define AUX2_RAM_START 0x10002000
-#define AUX2_RAM_SIZE (32 * 1024)
-
-// misc
-#define CODE_ALIGNMENT 0x200
-#define COREAPP_ALIGNMENT 0x200
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/T2T1/memory.h b/core/embed/models/T2T1/memory.h
new file mode 100644
index 0000000000..91f397d7a8
--- /dev/null
+++ b/core/embed/models/T2T1/memory.h
@@ -0,0 +1,117 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE
+// common
+
+#define FLASH_START 0x08000000
+#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
+
+// FLASH layout
+#define BOARDLOADER_START 0x08000000
+#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
+#define BOARDLOADER_SECTOR_START 0
+#define BOARDLOADER_SECTOR_END 2
+
+#define BOARDCAPS_START 0x0800BF00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define UNUSED_1_START 0x0800C000
+#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_1_SECTOR_START 3
+#define UNUSED_1_SECTOR_END 3
+
+#define STORAGE_1_START 0x08010000
+#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_1_SECTOR_START 4
+#define STORAGE_1_SECTOR_END 4
+
+#define BOOTLOADER_START 0x08020000
+#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
+#define BOOTLOADER_SECTOR_START 5
+#define BOOTLOADER_SECTOR_END 5
+
+#define FIRMWARE_START 0x08040000
+#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
+#define FIRMWARE_P1_START 0x08040000
+#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
+#define FIRMWARE_P1_SECTOR_START 6
+#define FIRMWARE_P1_SECTOR_END 11
+// part of firmware P1
+#define KERNEL_START 0x08040000
+#define KERNEL_MAXSIZE (4 * 128 * 1024)
+
+#define ASSETS_START 0x08100000
+#define ASSETS_MAXSIZE (3 * 16 * 1024) // 48 kB
+#define ASSETS_SECTOR_START 12
+#define ASSETS_SECTOR_END 14
+
+#define UNUSED_2_START 0x0810C000
+#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
+#define UNUSED_2_SECTOR_START 15
+#define UNUSED_2_SECTOR_END 15
+
+#define STORAGE_2_START 0x08110000
+#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
+#define STORAGE_2_SECTOR_START 16
+#define STORAGE_2_SECTOR_END 16
+
+#define FIRMWARE_P2_START 0x08120000
+#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
+#define FIRMWARE_P2_SECTOR_START 17
+#define FIRMWARE_P2_SECTOR_END 23
+
+// Ram layout - shared boardloader, bootloader, prodtest
+#define S_MAIN_STACK_START 0x10000000
+#define S_MAIN_STACK_SIZE (16 * 1024)
+
+#define S_FB1_RAM_START 0x10004000
+#define S_FB1_RAM_SIZE (0)
+
+#define S_MAIN_RAM_START 0x10004000
+#define S_MAIN_RAM_SIZE (48 * 1024 - 0x100)
+
+// RAM layout - kernel
+#define K_MAIN_STACK_START 0x10000000
+#define K_MAIN_STACK_SIZE (8 * 1024)
+
+#define K_FB1_RAM_START 0x1000C000
+#define K_FB1_RAM_SIZE (0)
+
+#define K_MAIN_RAM_START 0x1000C000
+#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
+
+// RAM layout - common
+#define BOOTARGS_START 0x1000FF00
+#define BOOTARGS_SIZE 0x100
+
+#define DMABUF_RAM_START 0x20000000
+#define DMABUF_RAM_SIZE (1 * 1024)
+
+#define AUX1_RAM_START (0x20000400)
+#define AUX1_RAM_SIZE (191 * 1024)
+
+#define AUX2_RAM_START 0x10002000
+#define AUX2_RAM_SIZE (40 * 1024)
+
+// misc
+#define CODE_ALIGNMENT 0x200
+#define COREAPP_ALIGNMENT 0x200
diff --git a/core/embed/models/T2T1/memory.ld b/core/embed/models/T2T1/memory.ld
index 075cccbacc..4f68c3fa58 100644
--- a/core/embed/models/T2T1/memory.ld
+++ b/core/embed/models/T2T1/memory.ld
@@ -2,7 +2,6 @@
FLASH_START = 0x8000000;
NORCOW_SECTOR_SIZE = 0x10000;
-NORCOW_MIN_VERSION = 0x0;
BOARDLOADER_START = 0x8000000;
BOARDLOADER_MAXSIZE = 0xc000;
BOARDLOADER_SECTOR_START = 0x0;
diff --git a/core/embed/models/T2T1/model_T2T1.h b/core/embed/models/T2T1/model_T2T1.h
index 978cfe0d55..b4a58f3141 100644
--- a/core/embed/models/T2T1/model_T2T1.h
+++ b/core/embed/models/T2T1/model_T2T1.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_T2T1_H_
-#define MODELS_MODEL_T2T1_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include "bootloaders/bootloader_hashes.h"
@@ -29,102 +47,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RETAIN_CONTENT
#define RSOD_INFINITE_LOOP 1
-// SHARED WITH MAKEFILE
-// common
-
-#define FLASH_START 0x08000000
#define NORCOW_SECTOR_SIZE (1 * 64 * 1024) // 64 kB
#define NORCOW_MIN_VERSION 0x00000000
-// FLASH layout
-#define BOARDLOADER_START 0x08000000
-#define BOARDLOADER_MAXSIZE (3 * 16 * 1024) // 48 kB
-#define BOARDLOADER_SECTOR_START 0
-#define BOARDLOADER_SECTOR_END 2
-
-#define BOARDCAPS_START 0x0800BF00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define UNUSED_1_START 0x0800C000
-#define UNUSED_1_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_1_SECTOR_START 3
-#define UNUSED_1_SECTOR_END 3
-
-#define STORAGE_1_START 0x08010000
-#define STORAGE_1_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_1_SECTOR_START 4
-#define STORAGE_1_SECTOR_END 4
-
-#define BOOTLOADER_START 0x08020000
-#define BOOTLOADER_MAXSIZE (1 * 128 * 1024) // 128 kB
-#define BOOTLOADER_SECTOR_START 5
-#define BOOTLOADER_SECTOR_END 5
-
-#define FIRMWARE_START 0x08040000
-#define FIRMWARE_MAXSIZE (13 * 128 * 1024) // 1664 kB
-#define FIRMWARE_P1_START 0x08040000
-#define FIRMWARE_P1_MAXSIZE (6 * 128 * 1024)
-#define FIRMWARE_P1_SECTOR_START 6
-#define FIRMWARE_P1_SECTOR_END 11
-// part of firmware P1
-#define KERNEL_START 0x08040000
-#define KERNEL_MAXSIZE (4 * 128 * 1024)
-
-#define ASSETS_START 0x08100000
-#define ASSETS_MAXSIZE (3 * 16 * 1024) // 48 kB
-#define ASSETS_SECTOR_START 12
-#define ASSETS_SECTOR_END 14
-
-#define UNUSED_2_START 0x0810C000
-#define UNUSED_2_MAXSIZE (1 * 16 * 1024) // 16 kB
-#define UNUSED_2_SECTOR_START 15
-#define UNUSED_2_SECTOR_END 15
-
-#define STORAGE_2_START 0x08110000
-#define STORAGE_2_MAXSIZE (1 * 64 * 1024) // 64 kB
-#define STORAGE_2_SECTOR_START 16
-#define STORAGE_2_SECTOR_END 16
-
-#define FIRMWARE_P2_START 0x08120000
-#define FIRMWARE_P2_MAXSIZE (7 * 128 * 1024)
-#define FIRMWARE_P2_SECTOR_START 17
-#define FIRMWARE_P2_SECTOR_END 23
-
-// Ram layout - shared boardloader, bootloader, prodtest
-#define S_MAIN_STACK_START 0x10000000
-#define S_MAIN_STACK_SIZE (16 * 1024)
-
-#define S_FB1_RAM_START 0x10004000
-#define S_FB1_RAM_SIZE (0)
-
-#define S_MAIN_RAM_START 0x10004000
-#define S_MAIN_RAM_SIZE (48 * 1024 - 0x100)
-
-// RAM layout - kernel
-#define K_MAIN_STACK_START 0x10000000
-#define K_MAIN_STACK_SIZE (8 * 1024)
-
-#define K_FB1_RAM_START 0x1000C000
-#define K_FB1_RAM_SIZE (0)
-
-#define K_MAIN_RAM_START 0x1000C000
-#define K_MAIN_RAM_SIZE (16 * 1024 - 0x100)
-
-// RAM layout - common
-#define BOOTARGS_START 0x1000FF00
-#define BOOTARGS_SIZE 0x100
-
-#define DMABUF_RAM_START 0x20000000
-#define DMABUF_RAM_SIZE (1 * 1024)
-
-#define AUX1_RAM_START (0x20000400)
-#define AUX1_RAM_SIZE (191 * 1024)
-
-#define AUX2_RAM_START 0x10002000
-#define AUX2_RAM_SIZE (40 * 1024)
-
-// misc
-#define CODE_ALIGNMENT 0x200
-#define COREAPP_ALIGNMENT 0x200
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/T3B1/memory.h b/core/embed/models/T3B1/memory.h
new file mode 100644
index 0000000000..e04de82ec4
--- /dev/null
+++ b/core/embed/models/T3B1/memory.h
@@ -0,0 +1,99 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
+// misc
+#define FLASH_START 0x0C004000
+
+// FLASH layout
+#define SECRET_START 0x0C000000
+#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
+#define SECRET_SECTOR_START 0x0
+#define SECRET_SECTOR_END 0x1
+
+// overlaps with secret
+#define BHK_START 0x0C002000
+#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
+#define BHK_SECTOR_START 0x1
+#define BHK_SECTOR_END 0x1
+
+#define BOARDLOADER_START 0x0C004000
+#define BOARDLOADER_MAXSIZE (6 * 8 * 1024) // 48 kB
+#define BOARDLOADER_SECTOR_START 0x2
+#define BOARDLOADER_SECTOR_END 0x7
+
+#define BOARDCAPS_START 0x0C00FF00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define BOOTLOADER_START 0x0C010000
+#define BOOTLOADER_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define BOOTLOADER_SECTOR_START 0x8
+#define BOOTLOADER_SECTOR_END 0x17
+
+#define STORAGE_1_START 0x0C030000
+#define STORAGE_1_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define STORAGE_1_SECTOR_START 0x18
+#define STORAGE_1_SECTOR_END 0x1F
+
+#define STORAGE_2_START 0x0C040000
+#define STORAGE_2_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define STORAGE_2_SECTOR_START 0x20
+#define STORAGE_2_SECTOR_END 0x27
+
+#define FIRMWARE_START 0x0C050000
+#define FIRMWARE_MAXSIZE (208 * 8 * 1024) // 1664 kB
+#define FIRMWARE_SECTOR_START 0x28
+#define FIRMWARE_SECTOR_END 0xF7
+#define KERNEL_START 0x0C050000
+#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
+
+#define ASSETS_START 0x0C1F0000
+#define ASSETS_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define ASSETS_SECTOR_START 0xF8
+#define ASSETS_SECTOR_END 0xFF
+
+// RAM layout
+#define AUX1_RAM_START 0x30000000
+#define AUX1_RAM_SIZE (192 * 1024 - 512)
+
+// 256 bytes skipped - trustzone alignment vs fixed bootargs position
+
+#define BOOTARGS_START 0x3002FF00
+#define BOOTARGS_SIZE 0x100
+
+#define MAIN_RAM_START 0x30030000
+#define MAIN_RAM_SIZE (24 * 1024 - 512)
+
+#define SAES_RAM_START 0x30035E00
+#define SAES_RAM_SIZE 512
+
+#define AUX2_RAM_START 0x30036000
+#define AUX2_RAM_SIZE (544 * 1024)
+
+#define FB1_RAM_START 0x300BE000
+#define FB1_RAM_SIZE (0x2000)
+
+#define FB2_RAM_START 0x300C0000
+#define FB2_RAM_SIZE (0)
+
+// misc
+#define CODE_ALIGNMENT 0x200
+#define COREAPP_ALIGNMENT 0x2000
diff --git a/core/embed/models/T3B1/memory.ld b/core/embed/models/T3B1/memory.ld
index 0b45ca6ea7..1c183e36b4 100644
--- a/core/embed/models/T3B1/memory.ld
+++ b/core/embed/models/T3B1/memory.ld
@@ -1,8 +1,6 @@
/* Auto-generated file, do not edit.*/
FLASH_START = 0xc004000;
-NORCOW_SECTOR_SIZE = 0x10000;
-NORCOW_MIN_VERSION = 0x5;
SECRET_START = 0xc000000;
SECRET_MAXSIZE = 0x4000;
SECRET_SECTOR_START = 0x0;
diff --git a/core/embed/models/T3B1/model_T3B1.h b/core/embed/models/T3B1/model_T3B1.h
index e5920f13d6..f9afa212ae 100644
--- a/core/embed/models/T3B1/model_T3B1.h
+++ b/core/embed/models/T3B1/model_T3B1.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_T3B1_H_
-#define MODELS_MODEL_T3B1_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include "bootloaders/bootloader_hashes.h"
@@ -30,85 +48,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RETAIN_CONTENT
#define RSOD_INFINITE_LOOP 1
-// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
-// misc
-#define FLASH_START 0x0C004000
#define NORCOW_SECTOR_SIZE (8 * 8 * 1024) // 64 kB
#define NORCOW_MIN_VERSION 0x00000005
-// FLASH layout
-#define SECRET_START 0x0C000000
-#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
-#define SECRET_SECTOR_START 0x0
-#define SECRET_SECTOR_END 0x1
-
-// overlaps with secret
-#define BHK_START 0x0C002000
-#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
-#define BHK_SECTOR_START 0x1
-#define BHK_SECTOR_END 0x1
-
-#define BOARDLOADER_START 0x0C004000
-#define BOARDLOADER_MAXSIZE (6 * 8 * 1024) // 48 kB
-#define BOARDLOADER_SECTOR_START 0x2
-#define BOARDLOADER_SECTOR_END 0x7
-
-#define BOARDCAPS_START 0x0C00FF00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define BOOTLOADER_START 0x0C010000
-#define BOOTLOADER_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define BOOTLOADER_SECTOR_START 0x8
-#define BOOTLOADER_SECTOR_END 0x17
-
-#define STORAGE_1_START 0x0C030000
-#define STORAGE_1_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define STORAGE_1_SECTOR_START 0x18
-#define STORAGE_1_SECTOR_END 0x1F
-
-#define STORAGE_2_START 0x0C040000
-#define STORAGE_2_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define STORAGE_2_SECTOR_START 0x20
-#define STORAGE_2_SECTOR_END 0x27
-
-#define FIRMWARE_START 0x0C050000
-#define FIRMWARE_MAXSIZE (208 * 8 * 1024) // 1664 kB
-#define FIRMWARE_SECTOR_START 0x28
-#define FIRMWARE_SECTOR_END 0xF7
-#define KERNEL_START 0x0C050000
-#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
-
-#define ASSETS_START 0x0C1F0000
-#define ASSETS_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define ASSETS_SECTOR_START 0xF8
-#define ASSETS_SECTOR_END 0xFF
-
-// RAM layout
-#define AUX1_RAM_START 0x30000000
-#define AUX1_RAM_SIZE (192 * 1024 - 512)
-
-// 256 bytes skipped - trustzone alignment vs fixed bootargs position
-
-#define BOOTARGS_START 0x3002FF00
-#define BOOTARGS_SIZE 0x100
-
-#define MAIN_RAM_START 0x30030000
-#define MAIN_RAM_SIZE (24 * 1024 - 512)
-
-#define SAES_RAM_START 0x30035E00
-#define SAES_RAM_SIZE 512
-
-#define AUX2_RAM_START 0x30036000
-#define AUX2_RAM_SIZE (544 * 1024)
-
-#define FB1_RAM_START 0x300BE000
-#define FB1_RAM_SIZE (0x2000)
-
-#define FB2_RAM_START 0x300C0000
-#define FB2_RAM_SIZE (0)
-
-// misc
-#define CODE_ALIGNMENT 0x200
-#define COREAPP_ALIGNMENT 0x2000
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/T3T1/memory.h b/core/embed/models/T3T1/memory.h
new file mode 100644
index 0000000000..613647daf0
--- /dev/null
+++ b/core/embed/models/T3T1/memory.h
@@ -0,0 +1,99 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
+// misc
+#define FLASH_START 0x0C004000
+
+// FLASH layout
+#define SECRET_START 0x0C000000
+#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
+#define SECRET_SECTOR_START 0x0
+#define SECRET_SECTOR_END 0x1
+
+// overlaps with secret
+#define BHK_START 0x0C002000
+#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
+#define BHK_SECTOR_START 0x1
+#define BHK_SECTOR_END 0x1
+
+#define BOARDLOADER_START 0x0C004000
+#define BOARDLOADER_MAXSIZE (6 * 8 * 1024) // 48 kB
+#define BOARDLOADER_SECTOR_START 0x2
+#define BOARDLOADER_SECTOR_END 0x7
+
+#define BOARDCAPS_START 0x0C00FF00
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define BOOTLOADER_START 0x0C010000
+#define BOOTLOADER_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define BOOTLOADER_SECTOR_START 0x8
+#define BOOTLOADER_SECTOR_END 0x17
+
+#define STORAGE_1_START 0x0C030000
+#define STORAGE_1_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define STORAGE_1_SECTOR_START 0x18
+#define STORAGE_1_SECTOR_END 0x1F
+
+#define STORAGE_2_START 0x0C040000
+#define STORAGE_2_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define STORAGE_2_SECTOR_START 0x20
+#define STORAGE_2_SECTOR_END 0x27
+
+#define FIRMWARE_START 0x0C050000
+#define FIRMWARE_MAXSIZE (208 * 8 * 1024) // 1664 kB
+#define FIRMWARE_SECTOR_START 0x28
+#define FIRMWARE_SECTOR_END 0xF7
+#define KERNEL_START 0x0C050000
+#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
+
+#define ASSETS_START 0x0C1F0000
+#define ASSETS_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define ASSETS_SECTOR_START 0xF8
+#define ASSETS_SECTOR_END 0xFF
+
+// RAM layout
+#define AUX1_RAM_START 0x30000000
+#define AUX1_RAM_SIZE (192 * 1024 - 512)
+
+// 256 bytes skipped - trustzone alignment vs fixed bootargs position
+
+#define BOOTARGS_START 0x3002FF00
+#define BOOTARGS_SIZE 0x100
+
+#define MAIN_RAM_START 0x30030000
+#define MAIN_RAM_SIZE (24 * 1024 - 512)
+
+#define SAES_RAM_START 0x30035E00
+#define SAES_RAM_SIZE 512
+
+#define AUX2_RAM_START 0x30036000
+#define AUX2_RAM_SIZE (327 * 1024)
+
+#define FB1_RAM_START 0x30087C00
+#define FB1_RAM_SIZE (115200)
+
+#define FB2_RAM_START 0x300A3E00
+#define FB2_RAM_SIZE (115200)
+
+// misc
+#define CODE_ALIGNMENT 0x200
+#define COREAPP_ALIGNMENT 0x2000
diff --git a/core/embed/models/T3T1/memory.ld b/core/embed/models/T3T1/memory.ld
index 4a08fe0b52..9d9dc882a0 100644
--- a/core/embed/models/T3T1/memory.ld
+++ b/core/embed/models/T3T1/memory.ld
@@ -1,8 +1,6 @@
/* Auto-generated file, do not edit.*/
FLASH_START = 0xc004000;
-NORCOW_SECTOR_SIZE = 0x10000;
-NORCOW_MIN_VERSION = 0x4;
SECRET_START = 0xc000000;
SECRET_MAXSIZE = 0x4000;
SECRET_SECTOR_START = 0x0;
diff --git a/core/embed/models/T3T1/model_T3T1.h b/core/embed/models/T3T1/model_T3T1.h
index cb19229795..4895a3fbcf 100644
--- a/core/embed/models/T3T1/model_T3T1.h
+++ b/core/embed/models/T3T1/model_T3T1.h
@@ -1,5 +1,23 @@
-#ifndef MODELS_MODEL_T3T1_H_
-#define MODELS_MODEL_T3T1_H_
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include "bootloaders/bootloader_hashes.h"
@@ -30,85 +48,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RETAIN_CONTENT
#define RSOD_INFINITE_LOOP 1
-// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
-// misc
-#define FLASH_START 0x0C004000
#define NORCOW_SECTOR_SIZE (8 * 8 * 1024) // 64 kB
#define NORCOW_MIN_VERSION 0x00000004
-// FLASH layout
-#define SECRET_START 0x0C000000
-#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
-#define SECRET_SECTOR_START 0x0
-#define SECRET_SECTOR_END 0x1
-
-// overlaps with secret
-#define BHK_START 0x0C002000
-#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
-#define BHK_SECTOR_START 0x1
-#define BHK_SECTOR_END 0x1
-
-#define BOARDLOADER_START 0x0C004000
-#define BOARDLOADER_MAXSIZE (6 * 8 * 1024) // 48 kB
-#define BOARDLOADER_SECTOR_START 0x2
-#define BOARDLOADER_SECTOR_END 0x7
-
-#define BOARDCAPS_START 0x0C00FF00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define BOOTLOADER_START 0x0C010000
-#define BOOTLOADER_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define BOOTLOADER_SECTOR_START 0x8
-#define BOOTLOADER_SECTOR_END 0x17
-
-#define STORAGE_1_START 0x0C030000
-#define STORAGE_1_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define STORAGE_1_SECTOR_START 0x18
-#define STORAGE_1_SECTOR_END 0x1F
-
-#define STORAGE_2_START 0x0C040000
-#define STORAGE_2_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define STORAGE_2_SECTOR_START 0x20
-#define STORAGE_2_SECTOR_END 0x27
-
-#define FIRMWARE_START 0x0C050000
-#define FIRMWARE_MAXSIZE (208 * 8 * 1024) // 1664 kB
-#define FIRMWARE_SECTOR_START 0x28
-#define FIRMWARE_SECTOR_END 0xF7
-#define KERNEL_START 0x0C050000
-#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
-
-#define ASSETS_START 0x0C1F0000
-#define ASSETS_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define ASSETS_SECTOR_START 0xF8
-#define ASSETS_SECTOR_END 0xFF
-
-// RAM layout
-#define AUX1_RAM_START 0x30000000
-#define AUX1_RAM_SIZE (192 * 1024 - 512)
-
-// 256 bytes skipped - trustzone alignment vs fixed bootargs position
-
-#define BOOTARGS_START 0x3002FF00
-#define BOOTARGS_SIZE 0x100
-
-#define MAIN_RAM_START 0x30030000
-#define MAIN_RAM_SIZE (24 * 1024 - 512)
-
-#define SAES_RAM_START 0x30035E00
-#define SAES_RAM_SIZE 512
-
-#define AUX2_RAM_START 0x30036000
-#define AUX2_RAM_SIZE (327 * 1024)
-
-#define FB1_RAM_START 0x30087C00
-#define FB1_RAM_SIZE (115200)
-
-#define FB2_RAM_START 0x300A3E00
-#define FB2_RAM_SIZE (115200)
-
-// misc
-#define CODE_ALIGNMENT 0x200
-#define COREAPP_ALIGNMENT 0x2000
-
-#endif
+#include "memory.h"
diff --git a/core/embed/models/T3W1/memory.h b/core/embed/models/T3W1/memory.h
new file mode 100644
index 0000000000..5e4e674156
--- /dev/null
+++ b/core/embed/models/T3W1/memory.h
@@ -0,0 +1,92 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
+// misc
+#define FLASH_START (0x0C004000)
+
+// FLASH layout
+#define SECRET_START (0x0C000000)
+#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
+#define SECRET_SECTOR_START 0x0
+#define SECRET_SECTOR_END 0x1
+
+// overlaps with secret
+#define BHK_START (0x0C002000)
+#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
+#define BHK_SECTOR_START 0x1
+#define BHK_SECTOR_END 0x1
+
+#define BOARDLOADER_START (0x0C004000)
+#define BOARDLOADER_MAXSIZE (8 * 8 * 1024) // 64 kB
+#define BOARDLOADER_SECTOR_START 0x2
+#define BOARDLOADER_SECTOR_END 0x9
+
+#define BOARDCAPS_START (0x0C013F00)
+#define BOARDCAPS_MAXSIZE 0x100
+
+#define BOOTLOADER_START (0x0C014000)
+#define BOOTLOADER_MAXSIZE (24 * 8 * 1024) // 192 kB
+#define BOOTLOADER_SECTOR_START 0x0A
+#define BOOTLOADER_SECTOR_END 0x21
+
+#define FIRMWARE_START (0x0C044000)
+#define FIRMWARE_MAXSIZE (430 * 8 * 1024) // 3440 kB
+#define FIRMWARE_SECTOR_START 0x22
+#define FIRMWARE_SECTOR_END 0x1CF
+
+#define KERNEL_START (0x0C044000)
+#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
+
+#define STORAGE_1_START (0x0C3A0000)
+#define STORAGE_1_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define STORAGE_1_SECTOR_START 0x1D0
+#define STORAGE_1_SECTOR_END 0x1DF
+
+#define STORAGE_2_START (0x0C3C0000)
+#define STORAGE_2_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define STORAGE_2_SECTOR_START 0x1E0
+#define STORAGE_2_SECTOR_END 0x1EF
+
+#define ASSETS_START (0x0C3E0000)
+#define ASSETS_MAXSIZE (16 * 8 * 1024) // 128 kB
+#define ASSETS_SECTOR_START 0x1F0
+#define ASSETS_SECTOR_END 0x1FF
+
+// RAM layout
+#define BOOTARGS_START (0x30000000)
+#define BOOTARGS_SIZE 0x200
+
+#define FB1_RAM_START (0x30000200)
+#define FB1_RAM_SIZE (768 * 1024 - 512)
+
+#define MAIN_RAM_START (0x300C0000)
+#define MAIN_RAM_SIZE (64 * 1024)
+
+#define FB2_RAM_START (0x300D0000)
+#define FB2_RAM_SIZE (768 * 1024)
+
+#define AUX1_RAM_START (0x30190000)
+#define AUX1_RAM_SIZE (896 * 1024)
+
+// misc
+#define CODE_ALIGNMENT 0x400
+#define COREAPP_ALIGNMENT 0x2000
diff --git a/core/embed/models/T3W1/memory.ld b/core/embed/models/T3W1/memory.ld
index 82056cd7a5..d8d842494b 100644
--- a/core/embed/models/T3W1/memory.ld
+++ b/core/embed/models/T3W1/memory.ld
@@ -1,8 +1,6 @@
/* Auto-generated file, do not edit.*/
FLASH_START = 0xc004000;
-NORCOW_SECTOR_SIZE = 0x20000;
-NORCOW_MIN_VERSION = 0x6;
SECRET_START = 0xc000000;
SECRET_MAXSIZE = 0x4000;
SECRET_SECTOR_START = 0x0;
diff --git a/core/embed/models/T3W1/model_T3W1.h b/core/embed/models/T3W1/model_T3W1.h
index 8c3d9d6de1..d34ac6f1d8 100644
--- a/core/embed/models/T3W1/model_T3W1.h
+++ b/core/embed/models/T3W1/model_T3W1.h
@@ -1,7 +1,24 @@
-#ifndef MODELS_MODEL_T3W1_H_
-#define MODELS_MODEL_T3W1_H_
-// #include "bootloaders/bootloader_hashes.h"
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
#include
@@ -29,77 +46,7 @@
#define DISPLAY_JUMP_BEHAVIOR DISPLAY_RESET_CONTENT
-// SHARED WITH MAKEFILE, LINKER SCRIPT etc.
-// misc
-#define FLASH_START 0x0C004000
#define NORCOW_SECTOR_SIZE (16 * 8 * 1024) // 128 kB
#define NORCOW_MIN_VERSION 0x00000006
-// FLASH layout
-#define SECRET_START 0x0C000000
-#define SECRET_MAXSIZE (2 * 8 * 1024) // 8 kB
-#define SECRET_SECTOR_START 0x0
-#define SECRET_SECTOR_END 0x1
-
-// overlaps with secret
-#define BHK_START 0x0C002000
-#define BHK_MAXSIZE (1 * 8 * 1024) // 8 kB
-#define BHK_SECTOR_START 0x1
-#define BHK_SECTOR_END 0x1
-
-#define BOARDLOADER_START 0x0C004000
-#define BOARDLOADER_MAXSIZE (8 * 8 * 1024) // 64 kB
-#define BOARDLOADER_SECTOR_START 0x2
-#define BOARDLOADER_SECTOR_END 0x9
-
-#define BOARDCAPS_START 0x0C013F00
-#define BOARDCAPS_MAXSIZE 0x100
-
-#define BOOTLOADER_START 0x0C014000
-#define BOOTLOADER_MAXSIZE (24 * 8 * 1024) // 192 kB
-#define BOOTLOADER_SECTOR_START 0x0A
-#define BOOTLOADER_SECTOR_END 0x21
-
-#define FIRMWARE_START 0x0C044000
-#define FIRMWARE_MAXSIZE (430 * 8 * 1024) // 3440 kB
-#define FIRMWARE_SECTOR_START 0x22
-#define FIRMWARE_SECTOR_END 0x1CF
-#define KERNEL_START 0x0C044000
-#define KERNEL_MAXSIZE (512 * 1024) // 512 kB
-
-#define STORAGE_1_START 0x0C3A0000
-#define STORAGE_1_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define STORAGE_1_SECTOR_START 0x1D0
-#define STORAGE_1_SECTOR_END 0x1DF
-
-#define STORAGE_2_START 0x0C3C0000
-#define STORAGE_2_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define STORAGE_2_SECTOR_START 0x1E0
-#define STORAGE_2_SECTOR_END 0x1EF
-
-#define ASSETS_START 0x0C3E0000
-#define ASSETS_MAXSIZE (16 * 8 * 1024) // 128 kB
-#define ASSETS_SECTOR_START 0x1F0
-#define ASSETS_SECTOR_END 0x1FF
-
-// RAM layout
-#define BOOTARGS_START 0x30000000
-#define BOOTARGS_SIZE 0x200
-
-#define FB1_RAM_START 0x30000200
-#define FB1_RAM_SIZE (768 * 1024 - 512)
-
-#define MAIN_RAM_START 0x300C0000
-#define MAIN_RAM_SIZE (64 * 1024)
-
-#define FB2_RAM_START 0x300D0000
-#define FB2_RAM_SIZE (768 * 1024)
-
-#define AUX1_RAM_START 0x30190000
-#define AUX1_RAM_SIZE (896 * 1024)
-
-// misc
-#define CODE_ALIGNMENT 0x400
-#define COREAPP_ALIGNMENT 0x2000
-
-#endif
+#include "memory.h"
diff --git a/core/site_scons/models/D002/discovery2.py b/core/site_scons/models/D002/discovery2.py
index a5afc78386..be04be537d 100644
--- a/core/site_scons/models/D002/discovery2.py
+++ b/core/site_scons/models/D002/discovery2.py
@@ -18,6 +18,7 @@ def configure(
mcu = "STM32U5G9xx"
linker_script = """embed/sys/linker/stm32u5g/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -108,5 +109,6 @@ def configure(
]
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/T3B1/trezor_t3b1_revB.py b/core/site_scons/models/T3B1/trezor_t3b1_revB.py
index a86b92f672..613c7ff50c 100644
--- a/core/site_scons/models/T3B1/trezor_t3b1_revB.py
+++ b/core/site_scons/models/T3B1/trezor_t3b1_revB.py
@@ -27,6 +27,7 @@ def configure(
mcu = "STM32U585xx"
linker_script = """embed/sys/linker/stm32u58/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -116,5 +117,6 @@ def configure(
env.get("ENV")["TREZOR_BOARD"] = board
env.get("ENV")["MCU_TYPE"] = mcu
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/T3T1/trezor_t3t1_revE.py b/core/site_scons/models/T3T1/trezor_t3t1_revE.py
index e176df8245..09eaf3fa3a 100644
--- a/core/site_scons/models/T3T1/trezor_t3t1_revE.py
+++ b/core/site_scons/models/T3T1/trezor_t3t1_revE.py
@@ -29,6 +29,7 @@ def configure(
mcu = "STM32U585xx"
linker_script = """embed/sys/linker/stm32u58/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -149,5 +150,6 @@ def configure(
env.get("ENV")["TREZOR_BOARD"] = board
env.get("ENV")["MCU_TYPE"] = mcu
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revA.py b/core/site_scons/models/T3W1/trezor_t3w1_revA.py
index 8cb7b83169..67e00f0c7b 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revA.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revA.py
@@ -18,6 +18,7 @@ def configure(
mcu = "STM32U5G9xx"
linker_script = """embed/sys/linker/stm32u5g/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -259,5 +260,6 @@ def configure(
features_available.append("power_manager")
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revB.py b/core/site_scons/models/T3W1/trezor_t3w1_revB.py
index 7944d5fd35..278699f77a 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revB.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revB.py
@@ -18,6 +18,7 @@ def configure(
mcu = "STM32U5G9xx"
linker_script = """embed/sys/linker/stm32u5g/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -264,5 +265,6 @@ def configure(
features_available.append("power_manager")
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revC.py b/core/site_scons/models/T3W1/trezor_t3w1_revC.py
index b5bef1faab..578c953ffb 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revC.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revC.py
@@ -18,6 +18,7 @@ def configure(
mcu = "STM32U5G9xx"
linker_script = """embed/sys/linker/stm32u5g/{target}.ld"""
+ memory_layout = "memory.ld"
stm32u5_common_files(env, features_wanted, defines, sources, paths)
@@ -264,5 +265,6 @@ def configure(
features_available.append("power_manager")
env.get("ENV")["LINKER_SCRIPT"] = linker_script
+ env.get("ENV")["MEMORY_LAYOUT"] = memory_layout
return features_available
diff --git a/core/site_scons/models/stm32f4_common.py b/core/site_scons/models/stm32f4_common.py
index b1ef41b768..0664590081 100644
--- a/core/site_scons/models/stm32f4_common.py
+++ b/core/site_scons/models/stm32f4_common.py
@@ -104,3 +104,4 @@ def stm32f4_common_files(env, defines, sources, paths):
env.get("ENV")["SUFFIX"] = "stm32f4"
env.get("ENV")["LINKER_SCRIPT"] = """embed/sys/linker/stm32f4/{target}.ld"""
+ env.get("ENV")["MEMORY_LAYOUT"] = "memory.ld"
diff --git a/core/tools/trezor_core_tools/common.py b/core/tools/trezor_core_tools/common.py
index 824d801d21..e896e79eb3 100644
--- a/core/tools/trezor_core_tools/common.py
+++ b/core/tools/trezor_core_tools/common.py
@@ -7,9 +7,15 @@ CORE = HERE.parent.parent
MODELS_DIR = CORE / "embed" / "models"
+def get_layout_for_model(model: str, secmon: bool) -> Path:
+ if secmon:
+ return MODELS_DIR / model / f"memory_secmon.h"
+ else:
+ return MODELS_DIR / model / f"memory.h"
-def get_layout_for_model(model: str) -> Path:
- return MODELS_DIR / model / f"model_{model}.h"
+def get_linkerscript_for_model(model: str, secmon: bool) -> Path:
+ if secmon:
+ return MODELS_DIR / model / f"memory_secmon.ld"
+ else:
+ return MODELS_DIR / model / f"memory.ld"
-def get_linkerscript_for_model(model: str) -> Path:
- return MODELS_DIR / model / f"memory.ld"
diff --git a/core/tools/trezor_core_tools/layout_parser.py b/core/tools/trezor_core_tools/layout_parser.py
index aec22a1e1e..3544f4d8b3 100644
--- a/core/tools/trezor_core_tools/layout_parser.py
+++ b/core/tools/trezor_core_tools/layout_parser.py
@@ -16,8 +16,8 @@ from .common import get_layout_for_model
SEARCH_PATTERN = r"#define (\w+) (.+?)(?:\s*//.*)?$"
-def find_all_values(model: str) -> dict[str, int]:
- layout = get_layout_for_model(model)
+def find_all_values(model: str, secmon: bool) -> dict[str, int]:
+ layout = get_layout_for_model(model, secmon)
values = {}
begin = False
for line in open(layout):
@@ -37,8 +37,8 @@ def find_all_values(model: str) -> dict[str, int]:
return values
-def find_value(model: str, name: str) -> int:
- all_values = find_all_values(model)
+def find_value(model: str, name: str, secmon: bool) -> int:
+ all_values = find_all_values(model, secmon)
if name not in all_values:
raise ValueError(f"Value {name} not found in layout for model {model}")
return all_values[name]
@@ -47,9 +47,10 @@ def find_value(model: str, name: str) -> int:
@click.command()
@click.argument("model")
@click.argument("name")
-def main(model: str, name: str) -> None:
+@click.option("--secmon", is_flag=True)
+def main(model: str, name: str, secmon:bool) -> None:
try:
- print(find_value(model, name))
+ print(find_value(model, name, secmon))
except ValueError as e:
raise click.ClickException(str(e))
diff --git a/core/tools/trezor_core_tools/lsgen.py b/core/tools/trezor_core_tools/lsgen.py
index 36d7d7e722..9acdabbb76 100644
--- a/core/tools/trezor_core_tools/lsgen.py
+++ b/core/tools/trezor_core_tools/lsgen.py
@@ -2,15 +2,24 @@
from __future__ import annotations
import click
+import itertools
-from .common import get_linkerscript_for_model, MODELS_DIR
+from .common import get_linkerscript_for_model, get_layout_for_model, MODELS_DIR
from .layout_parser import find_all_values
-warning = """/* Auto-generated file, do not edit.*/
+FILE_HEADER = """/* Auto-generated file, do not edit.*/
"""
+def create_linker_script(model: str, cmse: bool) -> str:
+ content = FILE_HEADER
+ defines = find_all_values(model, cmse)
+ for name, value in defines.items():
+ content += f"{name} = {hex(value)};\n"
+ return content
+
+
@click.command()
@click.option("--check", is_flag=True)
def main(check: bool) -> None:
@@ -18,20 +27,23 @@ def main(check: bool) -> None:
models = list(MODELS_DIR.iterdir())
models = [model for model in models if model.is_dir()]
- for model in models:
- values = find_all_values(model.name)
- content = warning
- input = get_linkerscript_for_model(model.name)
- print(f"Processing {input}")
- for name, value in values.items():
- content += f"{name} = {hex(value)};\n"
- if not check:
- input.write_text(content)
- else:
- actual = input.read_text()
- if content != actual:
- raise click.ClickException(f"{input} differs from expected")
+ for model, split in itertools.product(models, [False, True]):
+ path = get_layout_for_model(model.name, split)
+ if not path.exists():
+ continue
+
+ path = get_linkerscript_for_model(model.name, split)
+ print(f"Processing {path}")
+
+ new_content = create_linker_script(model.name, split)
+
+ if check:
+ current_content = path.read_text()
+ if new_content != current_content:
+ raise click.ClickException(f"{path} differs from expected")
+ else:
+ path.write_text(new_content)
if __name__ == "__main__":
main()