Example #1
0
int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    char cmd;

    if (argc == 1) {
        show_eeprom();
        return 0;
    }

    cmd = argv[1][0];

    if (cmd == 'r') {
        read_eeprom();
        return 0;
    }

    if (cmd == 'i') {
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        memcpy(e.id, "NXID", sizeof(e.id));
        e.version = 0;
#else
        memcpy(e.id, "CCID", sizeof(e.id));
#endif
        return 0;
    }

    if (!is_valid) {
        printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
        return 0;
    }

    if (argc == 2) {
        switch (cmd) {
        case 's':	/* save */
            prog_eeprom();
            break;
        default:
            return cmd_usage(cmdtp);
        }

        return 0;
    }

    /* We know we have at least one parameter  */

    switch (cmd) {
    case 'n':	/* serial number */
        memset(e.sn, 0, sizeof(e.sn));
        strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
        update_crc();
        break;
    case 'e':	/* errata */
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        memset(e.errata, 0, 5);
        strncpy((char *)e.errata, argv[2], 4);
#else
        e.errata[0] = argv[2][0];
        e.errata[1] = argv[2][1];
#endif
        update_crc();
        break;
    case 'd':	/* date BCD format YYMMDDhhmmss */
        set_date(argv[2]);
        break;
    case 'p':	/* MAC table size */
        e.mac_count = simple_strtoul(argv[2], NULL, 16);
        update_crc();
        break;
    case '0' ... '7':	/* "mac 0" through "mac 7" */
        set_mac_address(cmd - '0', argv[2]);
        break;
    case 'h':	/* help */
    default:
        return cmd_usage(cmdtp);
    }

    return 0;
}
Example #2
0
int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char cmd;

	if (argc == 1) {
		show_eeprom();
		return 0;
	}

	cmd = argv[1][0];

	if (cmd == 'r') {
#ifdef DEBUG
		printf("%s read\n", __func__);
#endif
		read_eeprom();
		return 0;
	}

	if (argc == 2) {
		switch (cmd) {
		case 's':	/* save */
#ifdef DEBUG
			printf("%s save\n", __func__);
#endif
			prog_eeprom();
			break;
		default:
			return cmd_usage(cmdtp);
		}

		return 0;
	}

	/* We know we have at least one parameter  */

	switch (cmd) {
	case 'n':	/* serial number */
#ifdef DEBUG
		printf("%s serial number\n", __func__);
#endif
		memset(e.sn, 0, sizeof(e.sn));
		strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
		update_crc();
		break;
	case 'd':	/* date BCD format YYMMDDhhmmss */
		set_date(argv[2]);
		break;
	case 'e':	/* errata */
		printf("mac errata not implemented\n");
		break;
	case 'i':	/* id */
		memset(e.id, 0, sizeof(e.id));
		strncpy((char *)e.id, argv[2], sizeof(e.id) - 1);
		update_crc();
		break;
	case 'p':	/* ports */
		printf("mac ports not implemented (always 1 port)\n");
		break;
	case '0' ... '9':
		/* we only have "mac 0" but any digit can be used here */
		set_mac_address(argv[2]);
		break;
	case 'h':	/* help */
	default:
		return cmd_usage(cmdtp);
	}

	return 0;
}