Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
Hi Albert, On Tue, Jan 26, 2016 at 7:15 AM, Albert ARIBAUDwrote: > Hello Joe, > > On Mon, 25 Jan 2016 18:45:52 -0600, Joe Hershberger > wrote: >> On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl >> wrote: > >> > +++ b/tools/gen_mac_addr.c >> >> This is not "generating a mac address", right? Its point is to create >> a CRC for the user-supplied MAC address. >> >> Perhaps a better name would be "gen_ethaddr_rom_crc". > > Hmm, why the "_rom" part? Just to give more hints to the observer that this is for creating a rom or eeprom image to be read by the associated new code in U-Boot. Cheers, -Joe > > Amicalement, > -- > Albert. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
On Tue, Jan 26, 2016 at 10:27 AM, Olliver Schinaglwrote: > Hey Joe, > > > On 26-01-16 01:45, Joe Hershberger wrote: >> >> On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl >> wrote: >>> >>> This patch adds a little tool that takes a generic MAC address and >>> generates a CRC byte for it. The output is the full MAC address without >>> any separators, ready written into an EEPROM. >>> >>> Signed-off-by: Olliver Schinagl >>> --- >>> tools/Makefile | 4 >>> tools/gen_mac_addr.c | 51 >>> +++ >>> 2 files changed, 55 insertions(+) >>> create mode 100644 tools/gen_mac_addr.c >>> >>> diff --git a/tools/Makefile b/tools/Makefile >>> index 4a50744..6191c26 100644 >>> --- a/tools/Makefile >>> +++ b/tools/Makefile >>> @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o >>> common/env_embedded.o lib/sha1.o >>> hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr >>> HOSTCFLAGS_gen_eth_addr.o := -pedantic >>> >>> +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr >>> +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o >>> +HOSTCFLAGS_gen_mac_addr.o := -pedantic >>> + >>> hostprogs-$(CONFIG_CMD_LOADS) += img2srec >>> HOSTCFLAGS_img2srec.o := -pedantic >>> >>> diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c >>> new file mode 100644 >>> index 000..bd8688f >>> --- /dev/null >>> +++ b/tools/gen_mac_addr.c >> >> This is not "generating a mac address", right? Its point is to create >> a CRC for the user-supplied MAC address. >> >> Perhaps a better name would be "gen_ethaddr_rom_crc". > > Yes, it takes a mac address as input and generates a macaddress + crc as > output. > > e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc > > But maybe it should get some flags to output either both (as described here) > or just the crc based on the input, and then a few flags to either output it > in hex format or as an int? What ever features you think will be useful for the users of this dev board I guess. I'm not sure if this is a platform (the included eeprom) that would carry over into other products. >> >>> @@ -0,0 +1,51 @@ >>> +/* >>> + * (C) Copyright 2016 >>> + * Olliver Schinagl >>> + * >>> + * SPDX-License-Identifier:GPL-2.0+ >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> + >>> +int main(int argc, char *argv[]) >>> +{ >>> + uint_fast8_t i; >>> + uint8_t mac_addr[7] = { 0x00 }; >>> + >>> + if (argc < 2) { >>> + puts("Please supply a MAC address."); >>> + return -1; >>> + } >>> + >>> + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { >>> + puts("Please supply a valid MAC address with optionaly\n" >>> +"dashes (-) or colons (:) as seperators."); >>> + return -1; >>> + } >> >> You could use the eth_validate_ethaddr_str() function here instead of this >> code. > > A right, well when I first wrote this, I think this didn't exist there yet. > I'll replace it and use it instead. >> >> >>> + >>> + i = 0; >>> + while (*argv[1] != '\0') { >>> + char nibble[2] = { 0x00, '\n' }; /* for strtol */ >>> + >>> + nibble[0] = *argv[1]++; >>> + if (isxdigit(nibble[0])) { >>> + if (isupper(nibble[0])) >>> + nibble[0] = tolower(nibble[0]); >>> + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << >>> ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); >>> + i++; >>> + } >>> + } >> >> Instead of all this you could just compile in (maybe it already is?) >> the eth_parse_enetaddr() function that U-Boot uses for this very >> purpose. > > I'll see if I can have access to this function and then rewrite this to use > that. > >> >>> + mac_addr[6] = crc8(mac_addr, 6); >>> + >>> + for (i = 0; i < 7; i++) >>> + printf("%.2x", mac_addr[i]); >>> + putchar('\n'); >>> + >>> + return 0; >>> +} >>> -- >>> 2.6.2 >>> >>> ___ >>> U-Boot mailing list >>> U-Boot@lists.denx.de >>> http://lists.denx.de/mailman/listinfo/u-boot > > > -- > Met vriendelijke groeten, Kind regards, 与亲切的问候 > > Olliver Schinagl > Software Engineer > Research & Development > Ultimaker B.V. > ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
Hey Joe, On 26-01-16 01:45, Joe Hershberger wrote: On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinaglwrote: This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM. Signed-off-by: Olliver Schinagl --- tools/Makefile | 4 tools/gen_mac_addr.c | 51 +++ 2 files changed, 55 insertions(+) create mode 100644 tools/gen_mac_addr.c diff --git a/tools/Makefile b/tools/Makefile index 4a50744..6191c26 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr HOSTCFLAGS_gen_eth_addr.o := -pedantic +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o +HOSTCFLAGS_gen_mac_addr.o := -pedantic + hostprogs-$(CONFIG_CMD_LOADS) += img2srec HOSTCFLAGS_img2srec.o := -pedantic diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c new file mode 100644 index 000..bd8688f --- /dev/null +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". Yes, it takes a mac address as input and generates a macaddress + crc as output. e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc But maybe it should get some flags to output either both (as described here) or just the crc based on the input, and then a few flags to either output it in hex format or as an int? @@ -0,0 +1,51 @@ +/* + * (C) Copyright 2016 + * Olliver Schinagl + * + * SPDX-License-Identifier:GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + uint_fast8_t i; + uint8_t mac_addr[7] = { 0x00 }; + + if (argc < 2) { + puts("Please supply a MAC address."); + return -1; + } + + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { + puts("Please supply a valid MAC address with optionaly\n" +"dashes (-) or colons (:) as seperators."); + return -1; + } You could use the eth_validate_ethaddr_str() function here instead of this code. A right, well when I first wrote this, I think this didn't exist there yet. I'll replace it and use it instead. + + i = 0; + while (*argv[1] != '\0') { + char nibble[2] = { 0x00, '\n' }; /* for strtol */ + + nibble[0] = *argv[1]++; + if (isxdigit(nibble[0])) { + if (isupper(nibble[0])) + nibble[0] = tolower(nibble[0]); + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); + i++; + } + } Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose. I'll see if I can have access to this function and then rewrite this to use that. + mac_addr[6] = crc8(mac_addr, 6); + + for (i = 0; i < 7; i++) + printf("%.2x", mac_addr[i]); + putchar('\n'); + + return 0; +} -- 2.6.2 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot -- Met vriendelijke groeten, Kind regards, 与亲切的问候 Olliver Schinagl Software Engineer Research & Development Ultimaker B.V. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
Hey all, On 26-01-16 15:56, Joe Hershberger wrote: Hi Albert, On Tue, Jan 26, 2016 at 7:15 AM, Albert ARIBAUDwrote: Hello Joe, On Mon, 25 Jan 2016 18:45:52 -0600, Joe Hershberger wrote: On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl wrote: +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". Hmm, why the "_rom" part? Just to give more hints to the observer that this is for creating a rom or eeprom image to be read by the associated new code in U-Boot. Well depending on the output, it could even be used to verify what is stored in an ROM. So i understand Albert's reasoning that it may not be related to ROM at all Cheers, -Joe Amicalement, -- Albert. -- Met vriendelijke groeten, Kind regards, 与亲切的问候 Olliver Schinagl Software Engineer Research & Development Ultimaker B.V. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
Hey Joe, On 26-01-16 17:31, Joe Hershberger wrote: On Tue, Jan 26, 2016 at 10:27 AM, Olliver Schinaglwrote: Hey Joe, On 26-01-16 01:45, Joe Hershberger wrote: On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl wrote: This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM. Signed-off-by: Olliver Schinagl --- tools/Makefile | 4 tools/gen_mac_addr.c | 51 +++ 2 files changed, 55 insertions(+) create mode 100644 tools/gen_mac_addr.c diff --git a/tools/Makefile b/tools/Makefile index 4a50744..6191c26 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr HOSTCFLAGS_gen_eth_addr.o := -pedantic +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o +HOSTCFLAGS_gen_mac_addr.o := -pedantic + hostprogs-$(CONFIG_CMD_LOADS) += img2srec HOSTCFLAGS_img2srec.o := -pedantic diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c new file mode 100644 index 000..bd8688f --- /dev/null +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". Yes, it takes a mac address as input and generates a macaddress + crc as output. e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc But maybe it should get some flags to output either both (as described here) or just the crc based on the input, and then a few flags to either output it in hex format or as an int? What ever features you think will be useful for the users of this dev board I guess. I'm not sure if this is a platform (the included eeprom) that would carry over into other products. Why not? It just reads a mac address and generates a crc8-appended mac address (or just the crc8) everybody that uses a mac address to be stored somewhere (even if the env is pre-generated) could use this. I don't think it is limited to our platform since it does something very generic. @@ -0,0 +1,51 @@ +/* + * (C) Copyright 2016 + * Olliver Schinagl + * + * SPDX-License-Identifier:GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + uint_fast8_t i; + uint8_t mac_addr[7] = { 0x00 }; + + if (argc < 2) { + puts("Please supply a MAC address."); + return -1; + } + + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { + puts("Please supply a valid MAC address with optionaly\n" +"dashes (-) or colons (:) as seperators."); + return -1; + } You could use the eth_validate_ethaddr_str() function here instead of this code. A right, well when I first wrote this, I think this didn't exist there yet. I'll replace it and use it instead. + + i = 0; + while (*argv[1] != '\0') { + char nibble[2] = { 0x00, '\n' }; /* for strtol */ + + nibble[0] = *argv[1]++; + if (isxdigit(nibble[0])) { + if (isupper(nibble[0])) + nibble[0] = tolower(nibble[0]); + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); + i++; + } + } Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose. I'll see if I can have access to this function and then rewrite this to use that. + mac_addr[6] = crc8(mac_addr, 6); + + for (i = 0; i < 7; i++) + printf("%.2x", mac_addr[i]); + putchar('\n'); + + return 0; +} -- 2.6.2 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot -- Met vriendelijke groeten, Kind regards, 与亲切的问候 Olliver Schinagl Software Engineer Research & Development Ultimaker B.V. -- Met vriendelijke groeten, Kind regards, 与亲切的问候 Olliver Schinagl Software Engineer Research & Development Ultimaker B.V. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
On Tue, Jan 26, 2016 at 10:36 AM, Olliver Schinaglwrote: > Hey Joe, > > > On 26-01-16 17:31, Joe Hershberger wrote: >> >> On Tue, Jan 26, 2016 at 10:27 AM, Olliver Schinagl >> wrote: >>> >>> Hey Joe, >>> >>> >>> On 26-01-16 01:45, Joe Hershberger wrote: On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl wrote: > > This patch adds a little tool that takes a generic MAC address and > generates a CRC byte for it. The output is the full MAC address without > any separators, ready written into an EEPROM. > > Signed-off-by: Olliver Schinagl > --- >tools/Makefile | 4 >tools/gen_mac_addr.c | 51 > +++ >2 files changed, 55 insertions(+) >create mode 100644 tools/gen_mac_addr.c > > diff --git a/tools/Makefile b/tools/Makefile > index 4a50744..6191c26 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o > common/env_embedded.o lib/sha1.o >hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr >HOSTCFLAGS_gen_eth_addr.o := -pedantic > > +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr > +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o > +HOSTCFLAGS_gen_mac_addr.o := -pedantic > + >hostprogs-$(CONFIG_CMD_LOADS) += img2srec >HOSTCFLAGS_img2srec.o := -pedantic > > diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c > new file mode 100644 > index 000..bd8688f > --- /dev/null > +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". >>> >>> Yes, it takes a mac address as input and generates a macaddress + crc as >>> output. >>> >>> e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc >>> >>> But maybe it should get some flags to output either both (as described >>> here) >>> or just the crc based on the input, and then a few flags to either output >>> it >>> in hex format or as an int? >> >> What ever features you think will be useful for the users of this dev >> board I guess. I'm not sure if this is a platform (the included >> eeprom) that would carry over into other products. > > Why not? It just reads a mac address and generates a crc8-appended mac > address (or just the crc8) everybody that uses a mac address to be stored > somewhere (even if the env is pre-generated) could use this. I don't think > it is limited to our platform since it does something very generic. OK. > >> > @@ -0,0 +1,51 @@ > +/* > + * (C) Copyright 2016 > + * Olliver Schinagl > + * > + * SPDX-License-Identifier:GPL-2.0+ > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +int main(int argc, char *argv[]) > +{ > + uint_fast8_t i; > + uint8_t mac_addr[7] = { 0x00 }; > + > + if (argc < 2) { > + puts("Please supply a MAC address."); > + return -1; > + } > + > + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { > + puts("Please supply a valid MAC address with > optionaly\n" > +"dashes (-) or colons (:) as seperators."); > + return -1; > + } You could use the eth_validate_ethaddr_str() function here instead of this code. >>> >>> A right, well when I first wrote this, I think this didn't exist there >>> yet. >>> I'll replace it and use it instead. > + > + i = 0; > + while (*argv[1] != '\0') { > + char nibble[2] = { 0x00, '\n' }; /* for strtol */ > + > + nibble[0] = *argv[1]++; > + if (isxdigit(nibble[0])) { > + if (isupper(nibble[0])) > + nibble[0] = tolower(nibble[0]); > + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << > ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); > + i++; > + } > + } Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose. >>> >>> I'll see if I can have access to this function and then rewrite this to >>> use >>> that. >>> > + mac_addr[6] = crc8(mac_addr, 6); > + > + for (i = 0; i < 7; i++) > + printf("%.2x", mac_addr[i]); > + putchar('\n'); > + > + return 0; > +} > -- > 2.6.2 > >
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
On Tue, Jan 26, 2016 at 10:31 AM, Olliver Schinaglwrote: > Hey all, > > On 26-01-16 15:56, Joe Hershberger wrote: >> >> Hi Albert, >> >> On Tue, Jan 26, 2016 at 7:15 AM, Albert ARIBAUD >> wrote: >>> >>> Hello Joe, >>> >>> On Mon, 25 Jan 2016 18:45:52 -0600, Joe Hershberger >>> wrote: On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl wrote: > > +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". >>> >>> Hmm, why the "_rom" part? >> >> Just to give more hints to the observer that this is for creating a >> rom or eeprom image to be read by the associated new code in U-Boot. > > Well depending on the output, it could even be used to verify what is stored > in an ROM. So i understand Albert's reasoning that it may not be related to > ROM at all You could make it even more generic and just call it gen_crc8... make it take an arbitrary byte stream. Anyway. I think there's no need for speculative generality. Make the tool be named for what its purpose is. Include the features you need it to have. If someone wants to expand it, it can be renamed at that point. Thanks, -Joe ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
Hello Joe, On Mon, 25 Jan 2016 18:45:52 -0600, Joe Hershbergerwrote: > On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl > wrote: > > +++ b/tools/gen_mac_addr.c > > This is not "generating a mac address", right? Its point is to create > a CRC for the user-supplied MAC address. > > Perhaps a better name would be "gen_ethaddr_rom_crc". Hmm, why the "_rom" part? Amicalement, -- Albert. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinaglwrote: > This patch adds a little tool that takes a generic MAC address and > generates a CRC byte for it. The output is the full MAC address without > any separators, ready written into an EEPROM. > > Signed-off-by: Olliver Schinagl > --- > tools/Makefile | 4 > tools/gen_mac_addr.c | 51 +++ > 2 files changed, 55 insertions(+) > create mode 100644 tools/gen_mac_addr.c > > diff --git a/tools/Makefile b/tools/Makefile > index 4a50744..6191c26 100644 > --- a/tools/Makefile > +++ b/tools/Makefile > @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o > lib/sha1.o > hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr > HOSTCFLAGS_gen_eth_addr.o := -pedantic > > +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr > +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o > +HOSTCFLAGS_gen_mac_addr.o := -pedantic > + > hostprogs-$(CONFIG_CMD_LOADS) += img2srec > HOSTCFLAGS_img2srec.o := -pedantic > > diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c > new file mode 100644 > index 000..bd8688f > --- /dev/null > +++ b/tools/gen_mac_addr.c This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address. Perhaps a better name would be "gen_ethaddr_rom_crc". > @@ -0,0 +1,51 @@ > +/* > + * (C) Copyright 2016 > + * Olliver Schinagl > + * > + * SPDX-License-Identifier:GPL-2.0+ > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +int main(int argc, char *argv[]) > +{ > + uint_fast8_t i; > + uint8_t mac_addr[7] = { 0x00 }; > + > + if (argc < 2) { > + puts("Please supply a MAC address."); > + return -1; > + } > + > + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { > + puts("Please supply a valid MAC address with optionaly\n" > +"dashes (-) or colons (:) as seperators."); > + return -1; > + } You could use the eth_validate_ethaddr_str() function here instead of this code. > + > + i = 0; > + while (*argv[1] != '\0') { > + char nibble[2] = { 0x00, '\n' }; /* for strtol */ > + > + nibble[0] = *argv[1]++; > + if (isxdigit(nibble[0])) { > + if (isupper(nibble[0])) > + nibble[0] = tolower(nibble[0]); > + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % > 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); > + i++; > + } > + } Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose. > + mac_addr[6] = crc8(mac_addr, 6); > + > + for (i = 0; i < 7; i++) > + printf("%.2x", mac_addr[i]); > + putchar('\n'); > + > + return 0; > +} > -- > 2.6.2 > > ___ > U-Boot mailing list > U-Boot@lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH v2 5/5] tools: Add tool to add crc8 to a mac address
This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM. Signed-off-by: Olliver Schinagl--- tools/Makefile | 4 tools/gen_mac_addr.c | 51 +++ 2 files changed, 55 insertions(+) create mode 100644 tools/gen_mac_addr.c diff --git a/tools/Makefile b/tools/Makefile index 4a50744..6191c26 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr HOSTCFLAGS_gen_eth_addr.o := -pedantic +hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr +gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o +HOSTCFLAGS_gen_mac_addr.o := -pedantic + hostprogs-$(CONFIG_CMD_LOADS) += img2srec HOSTCFLAGS_img2srec.o := -pedantic diff --git a/tools/gen_mac_addr.c b/tools/gen_mac_addr.c new file mode 100644 index 000..bd8688f --- /dev/null +++ b/tools/gen_mac_addr.c @@ -0,0 +1,51 @@ +/* + * (C) Copyright 2016 + * Olliver Schinagl + * + * SPDX-License-Identifier:GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + uint_fast8_t i; + uint8_t mac_addr[7] = { 0x00 }; + + if (argc < 2) { + puts("Please supply a MAC address."); + return -1; + } + + if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) { + puts("Please supply a valid MAC address with optionaly\n" +"dashes (-) or colons (:) as seperators."); + return -1; + } + + i = 0; + while (*argv[1] != '\0') { + char nibble[2] = { 0x00, '\n' }; /* for strtol */ + + nibble[0] = *argv[1]++; + if (isxdigit(nibble[0])) { + if (isupper(nibble[0])) + nibble[0] = tolower(nibble[0]); + mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0); + i++; + } + } + mac_addr[6] = crc8(mac_addr, 6); + + for (i = 0; i < 7; i++) + printf("%.2x", mac_addr[i]); + putchar('\n'); + + return 0; +} -- 2.6.2 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot