#!/bin/sh
#===============================================================================
#
#  ifup
#
#  Copyright (C) 2013 by Digi International Inc.
#  All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License version 2 as published by
#  the Free Software Foundation.
#
#
#  !Description: Set network interfaces MAC addresses on i.MX5X
#
#===============================================================================

set -e

# loopback methods are directly handled by ifup
[ "${METHOD}" = "loopback" ] && exit 0

# Do nothing if interface does not exist
[ -d "/sys/class/net/${IFACE}" ] || exit 0

driver="$(readlink -f -n /sys/class/net/${IFACE} | sed 's,/sys/devices/platform/\(.\{3\}\).*,\1,g')"

case "${IFACE}:${driver}" in
eth1: | *:sms)
	macaddr="$(sed -ne 's,^.*ethaddr3=\([^[:blank:]]\+\)[:blank:]*.*,\1,g;T;p' /proc/cmdline)"
esac

if [ -n "${macaddr}" ]; then
	ifconfig ${IFACE} hw ether ${macaddr} up
fi
