Somalia and Ethiopia have reached a deal to end a bitter, nearly year-long dispute, following talks in Turkey.