Skip to content

Commit 9307bd9

Browse files
committed
Add some dummy MK4 OTP data
1 parent 32f4104 commit 9307bd9

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

hw/arm/prusa/otp.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef __OTP_H__
2+
#define __OTP_H__
3+
4+
typedef struct {
5+
uint16_t product_id;
6+
uint8_t revision;
7+
uint32_t supplier_id;
8+
uint16_t prodution_year;
9+
uint8_t production_month;
10+
uint8_t production_day;
11+
uint16_t daily_serial_number;
12+
} datamatrix_t;
13+
14+
typedef struct {
15+
uint8_t mac[6];
16+
} MAC_addr;
17+
18+
#pragma pack(push, 1)
19+
typedef struct {
20+
uint8_t version; // Data structure version (1 bytes)
21+
uint16_t size; // Data structure size (uint16_t little endian)
22+
uint8_t bomID; // BOM ID (1 bytes)
23+
uint32_t timestamp; // UNIX Timestamp from 1970 (uint32_t little endian)
24+
uint8_t datamatrix[24]; // DataMatrix ID 1 (24 bytes)
25+
MAC_addr mac_address; // MAC address (6 bytes)
26+
uint16_t _padding;
27+
} OTP_v4;
28+
#pragma pack(pop)
29+
30+
#endif

hw/arm/prusa/prusa-mk4.c

+29
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "stm32_common/stm32_common.h"
4343
#include "hw/arm/armv7m.h"
4444
#include "parts/spi_rgb.h"
45+
#include "otp.h"
4546

4647
#define BOOTLOADER_IMAGE "Prusa_Mk4_Boot.bin"
4748
#define XFLASH_FN "Prusa_Mk4_xflash.bin"
@@ -118,6 +119,7 @@ typedef struct mk4_cfg_t {
118119
uint8_t m_spi;
119120
uint8_t m_uart;
120121
bool is_400step;
122+
uint8_t dm_ver;
121123

122124
} mk4_cfg_t;
123125

@@ -154,6 +156,7 @@ static const mk4_cfg_t mk4_027c_cfg = {
154156
.m_select = {STM_PIN(GPIOG,15), STM_PIN(GPIOB,5), STM_PIN(GPIOF,15), STM_PIN(GPIOF,12)},
155157
.m_spi = STM32_P_SPI3,
156158
.is_400step = true,
159+
.dm_ver = 27
157160
};
158161

159162
static const mk4_cfg_t mk4_034_cfg = {
@@ -187,10 +190,23 @@ static const mk4_cfg_t mk4_034_cfg = {
187190
.m_select = {STM_PIN(GPIOG,15), STM_PIN(GPIOB,5), STM_PIN(GPIOF,15), STM_PIN(GPIOF,12)},
188191
.m_spi = STM32_P_SPI3,
189192
.is_400step = true,
193+
.dm_ver = 34,
190194
};
191195

192196
static void mk4_init(MachineState *machine, mk4_cfg_t cfg)
193197
{
198+
199+
OTP_v4 otp_data = { .version = 4, .size = sizeof(OTP_v4),
200+
.datamatrix = {'4', '5', '5', '8', '-', '2', '7', '0', '0', '0', '0', '1', '9', '0', '0', '5', '2', '5', '9', '9', '9', '9', 0, 0}
201+
};
202+
if (cfg.dm_ver == 34)
203+
{
204+
otp_data.datamatrix[5]='3';
205+
otp_data.datamatrix[6]='4';
206+
}
207+
208+
uint32_t* otp_raw = (uint32_t*) &otp_data;
209+
194210
DeviceState *dev;
195211

196212
dev = qdev_new(TYPE_STM32F427xI_SOC);
@@ -205,6 +221,19 @@ static void mk4_init(MachineState *machine, mk4_cfg_t cfg)
205221
printf("Extended flash size: now %"PRIu64" kB\n", flash_size/1024);
206222
}
207223
qdev_prop_set_uint32(dev,"flash-size", flash_size);
224+
225+
DeviceState* otp = stm32_soc_get_periph(dev, STM32_P_OTP);
226+
qdev_prop_set_uint32(otp,"len-otp-data", 9);
227+
qdev_prop_set_uint32(otp,"otp-data[0]", otp_raw[0]);
228+
qdev_prop_set_uint32(otp,"otp-data[1]", otp_raw[1]);
229+
qdev_prop_set_uint32(otp,"otp-data[2]", otp_raw[2]);
230+
qdev_prop_set_uint32(otp,"otp-data[3]", otp_raw[3]);
231+
qdev_prop_set_uint32(otp,"otp-data[4]", otp_raw[4]);
232+
qdev_prop_set_uint32(otp,"otp-data[5]", otp_raw[5]);
233+
qdev_prop_set_uint32(otp,"otp-data[6]", otp_raw[6]);
234+
qdev_prop_set_uint32(otp,"otp-data[7]", otp_raw[7]);
235+
qdev_prop_set_uint32(otp,"otp-data[8]", otp_raw[8]);
236+
208237
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
209238
DeviceState* dev_soc = dev;
210239
// We (ab)use the kernel command line to piggyback custom arguments into QEMU.

0 commit comments

Comments
 (0)