公司的设备基于aspeed 的ast2600. 和ast2600-evt还是有不小差距, 需要为了多模拟一些数据, 需要添加新machine, 修改部分设备.
修改文件 hw/arm/aspeed.c
1. 添加新的machine pf12, 基于ast2600-evb, 提供一个class init函数
static const TypeInfo aspeed_machine_types[] = {
........
}, {
.name = MACHINE_TYPE_NAME("ast2600-evb"),
.parent = TYPE_ASPEED_MACHINE,
.class_init = aspeed_machine_ast2600_evb_class_init,
}, {
.name = MACHINE_TYPE_NAME("pf12"),
.parent = TYPE_ASPEED_MACHINE,
.class_init = aspeed_machine_pf12_class_init,
},{
....
2. 创建刚才提供的函数 aspeed_machine_pf12_class_init 参考 aspeed_machine_ast2600_evb_class_init
static void aspeed_machine_pf12_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
printf("init pf12 class\n");
mc->desc = "Aspeed AST2600 EVB (Cortex-A7)";
amc->soc_name = "ast2600-a3";
amc->hw_strap1 = AST2600_EVB_HW_STRAP1;
amc->hw_strap2 = AST2600_EVB_HW_STRAP2|0xC800; // 需要ABR功能
amc->fmc_model = "mx66u51235f";
amc->spi_model = "mx66u51235f";
amc->num_cs = 2;
amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON | ASPEED_MAC2_ON |
ASPEED_MAC3_ON;
amc->i2c_init = pf12_i2c_init; // 这个就是自定义的device的部分
mc->default_ram_size = 1 * GiB;
mc->default_cpus = mc->min_cpus = mc->max_cpus =
aspeed_soc_num_cpus(amc->soc_name);
mc->reset = pf12_reset; // 我需要reset部分gpio
};
3. 实现 pf12_i2c_init , 和evb上 i2c 设备不一样
static void pf12_i2c_init(AspeedMachineState *bmc)
{
AspeedSoCState *soc = &bmc->soc;
DeviceState *dev;
// dev = DEVICE(i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 1),
// "emc1413", 0x4c));
// object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
// object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
// object_property_set_int(OBJECT(dev), "temperature2", 20000, &error_abort);
i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 1),
TYPE_TMP105, 0x4d);
// 这些设备是FRU相关的(eeprom)
uint8_t *eeprom_buf2 = g_malloc0(8 * 1024);
uint8_t buf2[] = {
// 08:bf:b8:c0:be:ac
0x08, 0xbf, 0xb8, 0x0c, 0xbe, 0xac, 0x00, 0xfe,
.......
};
memcpy(eeprom_buf2, buf2, sizeof(buf2));
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 6), 0x56,
eeprom_buf2);
uint8_t *eeprom_fru = g_malloc0(8 * 256);
uint8_t fru[] = {
// 08:bf:b8:c0:be:ac
0x01, 0x00, 0x01, 0x05, 0x0f, 0x00, 0x00, 0xea, 0x01, 0x04, 0x17, 0xce, 0x31, 0x33, 0x53, 0x46,
.............
};
memcpy(eeprom_fru, fru, sizeof(fru));
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 6), 0x54,
eeprom_fru);
DEVICE(i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 2), TYPE_DS1338, 0x10));
// qdev_connect_gpio_out(dev, 14, qdev_get_gpio_in(DEVICE(dev), 0));
// i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 4), TYPE_ADS7846, 0x18);
// LM75 is compatible with TMP105 driver //
i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 6), TYPE_TMP105, 0x49);
i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 7), TYPE_TMP105, 0x49);
i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 8), TYPE_TMP105, 0x4B);
}
4. Reset 函数
static void pf12_reset(MachineState *state, ShutdownCause reason)
{
AspeedMachineState *bmc = ASPEED_MACHINE(state);
AspeedGPIOState *gpio = &bmc->soc.gpio;
printf("pf12_reset reason %d \n", reason);
qemu_devices_reset(reason);
/* Board ID: 7 (Class-1, 4 slots) */
object_property_set_bool(OBJECT(gpio), "gpioV4", true, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioV5", true, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioV6", true, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioV7", false, &error_fatal);
/* Slot presence pins, inverse polarity. (False means present) */
object_property_set_bool(OBJECT(gpio), "gpioH4", false, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioH5", true, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioH6", true, &error_fatal);
object_property_set_bool(OBJECT(gpio), "gpioH7", true, &error_fatal);
...........
}
aspeed machine支持参数设置, 可以运行时调整flash设备 ( fmc-model ,spi-model)
代码在 aspeed_machine_class_props_init
static void aspeed_machine_class_props_init(ObjectClass *oc)
{
object_class_property_add_bool(oc, "execute-in-place",
aspeed_get_mmio_exec,
aspeed_set_mmio_exec);
object_class_property_set_description(oc, "execute-in-place",
"boot directly from CE0 flash device");
object_class_property_add_str(oc, "bmc-console", aspeed_get_bmc_console,
aspeed_set_bmc_console);
object_class_property_set_description(oc, "bmc-console",
"Change the default UART to \"uartX\"");
object_class_property_add_str(oc, "fmc-model", aspeed_get_fmc_model,
aspeed_set_fmc_model);
object_class_property_set_description(oc, "fmc-model",
"Change the FMC Flash model");
object_class_property_add_str(oc, "spi-model", aspeed_get_spi_model,
aspeed_set_spi_model);
object_class_property_set_description(oc, "spi-model",
"Change the SPI Flash model");
}
标签:set,qemu,ast2600,object,property,添加,i2c,aspeed,class
From: https://blog.csdn.net/yanghuajia/article/details/142891070