Skip to content

Commit

Permalink
Merge pull request #10 from macpijan/serial_number
Browse files Browse the repository at this point in the history
Serial number
  • Loading branch information
pietrushnic authored Sep 12, 2016
2 parents 15e34d5 + 7c58c6c commit 6913bde
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# General setup
#
# CONFIG_EXPERT is not set
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION="4.0.1"
CONFIG_CBFS_PREFIX="fallback"
CONFIG_COMPILER_GCC=y
# CONFIG_COMPILER_LLVM_CLANG is not set
Expand Down Expand Up @@ -375,7 +375,7 @@ CONFIG_GENERATE_SMBIOS_TABLES=y
CONFIG_MAINBOARD_SERIAL_NUMBER="123456789"
CONFIG_MAINBOARD_VERSION="1.0"
CONFIG_MAINBOARD_SMBIOS_MANUFACTURER="PC Engines"
CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="apu2"
CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME="APU2"

#
# Payload
Expand Down
6 changes: 6 additions & 0 deletions src/arch/x86/boot/smbios.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ void __attribute__((weak)) smbios_mainboard_set_uuid(u8 *uuid)
/* leave all zero */
}

const char *__attribute__((weak)) smbios_mainboard_sku(void)
{
return "";
}

static int smbios_write_type1(unsigned long *current, int handle)
{
struct smbios_type1 *t = (struct smbios_type1 *)*current;
Expand All @@ -215,6 +220,7 @@ static int smbios_write_type1(unsigned long *current, int handle)
t->manufacturer = smbios_add_string(t->eos, smbios_mainboard_manufacturer());
t->product_name = smbios_add_string(t->eos, smbios_mainboard_product_name());
t->serial_number = smbios_add_string(t->eos, smbios_mainboard_serial_number());
t->sku = smbios_add_string(t->eos, smbios_mainboard_sku());
t->version = smbios_add_string(t->eos, smbios_mainboard_version());
smbios_mainboard_set_uuid(t->uuid);
len = t->length + smbios_string_table_len(t->eos);
Expand Down
1 change: 1 addition & 0 deletions src/include/smbios.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const char *smbios_mainboard_serial_number(void);
const char *smbios_mainboard_version(void);
void smbios_mainboard_set_uuid(u8 *uuid);
const char *smbios_mainboard_bios_version(void);
const char *smbios_mainboard_sku(void);
u8 smbios_mainboard_enclosure_type(void);

#define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
Expand Down
52 changes: 52 additions & 0 deletions src/mainboard/pcengines/apu2/mainboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#endif //CONFIG_USE_CBMEM_FILE_OVERRIDE
#include <cbfs_core.h>
#include <spd_cache.h>
#include <smbios.h>
#include <string.h>
#include <cpu/amd/amdfam16.h>
#include <cpuRegisters.h>

static bool check_console(void);

Expand Down Expand Up @@ -284,4 +288,52 @@ struct chip_operations mainboard_ops = {
.final = mainboard_final,
};

const char *smbios_mainboard_serial_number(void)
{
static char serial[10];
msr_t msr;
u32 mac_addr = 0;
device_t nic_dev;

// Allows the IO configuration space access method, IOCF8 and IOCFC, to be
// used to generate extended configuration cycles
msr = rdmsr(NB_CFG_MSR);
msr.hi |= (ENABLE_CF8_EXT_CFG);
wrmsr(NB_CFG_MSR, msr);

nic_dev = dev_find_slot(1, PCI_DEVFN(0, 0));

if ((serial[0] != 0) || !nic_dev)
return serial;

// Read 4 bytes starting from 0x144 offset
mac_addr = pci_read_config32(nic_dev, 0x144);
// MSB here is always 0xff
// Discard it so only bottom 3b of mac address are left
mac_addr &= 0x00ffffff;

// Set bit EnableCf8ExtCfg back to 0
msr.hi &= ~(ENABLE_CF8_EXT_CFG);
wrmsr(NB_CFG_MSR, msr);

// Calculate serial value
mac_addr /= 4;
mac_addr -= 64;

snprintf(serial, sizeof(serial), "%d", mac_addr);

return serial;
}

const char *smbios_mainboard_sku(void)
{
static char sku[5];
if (sku[0] != 0)
return sku;

if (!ReadFchGpio(APU2_SPD_STRAP0_GPIO))
snprintf(sku, sizeof(sku), "2 GB");
else
snprintf(sku, sizeof(sku), "4 GB");
return sku;
}

0 comments on commit 6913bde

Please # to comment.