From dd0c85f42706fa95d27f40af57f1f0db53eae7b3 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 3 Feb 2009 18:06:39 +0000 Subject: [PATCH] qi-add-gta02-indentity-part-parsing.patch Now everything else is in place, we are able to mount the GTA02 "identity" partition and extract the USB Ethernet MAC Address from it, and add it to the kernel commandline. This causes the Ethernet gadget to use the same MAC address each boot, simplifying DHCP server situation. The MAC address in the identity partition is globally unique from the factory. Signed-off-by: Andy Green --- qiboot/src/cpu/s3c2442/gta02.c | 59 +++++++++++++++++++++++++++++++++- qiboot/src/fs/dev.c | 4 +-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/qiboot/src/cpu/s3c2442/gta02.c b/qiboot/src/cpu/s3c2442/gta02.c index 522ec03..e520fbb 100644 --- a/qiboot/src/cpu/s3c2442/gta02.c +++ b/qiboot/src/cpu/s3c2442/gta02.c @@ -31,6 +31,7 @@ #include #include #include +#include #define GTA02_DEBUG_UART 2 #define PCF50633_I2C_ADS 0x73 @@ -38,6 +39,9 @@ static int battery_condition_reasonable = 0; +extern unsigned long partition_offset_blocks; +extern unsigned long partition_length_blocks; + struct nand_dynparts { const char *name; /* name of this partition for Linux */ u32 good_length; /* bytes needed from good sectors in this partition */ @@ -480,18 +484,30 @@ void post_serial_init_gta02(void) puts("BATTERY CONDITION LOW\n"); } +const struct board_api board_api_gta02; + /* - * create and append dynparts Linux kernel commandline + * create and append device-specific Linux kernel commandline + * + * This takes care of legacy dyanmic partition sizing and USB Ethernet + * MAC address identity information. */ char * append_device_specific_cmdline_gta02(char * cmdline) { int n = 0; + int len; u32 block512 = 0; u32 start_block512 = 0; char term = ','; const u32 GTA02_NAND_READBLOCK_SIZE = 2048; extern int s3c2442_nand_is_bad_block(unsigned long block_index_512); + static char mac[64]; + struct kernel_source const * real_kernel = this_kernel; + + /* + * dynparts computation + */ cmdline += strlen(strcpy(cmdline, " mtdparts=physmap-flash:-(nor);neo1973-nand:")); @@ -533,6 +549,47 @@ char * append_device_specific_cmdline_gta02(char * cmdline) *cmdline = '\0'; + /* + * Identity + */ + + /* position ourselves at true start of GTA02 identity partition */ + partition_offset_blocks = nand_dynparts[4].good_length; + partition_length_blocks = 0x40000 / 512; + + /* + * lie that we are in NAND context... GTA02 specific + * all filesystem access is completed before we are called + */ + this_kernel = &board_api_gta02.kernel_source[3]; + + if (!ext2fs_mount()) { + puts("Unable to mount ext2 filesystem\n"); + goto bail; + } + + len = ext2fs_open("usb"); + if (len < 0) { + puts(" Open failed\n"); + goto bail; + } + + n = ext2fs_read(mac, sizeof(mac)); + if (n < 0) { + puts(" Read failed\n"); + goto bail; + } + + mac[len] = '\0'; + + cmdline += strlen(strcpy(cmdline, " g_ether.host_addr=")); + cmdline += strlen(strcpy(cmdline, &mac[2])); + *cmdline += ' ' ; +bail: + this_kernel = real_kernel; + + *cmdline = '\0'; + return cmdline; } diff --git a/qiboot/src/fs/dev.c b/qiboot/src/fs/dev.c index 8ffcf2d..9d4fba3 100644 --- a/qiboot/src/fs/dev.c +++ b/qiboot/src/fs/dev.c @@ -39,6 +39,7 @@ int ext2fs_devread(int sector, int filesystem_block_log2, int byte_offset, int b sector = sector << filesystem_block_log2; + /* * Check partition boundaries */ @@ -93,8 +94,7 @@ int ext2fs_devread(int sector, int filesystem_block_log2, int byte_offset, int b u8 p[SECTOR_SIZE]; block_len = SECTOR_SIZE; - this_kernel->block_read(p, - partition_offset_blocks + sector, 1); + this_kernel->block_read(p,partition_offset_blocks + sector, 1); memcpy(buf, p, byte_len); return 1; }